@@ -257,38 +257,6 @@ function fail() {
257
257
process . exitCode = 1
258
258
}
259
259
260
- async function generateWorkspaceFile ( options : {
261
- configPath : string
262
- rootConfig : string
263
- provider : string
264
- browsers : string [ ]
265
- } ) {
266
- const relativeRoot = relative ( dirname ( options . configPath ) , options . rootConfig )
267
- const workspaceContent = [
268
- `import { defineWorkspace } from 'vitest/config'` ,
269
- '' ,
270
- 'export default defineWorkspace([' ,
271
- ' // If you want to keep running your existing tests in Node.js, uncomment the next line.' ,
272
- ` // '${ relativeRoot } ',` ,
273
- ` {` ,
274
- ` extends: '${ relativeRoot } ',` ,
275
- ` test: {` ,
276
- ` browser: {` ,
277
- ` enabled: true,` ,
278
- ` provider: '${ options . provider } ',` ,
279
- options . provider !== 'preview' && ` // ${ getProviderDocsLink ( options . provider ) } ` ,
280
- ` instances: [` ,
281
- ...options . browsers . map ( browser => ` { browser: '${ browser } ' },` ) ,
282
- ` ],` ,
283
- ` },` ,
284
- ` },` ,
285
- ` },` ,
286
- `])` ,
287
- '' ,
288
- ] . filter ( c => typeof c === 'string' ) . join ( '\n' )
289
- await writeFile ( options . configPath , workspaceContent )
290
- }
291
-
292
260
async function generateFrameworkConfigFile ( options : {
293
261
configPath : string
294
262
framework : string
@@ -318,7 +286,6 @@ async function generateFrameworkConfigFile(options: {
318
286
`})` ,
319
287
'' ,
320
288
] . filter ( t => typeof t === 'string' ) . join ( '\n' )
321
- // this file is only generated if there is already NO root config which is an edge case
322
289
await writeFile ( options . configPath , configContent )
323
290
}
324
291
@@ -403,7 +370,6 @@ export async function create(): Promise<void> {
403
370
return fail ( )
404
371
}
405
372
406
- // TODO: allow multiselect
407
373
const { browsers } = await prompt ( {
408
374
type : 'multiselect' ,
409
375
name : 'browsers' ,
@@ -474,19 +440,24 @@ export async function create(): Promise<void> {
474
440
log ( )
475
441
476
442
if ( rootConfig ) {
477
- let browserWorkspaceFile = resolve ( dirname ( rootConfig ) , `vitest.workspace.${ lang } ` )
478
- if ( existsSync ( browserWorkspaceFile ) ) {
479
- log ( c . yellow ( '⚠' ) , c . yellow ( 'A workspace file already exists. Creating a new one for the browser tests - you can merge them manually if needed.' ) )
480
- browserWorkspaceFile = resolve ( process . cwd ( ) , `vitest.workspace.browser.${ lang } ` )
481
- }
482
- scriptCommand = `vitest --workspace=${ relative ( process . cwd ( ) , browserWorkspaceFile ) } `
483
- await generateWorkspaceFile ( {
484
- configPath : browserWorkspaceFile ,
485
- rootConfig,
443
+ const configPath = resolve ( dirname ( rootConfig ) , `vitest.browser.config.${ lang } ` )
444
+ scriptCommand = `vitest --config=${ relative ( process . cwd ( ) , configPath ) } `
445
+ await generateFrameworkConfigFile ( {
446
+ configPath,
447
+ framework,
448
+ frameworkPlugin,
486
449
provider,
487
450
browsers,
488
451
} )
489
- log ( c . green ( '✔' ) , 'Created a workspace file for browser tests:' , c . bold ( relative ( process . cwd ( ) , browserWorkspaceFile ) ) )
452
+ log (
453
+ c . green ( '✔' ) ,
454
+ 'Created a new config file for browser tests:' ,
455
+ c . bold ( relative ( process . cwd ( ) , configPath ) ) ,
456
+ // TODO: Can we modify the config ourselves?
457
+ '\nSince you already have a Vitest config file, it is recommended to copy the contents of the new file ' ,
458
+ 'into your existing config located at ' ,
459
+ c . bold ( relative ( process . cwd ( ) , rootConfig ) ) ,
460
+ )
490
461
}
491
462
else {
492
463
const configPath = resolve ( process . cwd ( ) , `vitest.config.${ lang } ` )
@@ -497,7 +468,7 @@ export async function create(): Promise<void> {
497
468
provider,
498
469
browsers,
499
470
} )
500
- log ( c . green ( '✔' ) , 'Created a config file for browser tests' , c . bold ( relative ( process . cwd ( ) , configPath ) ) )
471
+ log ( c . green ( '✔' ) , 'Created a config file for browser tests: ' , c . bold ( relative ( process . cwd ( ) , configPath ) ) )
501
472
}
502
473
503
474
log ( )
0 commit comments