11import { execa } from 'execa' ;
2- import * as commonPrompts from '@travi/language-scaffolder-prompts' ;
32import * as prompts from '@form8ion/overridable-prompts' ;
43import { packageManagers , projectTypes } from '@form8ion/javascript-core' ;
54
6- import { expect , describe , it , vi , beforeEach } from 'vitest' ;
5+ import { describe , expect , it , vi } from 'vitest' ;
76import any from '@travi/any' ;
87import { when } from 'vitest-when' ;
98
@@ -15,19 +14,16 @@ import {prompt} from './questions.js';
1514import * as validators from './validators.js' ;
1615
1716vi . mock ( 'execa' ) ;
18- vi . mock ( '@travi/language-scaffolder-prompts' ) ;
1917vi . mock ( '@form8ion/overridable-prompts' ) ;
2018vi . mock ( '../../thirdparty-wrappers/npm-conf.js' ) ;
2119vi . mock ( '../dialects/prompt-choices.js' ) ;
2220vi . mock ( './validators.js' ) ;
2321vi . mock ( './conditionals.js' ) ;
2422
2523describe ( 'prompts' , ( ) => {
26- const commonQuestions = any . listOf ( any . simpleObject ) ;
2724 const decisions = any . simpleObject ( ) ;
2825 const vcs = any . simpleObject ( ) ;
2926 const pathWithinParent = any . string ( ) ;
30- const ciServices = any . simpleObject ( ) ;
3127 const visibility = any . word ( ) ;
3228 const integrationTested = any . boolean ( ) ;
3329 const unitTested = any . boolean ( ) ;
@@ -45,10 +41,10 @@ describe('prompts', () => {
4541 const scope = any . word ( ) ;
4642 const provideExample = any . boolean ( ) ;
4743 const answers = {
48- [ commonPrompts . questionNames . UNIT_TESTS ] : unitTested ,
49- [ commonPrompts . questionNames . INTEGRATION_TESTS ] : integrationTested ,
44+ [ questionNames . UNIT_TESTS ] : unitTested ,
45+ [ questionNames . INTEGRATION_TESTS ] : integrationTested ,
5046 [ questionNames . PROJECT_TYPE ] : projectType ,
51- [ commonPrompts . questionNames . CI_SERVICE ] : ci ,
47+ [ questionNames . CI_SERVICE ] : ci ,
5248 [ questionNames . HOST ] : chosenHost ,
5349 [ questionNames . SCOPE ] : scope ,
5450 [ questionNames . NODE_VERSION_CATEGORY ] : nodeVersionCategory ,
@@ -61,12 +57,6 @@ describe('prompts', () => {
6157 } ;
6258 const logger = { info : ( ) => undefined , warn : ( ) => undefined } ;
6359
64- beforeEach ( ( ) => {
65- when ( commonPrompts . questions )
66- . calledWith ( { vcs, ciServices, pathWithinParent : undefined } )
67- . thenReturn ( commonQuestions ) ;
68- } ) ;
69-
7060 it ( 'should prompt the user for the necessary details' , async ( ) => {
7161 const npmUser = any . word ( ) ;
7262 const get = vi . fn ( ) ;
@@ -144,7 +134,18 @@ describe('prompts', () => {
144134 message : 'What is the author\'s website url?' ,
145135 default : authorUrl
146136 } ,
147- ...commonQuestions ,
137+ {
138+ name : questionNames . UNIT_TESTS ,
139+ message : 'Will this project be unit tested?' ,
140+ type : 'confirm' ,
141+ default : true
142+ } ,
143+ {
144+ name : questionNames . INTEGRATION_TESTS ,
145+ message : 'Will this project be integration tested?' ,
146+ type : 'confirm' ,
147+ default : true
148+ } ,
148149 {
149150 name : questionNames . CONFIGURE_LINTING ,
150151 message : 'Will there be source code that should be linted?' ,
@@ -167,10 +168,9 @@ describe('prompts', () => {
167168 ] , decisions )
168169 . thenResolve ( { ...answers , [ questionNames . CONFIGURE_LINTING ] : any . word ( ) } ) ;
169170
170- expect ( await prompt ( ciServices , hosts , visibility , vcs , decisions , configs , undefined , { logger} ) ) . toEqual ( {
171+ expect ( await prompt ( hosts , visibility , vcs , decisions , configs , undefined , { logger} ) ) . toEqual ( {
171172 tests,
172173 projectType,
173- ci,
174174 chosenHost,
175175 scope,
176176 nodeVersionCategory,
@@ -189,10 +189,9 @@ describe('prompts', () => {
189189 when ( execa ) . calledWith ( 'npm' , [ 'whoami' ] ) . thenResolve ( { stdout : npmUser } ) ;
190190 prompts . prompt . mockResolvedValue ( { ...answers , [ questionNames . CONFIGURE_LINTING ] : false } ) ;
191191
192- expect ( await prompt ( ciServices , { } , visibility , vcs , decisions , undefined , undefined , { logger} ) ) . toEqual ( {
192+ expect ( await prompt ( { } , visibility , vcs , decisions , undefined , undefined , { logger} ) ) . toEqual ( {
193193 tests,
194194 projectType,
195- ci,
196195 chosenHost,
197196 scope,
198197 nodeVersionCategory,
@@ -207,12 +206,9 @@ describe('prompts', () => {
207206 it ( 'should not ask about node version for sub-projects since the parent project already defines' , async ( ) => {
208207 when ( execa ) . calledWith ( 'npm' , [ 'whoami' ] ) . thenResolve ( { stdout : any . word ( ) } ) ;
209208 npmConfFactory . mockReturnValue ( { get : ( ) => undefined } ) ;
210- when ( commonPrompts . questions )
211- . calledWith ( { vcs, ciServices, pathWithinParent} )
212- . thenReturn ( commonQuestions ) ;
213209 prompts . prompt . mockResolvedValue ( answers ) ;
214210
215- await prompt ( ciServices , { } , 'CS' , vcs , null , null , pathWithinParent , { logger} ) ;
211+ await prompt ( { } , 'CS' , vcs , null , null , pathWithinParent , { logger} ) ;
216212
217213 const [ questions ] = prompts . prompt . mock . lastCall ;
218214 expect ( questions . filter ( question => questionNames . NODE_VERSION_CATEGORY === question . name ) . length ) . toEqual ( 0 ) ;
@@ -221,12 +217,9 @@ describe('prompts', () => {
221217 it ( 'should not ask whether closed source packages should be scoped' , async ( ) => {
222218 when ( execa ) . calledWith ( 'npm' , [ 'whoami' ] ) . thenResolve ( { stdout : any . word ( ) } ) ;
223219 npmConfFactory . mockReturnValue ( { get : ( ) => undefined } ) ;
224- when ( commonPrompts . questions )
225- . calledWith ( { vcs, ciServices, pathWithinParent} )
226- . thenReturn ( commonQuestions ) ;
227220 prompts . prompt . mockResolvedValue ( answers ) ;
228221
229- await prompt ( ciServices , { } , 'CS' , vcs , null , null , pathWithinParent , { logger} ) ;
222+ await prompt ( { } , 'CS' , vcs , null , null , pathWithinParent , { logger} ) ;
230223
231224 const [ questions ] = prompts . prompt . mock . lastCall ;
232225 expect ( questions . filter ( question => questionNames . SHOULD_BE_SCOPED === question . name ) . length ) . toEqual ( 0 ) ;
@@ -235,12 +228,9 @@ describe('prompts', () => {
235228 it ( 'should not ask whether inner source packages should be scoped' , async ( ) => {
236229 when ( execa ) . calledWith ( 'npm' , [ 'whoami' ] ) . thenResolve ( { stdout : any . word ( ) } ) ;
237230 npmConfFactory . mockReturnValue ( { get : ( ) => undefined } ) ;
238- when ( commonPrompts . questions )
239- . calledWith ( { vcs, ciServices, pathWithinParent} )
240- . thenReturn ( commonQuestions ) ;
241231 prompts . prompt . mockResolvedValue ( answers ) ;
242232
243- await prompt ( ciServices , { } , 'ISS' , vcs , null , null , pathWithinParent , { logger} ) ;
233+ await prompt ( { } , 'ISS' , vcs , null , null , pathWithinParent , { logger} ) ;
244234
245235 const [ questions ] = prompts . prompt . mock . lastCall ;
246236 expect ( questions . filter ( question => questionNames . SHOULD_BE_SCOPED === question . name ) . length ) . toEqual ( 0 ) ;
@@ -249,12 +239,9 @@ describe('prompts', () => {
249239 it ( 'should handle a non-logged-in user gracefully' , async ( ) => {
250240 when ( execa ) . calledWith ( 'npm' , [ 'whoami' ] ) . thenReject ( new Error ( ) ) ;
251241 npmConfFactory . mockReturnValue ( { get : ( ) => undefined } ) ;
252- when ( commonPrompts . questions )
253- . calledWith ( { vcs, ciServices, pathWithinParent} )
254- . thenReturn ( commonQuestions ) ;
255242 prompts . prompt . mockResolvedValue ( answers ) ;
256243
257- await prompt ( ciServices , { } , 'OSS' , vcs , { } , null , pathWithinParent , { logger} ) ;
244+ await prompt ( { } , 'OSS' , vcs , { } , null , pathWithinParent , { logger} ) ;
258245
259246 const [ questions ] = prompts . prompt . mock . lastCall ;
260247 expect ( questions . filter ( question => questionNames . SHOULD_BE_SCOPED === question . name ) . length ) . toEqual ( 1 ) ;
0 commit comments