11import { readFile , writeFile } from 'node:fs/promises' ;
22import path from 'node:path' ;
3+ import { eslintSetupBinding } from '@code-pushup/eslint-plugin' ;
34import { cleanTestFolder } from '@code-pushup/test-utils' ;
45import { getGitRoot } from '@code-pushup/utils' ;
56import type { PluginSetupBinding } from './types.js' ;
@@ -19,7 +20,7 @@ const TEST_BINDINGS: PluginSetupBinding[] = [
1920 title : 'Alpha Plugin' ,
2021 packageName : '@code-pushup/alpha-plugin' ,
2122 isRecommended : ( ) => Promise . resolve ( true ) ,
22- prompts : [
23+ prompts : async ( ) => [
2324 {
2425 key : 'alpha.path' ,
2526 message : 'Path to config' ,
@@ -222,4 +223,71 @@ describe('runSetupWizard', () => {
222223 readFile ( path . join ( outputDir , '.gitignore' ) , 'utf8' ) ,
223224 ) . resolves . toBe ( 'node_modules\n.code-pushup\n' ) ;
224225 } ) ;
226+
227+ it ( 'should generate config with ESLint plugin using defaults' , async ( ) => {
228+ await runSetupWizard ( [ eslintSetupBinding ] , {
229+ yes : true ,
230+ plugins : [ 'eslint' ] ,
231+ 'config-format' : 'ts' ,
232+ 'target-dir' : outputDir ,
233+ } ) ;
234+
235+ await expect (
236+ readFile ( path . join ( outputDir , 'code-pushup.config.ts' ) , 'utf8' ) ,
237+ ) . resolves . toMatchInlineSnapshot ( `
238+ "import eslintPlugin from '@code-pushup/eslint-plugin';
239+ import type { CoreConfig } from '@code-pushup/models';
240+
241+ export default {
242+ plugins: [
243+ await eslintPlugin(),
244+ ],
245+ categories: [
246+ {
247+ slug: 'bug-prevention',
248+ title: 'Bug prevention',
249+ description: 'Lint rules that find **potential bugs** in your code.',
250+ refs: [
251+ { type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 },
252+ ],
253+ },
254+ {
255+ slug: 'code-style',
256+ title: 'Code style',
257+ description: 'Lint rules that promote **good practices** and consistency in your code.',
258+ refs: [
259+ { type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
260+ ],
261+ },
262+ ],
263+ } satisfies CoreConfig;
264+ "
265+ ` ) ;
266+ } ) ;
267+
268+ it ( 'should generate config with custom ESLint options' , async ( ) => {
269+ await runSetupWizard ( [ eslintSetupBinding ] , {
270+ yes : true ,
271+ plugins : [ 'eslint' ] ,
272+ 'config-format' : 'ts' ,
273+ 'target-dir' : outputDir ,
274+ 'eslint.eslintrc' : 'custom-eslint.config.js' ,
275+ 'eslint.patterns' : 'src' ,
276+ 'eslint.categories' : false ,
277+ } ) ;
278+
279+ await expect (
280+ readFile ( path . join ( outputDir , 'code-pushup.config.ts' ) , 'utf8' ) ,
281+ ) . resolves . toMatchInlineSnapshot ( `
282+ "import eslintPlugin from '@code-pushup/eslint-plugin';
283+ import type { CoreConfig } from '@code-pushup/models';
284+
285+ export default {
286+ plugins: [
287+ await eslintPlugin({ eslintrc: 'custom-eslint.config.js', patterns: 'src' }),
288+ ],
289+ } satisfies CoreConfig;
290+ "
291+ ` ) ;
292+ } ) ;
225293} ) ;
0 commit comments