-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbinding.unit.test.ts
More file actions
83 lines (74 loc) · 2.57 KB
/
binding.unit.test.ts
File metadata and controls
83 lines (74 loc) · 2.57 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
import type { PluginAnswer } from '@code-pushup/models';
import { jsDocsSetupBinding as binding } from './binding.js';
const defaultAnswers: Record<string, PluginAnswer> = {
'jsdocs.patterns': 'src/**/*.ts, src/**/*.js, !**/node_modules',
'jsdocs.categories': true,
};
const noCategoryAnswers: Record<string, PluginAnswer> = {
...defaultAnswers,
'jsdocs.categories': false,
};
describe('jsDocsSetupBinding', () => {
describe('prompts', () => {
it('should default to common TypeScript and JavaScript source patterns', async () => {
await expect(binding.prompts!()).resolves.toIncludeAllPartialMembers([
{
key: 'jsdocs.patterns',
type: 'input',
default: 'src/**/*.ts, src/**/*.js, !**/node_modules',
},
]);
});
it('should offer to add categories by default', async () => {
await expect(binding.prompts!()).resolves.toIncludeAllPartialMembers([
{ key: 'jsdocs.categories', type: 'confirm', default: true },
]);
});
});
describe('generateConfig', () => {
it('should import from @code-pushup/jsdocs-plugin', () => {
const { imports } = binding.generateConfig(defaultAnswers);
expect(imports).toStrictEqual([
expect.objectContaining({
defaultImport: 'jsDocsPlugin',
}),
]);
});
it('should pass multiple patterns as array to plugin call', () => {
const { pluginInit } = binding.generateConfig(defaultAnswers);
expect(pluginInit).toStrictEqual([
'jsDocsPlugin([',
" 'src/**/*.ts',",
" 'src/**/*.js',",
" '!**/node_modules',",
']),',
]);
});
it('should pass single pattern as string to plugin call', () => {
const { pluginInit } = binding.generateConfig({
...defaultAnswers,
'jsdocs.patterns': 'src/**/*.ts',
});
expect(pluginInit).toStrictEqual(["jsDocsPlugin('src/**/*.ts'),"]);
});
it('should generate Documentation category from documentation-coverage group', () => {
const { categories } = binding.generateConfig(defaultAnswers);
expect(categories).toStrictEqual([
expect.objectContaining({
slug: 'docs',
title: 'Documentation',
refs: [
expect.objectContaining({
plugin: 'jsdocs',
slug: 'documentation-coverage',
}),
],
}),
]);
});
it('should omit categories when declined', () => {
const { categories } = binding.generateConfig(noCategoryAnswers);
expect(categories).toBeUndefined();
});
});
});