-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathplugins.unit.test.ts
More file actions
45 lines (41 loc) · 1.34 KB
/
plugins.unit.test.ts
File metadata and controls
45 lines (41 loc) · 1.34 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
import { parsePluginSlugs, validatePluginSlugs } from './plugins.js';
describe('parsePluginSlugs', () => {
it.each([
['eslint,coverage', ['eslint', 'coverage']],
[' eslint , coverage ', ['eslint', 'coverage']],
['eslint,eslint', ['eslint']],
['eslint,,coverage', ['eslint', 'coverage']],
])('should parse %j into %j', (input, expected) => {
expect(parsePluginSlugs(input)).toStrictEqual(expected);
});
});
describe('validatePluginSlugs', () => {
const bindings = [
{
slug: 'eslint',
title: 'ESLint',
packageName: '@code-pushup/eslint-plugin',
generateConfig: () => ({ imports: [], pluginInit: [] }),
},
{
slug: 'coverage',
title: 'Code Coverage',
packageName: '@code-pushup/coverage-plugin',
generateConfig: () => ({ imports: [], pluginInit: [] }),
},
];
it('should not throw for valid or missing slugs', () => {
expect(() => validatePluginSlugs(bindings)).not.toThrow();
expect(() =>
validatePluginSlugs(bindings, ['eslint', 'coverage']),
).not.toThrow();
});
it('should throw TypeError on unknown slug', () => {
expect(() => validatePluginSlugs(bindings, ['eslint', 'unknown'])).toThrow(
TypeError,
);
expect(() => validatePluginSlugs(bindings, ['eslint', 'unknown'])).toThrow(
'Unknown plugin slugs: unknown',
);
});
});