feat(plugin-jsdocs): add setup wizard binding · code-pushup/cli@0a047d5

1+

import type { PluginAnswer } from '@code-pushup/models';

2+

import { jsDocsSetupBinding as binding } from './binding.js';

3+4+

const defaultAnswers: Record<string, PluginAnswer> = {

5+

'jsdocs.patterns': 'src/**/*.ts, src/**/*.js, !**/node_modules',

6+

'jsdocs.categories': true,

7+

};

8+9+

const noCategoryAnswers: Record<string, PluginAnswer> = {

10+

...defaultAnswers,

11+

'jsdocs.categories': false,

12+

};

13+14+

describe('jsDocsSetupBinding', () => {

15+

describe('prompts', () => {

16+

it('should default to common TypeScript and JavaScript source patterns', async () => {

17+

await expect(binding.prompts!()).resolves.toIncludeAllPartialMembers([

18+

{

19+

key: 'jsdocs.patterns',

20+

type: 'input',

21+

default: 'src/**/*.ts, src/**/*.js, !**/node_modules',

22+

},

23+

]);

24+

});

25+26+

it('should offer to add categories by default', async () => {

27+

await expect(binding.prompts!()).resolves.toIncludeAllPartialMembers([

28+

{ key: 'jsdocs.categories', type: 'confirm', default: true },

29+

]);

30+

});

31+

});

32+33+

describe('generateConfig', () => {

34+

it('should import from @code-pushup/jsdocs-plugin', () => {

35+

const { imports } = binding.generateConfig(defaultAnswers);

36+

expect(imports).toStrictEqual([

37+

expect.objectContaining({

38+

defaultImport: 'jsDocsPlugin',

39+

}),

40+

]);

41+

});

42+43+

it('should pass multiple patterns as array to plugin call', () => {

44+

const { pluginInit } = binding.generateConfig(defaultAnswers);

45+

expect(pluginInit).toStrictEqual([

46+

'jsDocsPlugin([',

47+

" 'src/**/*.ts',",

48+

" 'src/**/*.js',",

49+

" '!**/node_modules',",

50+

']),',

51+

]);

52+

});

53+54+

it('should pass single pattern as string to plugin call', () => {

55+

const { pluginInit } = binding.generateConfig({

56+

...defaultAnswers,

57+

'jsdocs.patterns': 'src/**/*.ts',

58+

});

59+

expect(pluginInit).toStrictEqual(["jsDocsPlugin('src/**/*.ts'),"]);

60+

});

61+62+

it('should generate Documentation category from documentation-coverage group', () => {

63+

const { categories } = binding.generateConfig(defaultAnswers);

64+

expect(categories).toStrictEqual([

65+

expect.objectContaining({

66+

slug: 'docs',

67+

title: 'Documentation',

68+

refs: [

69+

expect.objectContaining({

70+

plugin: 'jsdocs',

71+

slug: 'documentation-coverage',

72+

}),

73+

],

74+

}),

75+

]);

76+

});

77+78+

it('should omit categories when declined', () => {

79+

const { categories } = binding.generateConfig(noCategoryAnswers);

80+

expect(categories).toBeUndefined();

81+

});

82+

});

83+

});