@@ -18,21 +18,26 @@ vi.mock('./monorepo.js', async importOriginal => ({
1818 addCodePushUpCommand : vi . fn ( ) . mockResolvedValue ( undefined ) ,
1919} ) ) ;
2020
21- const TEST_BINDING : PluginSetupBinding = {
22- slug : 'test-plugin' ,
23- title : 'Test Plugin' ,
24- packageName : '@code-pushup/test-plugin' ,
25- isRecommended : ( ) => Promise . resolve ( true ) ,
26- generateConfig : ( ) => ( {
27- imports : [
28- {
29- moduleSpecifier : '@code-pushup/test-plugin' ,
30- defaultImport : 'testPlugin' ,
31- } ,
32- ] ,
33- pluginInit : [ 'testPlugin(),' ] ,
34- } ) ,
35- } ;
21+ function createBinding (
22+ overrides ?: Partial < PluginSetupBinding > ,
23+ ) : PluginSetupBinding {
24+ return {
25+ slug : 'test-plugin' ,
26+ title : 'Test Plugin' ,
27+ packageName : '@code-pushup/test-plugin' ,
28+ isRecommended : ( ) => Promise . resolve ( true ) ,
29+ generateConfig : ( ) => ( {
30+ imports : [
31+ {
32+ moduleSpecifier : '@code-pushup/test-plugin' ,
33+ defaultImport : 'testPlugin' ,
34+ } ,
35+ ] ,
36+ pluginInit : [ 'testPlugin(),' ] ,
37+ } ) ,
38+ ...overrides ,
39+ } ;
40+ }
3641
3742describe ( 'runSetupWizard' , ( ) => {
3843 describe ( 'TypeScript config' , ( ) => {
@@ -41,7 +46,7 @@ describe('runSetupWizard', () => {
4146 } ) ;
4247
4348 it ( 'should generate ts config and log success' , async ( ) => {
44- await runSetupWizard ( [ TEST_BINDING ] , {
49+ await runSetupWizard ( [ createBinding ( ) ] , {
4550 yes : true ,
4651 'target-dir' : MEMFS_VOLUME ,
4752 } ) ;
@@ -67,7 +72,7 @@ describe('runSetupWizard', () => {
6772 } ) ;
6873
6974 it ( 'should log dry-run message without writing files' , async ( ) => {
70- await runSetupWizard ( [ TEST_BINDING ] , {
75+ await runSetupWizard ( [ createBinding ( ) ] , {
7176 yes : true ,
7277 'dry-run' : true ,
7378 'target-dir' : MEMFS_VOLUME ,
@@ -109,7 +114,7 @@ describe('runSetupWizard', () => {
109114 } ) ;
110115
111116 it ( 'should generate .mjs config when js format is auto-detected' , async ( ) => {
112- await runSetupWizard ( [ TEST_BINDING ] , {
117+ await runSetupWizard ( [ createBinding ( ) ] , {
113118 yes : true ,
114119 'target-dir' : MEMFS_VOLUME ,
115120 } ) ;
@@ -136,7 +141,7 @@ describe('runSetupWizard', () => {
136141 MEMFS_VOLUME ,
137142 ) ;
138143
139- await runSetupWizard ( [ TEST_BINDING ] , {
144+ await runSetupWizard ( [ createBinding ( ) ] , {
140145 yes : true ,
141146 'config-format' : 'js' ,
142147 'target-dir' : MEMFS_VOLUME ,
@@ -159,40 +164,26 @@ describe('runSetupWizard', () => {
159164 } ) ;
160165 } ) ;
161166
162- describe ( 'Monorepo config' , ( ) => {
163- const PROJECT_BINDING : PluginSetupBinding = {
164- slug : 'test-plugin' ,
165- title : 'Test Plugin' ,
166- packageName : '@code-pushup/test-plugin' ,
167- isRecommended : ( ) => Promise . resolve ( true ) ,
168- generateConfig : ( ) => ( {
169- imports : [
170- {
171- moduleSpecifier : '@code-pushup/test-plugin' ,
172- defaultImport : 'testPlugin' ,
173- } ,
167+ it ( 'should log a heading for each plugin with prompts' , async ( ) => {
168+ vol . fromJSON ( { 'tsconfig.json' : '{}' } , MEMFS_VOLUME ) ;
169+ const withPrompts = ( title : string ) =>
170+ createBinding ( {
171+ title,
172+ prompts : async ( ) => [
173+ { key : 'x' , message : 'X:' , type : 'input' , default : '' } ,
174174 ] ,
175- pluginInit : [ 'testPlugin(),' ] ,
176- } ) ,
177- } ;
178-
179- const ROOT_BINDING : PluginSetupBinding = {
180- slug : 'root-plugin' ,
181- title : 'Root Plugin' ,
182- packageName : '@code-pushup/root-plugin' ,
183- scope : 'root' ,
184- isRecommended : ( ) => Promise . resolve ( true ) ,
185- generateConfig : ( ) => ( {
186- imports : [
187- {
188- moduleSpecifier : '@code-pushup/root-plugin' ,
189- defaultImport : 'rootPlugin' ,
190- } ,
191- ] ,
192- pluginInit : [ 'rootPlugin(),' ] ,
193- } ) ,
194- } ;
175+ } ) ;
176+
177+ await runSetupWizard (
178+ [ withPrompts ( 'Alpha' ) , createBinding ( ) , withPrompts ( 'Beta' ) ] ,
179+ { yes : true , 'target-dir' : MEMFS_VOLUME } ,
180+ ) ;
195181
182+ expect ( logger . info ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Alpha' ) ) ;
183+ expect ( logger . info ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Beta' ) ) ;
184+ } ) ;
185+
186+ describe ( 'Monorepo config' , ( ) => {
196187 beforeEach ( ( ) => {
197188 vol . fromJSON (
198189 {
@@ -216,7 +207,7 @@ describe('runSetupWizard', () => {
216207 } ) ;
217208
218209 it ( 'should generate preset and per-project configs' , async ( ) => {
219- await runSetupWizard ( [ PROJECT_BINDING ] , {
210+ await runSetupWizard ( [ createBinding ( ) ] , {
220211 yes : true ,
221212 mode : 'monorepo' ,
222213 'target-dir' : MEMFS_VOLUME ,
@@ -269,7 +260,23 @@ describe('runSetupWizard', () => {
269260 } ) ;
270261
271262 it ( 'should generate root config for root-scoped plugins' , async ( ) => {
272- await runSetupWizard ( [ PROJECT_BINDING , ROOT_BINDING ] , {
263+ const rootBinding = createBinding ( {
264+ slug : 'root-plugin' ,
265+ title : 'Root Plugin' ,
266+ packageName : '@code-pushup/root-plugin' ,
267+ scope : 'root' ,
268+ generateConfig : ( ) => ( {
269+ imports : [
270+ {
271+ moduleSpecifier : '@code-pushup/root-plugin' ,
272+ defaultImport : 'rootPlugin' ,
273+ } ,
274+ ] ,
275+ pluginInit : [ 'rootPlugin(),' ] ,
276+ } ) ,
277+ } ) ;
278+
279+ await runSetupWizard ( [ createBinding ( ) , rootBinding ] , {
273280 yes : true ,
274281 mode : 'monorepo' ,
275282 'target-dir' : MEMFS_VOLUME ,
0 commit comments