-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(init): invalid browser config (#7475)
- Loading branch information
1 parent
0e563ea
commit 8fe641b
Showing
6 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"scripts": { | ||
"test:browser": "vitest --workspace=vitest.workspace.ts" | ||
}, | ||
"dependencies": { | ||
"vitest": "latest" | ||
}, | ||
"devDependencies": { | ||
"@vitest/browser": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { readdir, readFile, rm, writeFile } from 'node:fs/promises' | ||
import { join } from 'node:path' | ||
import { beforeEach, expect, test } from 'vitest' | ||
import { runVitestCli } from '../../test-utils' | ||
|
||
const ARROW_DOWN = '\u001B[B' | ||
const ENTER = '\n' | ||
|
||
const cwd = 'fixtures/browser-init' | ||
|
||
beforeEach(async () => { | ||
await cleanup() | ||
return cleanup | ||
|
||
async function cleanup() { | ||
for (const file of await getFiles()) { | ||
if (file !== 'package.json') { | ||
await rm(`${cwd}/${file}`, { recursive: true }) | ||
} | ||
} | ||
await writeFile(`${cwd}/vitest.config.ts`, '{}', 'utf8') | ||
} | ||
}) | ||
|
||
test('initializes project', async () => { | ||
const { vitest } = await runVitestCli({ nodeOptions: { cwd } }, 'init', 'browser') | ||
|
||
await vitest.waitForStdout('This utility will help you set up a browser testing environment.') | ||
await vitest.waitForStdout('? Choose a language for your tests') | ||
vitest.write(ENTER) | ||
|
||
await vitest.waitForStdout('Choose a browser provider') | ||
vitest.write(`${ARROW_DOWN}${ARROW_DOWN}${ENTER}`) | ||
|
||
await vitest.waitForStdout('Choose a browser') | ||
vitest.write(ENTER) | ||
|
||
await vitest.waitForStdout('Choose your framework') | ||
vitest.write(ENTER) | ||
|
||
await vitest.waitForStdout('✔ All packages are already installed.') | ||
await vitest.waitForStdout('✔ Added "test:browser" script to your package.json.') | ||
await vitest.waitForStdout(`✔ Created example test file in ${join('vitest-example', 'HelloWorld.test.ts')}`) | ||
await vitest.waitForStdout('All done! Run your tests with pnpm test:browser') | ||
|
||
expect(await getFiles()).toMatchInlineSnapshot(` | ||
[ | ||
"package.json", | ||
"vitest-example", | ||
"vitest.config.ts", | ||
"vitest.workspace.ts", | ||
] | ||
`) | ||
|
||
expect(await getFileContent('/vitest.workspace.ts')).toMatchInlineSnapshot(` | ||
"import { defineWorkspace } from 'vitest/config' | ||
export default defineWorkspace([ | ||
// If you want to keep running your existing tests in Node.js, uncomment the next line. | ||
// 'vitest.config.ts', | ||
{ | ||
extends: 'vitest.config.ts', | ||
test: { | ||
browser: { | ||
enabled: true, | ||
provider: 'preview', | ||
instances: [ | ||
], | ||
}, | ||
}, | ||
}, | ||
]) | ||
" | ||
`) | ||
|
||
expect(await getFiles('/vitest-example')).toMatchInlineSnapshot(` | ||
[ | ||
"HelloWorld.test.ts", | ||
"HelloWorld.ts", | ||
] | ||
`) | ||
}) | ||
|
||
async function getFiles(subDir = '') { | ||
return await readdir(cwd + subDir) | ||
} | ||
|
||
async function getFileContent(subDir = '') { | ||
return await readFile(cwd + subDir, 'utf8') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters