@@ -257,38 +257,6 @@ function fail() {
257257 process . exitCode = 1
258258}
259259
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-
292260async function generateFrameworkConfigFile ( options : {
293261 configPath : string
294262 framework : string
@@ -318,7 +286,6 @@ async function generateFrameworkConfigFile(options: {
318286 `})` ,
319287 '' ,
320288 ] . 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
322289 await writeFile ( options . configPath , configContent )
323290}
324291
@@ -403,7 +370,6 @@ export async function create(): Promise<void> {
403370 return fail ( )
404371 }
405372
406- // TODO: allow multiselect
407373 const { browsers } = await prompt ( {
408374 type : 'multiselect' ,
409375 name : 'browsers' ,
@@ -474,19 +440,24 @@ export async function create(): Promise<void> {
474440 log ( )
475441
476442 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,
486449 provider,
487450 browsers,
488451 } )
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+ )
490461 }
491462 else {
492463 const configPath = resolve ( process . cwd ( ) , `vitest.config.${ lang } ` )
@@ -497,7 +468,7 @@ export async function create(): Promise<void> {
497468 provider,
498469 browsers,
499470 } )
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 ) ) )
501472 }
502473
503474 log ( )
0 commit comments