-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathplugin-config.unit.test.ts
More file actions
137 lines (130 loc) · 4.24 KB
/
plugin-config.unit.test.ts
File metadata and controls
137 lines (130 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { describe, expect, it } from 'vitest';
import { type PluginConfig, pluginConfigSchema } from './plugin-config.js';
describe('pluginConfigSchema', () => {
it('should accept a valid plugin configuration with all entities', () => {
expect(() =>
pluginConfigSchema.parse({
slug: 'eslint',
title: 'ESLint plugin',
description: 'This plugin checks ESLint in configured files.',
docsUrl: 'https://eslint.org/',
icon: 'eslint',
runner: { command: 'node', outputFile: 'output.json' },
audits: [
{ slug: 'no-magic-numbers', title: 'Use defined constants' },
{ slug: 'require-await', title: 'Every async has await.' },
],
groups: [
{
slug: 'typescript-eslint',
title: 'TypeScript ESLint rules',
refs: [{ slug: 'require-await', weight: 2 }],
},
],
packageName: 'cli',
version: 'v0.5.2',
} satisfies PluginConfig),
).not.toThrow();
});
it('should accept a minimal plugin configuration', () => {
expect(() =>
pluginConfigSchema.parse({
slug: 'cypress',
title: 'Cypress testing',
icon: 'cypress',
runner: { command: 'npx cypress run', outputFile: 'e2e-output.json' },
audits: [{ slug: 'cypress-e2e', title: 'Cypress E2E results' }],
} satisfies PluginConfig),
).not.toThrow();
});
it('should accept a valid plugin configuration with a score target', () => {
expect(() =>
pluginConfigSchema.parse({
slug: 'lighthouse',
title: 'Lighthouse',
icon: 'lighthouse',
runner: async () => [
{
slug: 'first-contentful-paint',
score: 0.28,
value: 3752,
displayValue: '3.8 s',
},
{
slug: 'total-blocking-time',
score: 0.91,
value: 183.5,
displayValue: '180 ms',
},
],
scoreTarget: { 'total-blocking-time': 0.9 },
audits: [
{ slug: 'first-contentful-paint', title: 'First Contentful Paint' },
{ slug: 'total-blocking-time', title: 'Total Blocking Time' },
],
} satisfies PluginConfig),
).not.toThrow();
});
it('should throw for a plugin configuration without audits', () => {
expect(() =>
pluginConfigSchema.parse({
slug: 'jest',
title: 'Jest',
icon: 'jest',
runner: { command: 'npm run test', outputFile: 'jest-output.json' },
audits: [],
} satisfies PluginConfig),
).toThrow('too_small');
});
it('should throw for a configuration with a group reference missing among audits', () => {
expect(() =>
pluginConfigSchema.parse({
slug: 'cypress',
title: 'Cypress testing',
icon: 'cypress',
runner: { command: 'npx cypress run', outputFile: 'output.json' },
audits: [{ slug: 'jest', title: 'Jest' }],
groups: [
{
slug: 'cyct',
title: 'Cypress component testing',
refs: [{ slug: 'cyct', weight: 5 }],
},
],
} satisfies PluginConfig),
).toThrow(
String.raw`Group references audits which don't exist in this plugin: \"cyct\"`,
);
});
it('should throw for a plugin configuration that has a group but empty audits', () => {
expect(() =>
pluginConfigSchema.parse({
slug: 'cypress',
title: 'Cypress testing',
icon: 'cypress',
runner: { command: 'npx cypress run', outputFile: 'output.json' },
audits: [],
groups: [
{
slug: 'cyct',
title: 'Cypress component testing',
refs: [{ slug: 'cyct', weight: 5 }],
},
],
} satisfies PluginConfig),
).toThrow(
String.raw`Group references audits which don't exist in this plugin: \"cyct\"`,
);
});
it('should throw for an invalid plugin slug', () => {
expect(() =>
pluginConfigSchema.parse({
slug: '-invalid-jest',
title: 'Jest',
icon: 'jest',
runner: { command: 'npm run test', outputFile: 'jest-output.json' },
audits: [],
} satisfies PluginConfig),
).toThrow('slug has to follow the pattern');
});
});