Skip to content

Commit

Permalink
Merge pull request #30309 from storybookjs/valentin/introduce-instanc…
Browse files Browse the repository at this point in the history
…es-vitest-3

Addon Test: Support Vitest 3 browser.test.instances field
  • Loading branch information
valentinpalkovic authored Jan 22, 2025
2 parents 61fa84b + 2bf54fb commit 4d2989d
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 335 deletions.
6 changes: 5 additions & 1 deletion code/.storybook/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ export default mergeConfig(
testNamePattern: /^(?!.*(UseState)).*$/,
browser: {
enabled: true,
name: 'chromium',
provider: 'playwright',
instances: [
{
browser: 'chromium',
},
],
headless: true,
screenshotFailures: false,
},
Expand Down
6 changes: 3 additions & 3 deletions code/addons/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"@types/istanbul-lib-report": "^3.0.3",
"@types/node": "^22.0.0",
"@types/semver": "^7",
"@vitest/browser": "3.0.0-beta.4",
"@vitest/runner": "3.0.0-beta.4",
"@vitest/browser": "^3.0.2",
"@vitest/runner": "^3.0.2",
"ansi-to-html": "^0.7.2",
"boxen": "^8.0.1",
"es-toolkit": "^1.22.0",
Expand All @@ -116,7 +116,7 @@
"tree-kill": "^1.2.2",
"ts-dedent": "^2.2.0",
"typescript": "^5.3.2",
"vitest": "3.0.0-beta.4"
"vitest": "^3.0.2"
},
"peerDependencies": {
"@vitest/browser": "^2.1.1 || ^3.0.0",
Expand Down
32 changes: 20 additions & 12 deletions code/addons/test/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,24 @@ export default async function postInstall(options: PostinstallOptions) {

const isVitest3OrLater = !!(coercedVitestVersion && satisfies(coercedVitestVersion, '>=3.0.0'));

const browserConfig = isVitest3OrLater
? `{
enabled: true,
headless: true,
provider: 'playwright',
instances: [
{
browser: 'chromium',
}
]
}`
: `{
enabled: true,
headless: true,
name: 'chromium',
provider: 'playwright'
}`;

if (isVitest3OrLater && fileExtension === 'ts' && !vitestShimFile) {
await writeFile(
'vitest.shims.d.ts',
Expand Down Expand Up @@ -465,12 +483,7 @@ export default async function postInstall(options: PostinstallOptions) {
],
test: {
name: 'storybook',
browser: {
enabled: true,
headless: true,
name: 'chromium',
provider: 'playwright',
},
browser: ${browserConfig},
setupFiles: ['${vitestSetupFilePath}'],
},
},
Expand Down Expand Up @@ -509,12 +522,7 @@ export default async function postInstall(options: PostinstallOptions) {
],
test: {
name: 'storybook',
browser: {
enabled: true,
headless: true,
name: 'chromium',
provider: 'playwright',
},
browser: ${browserConfig},
setupFiles: ['${vitestSetupFilePath}'],
},
});
Expand Down
1 change: 0 additions & 1 deletion code/addons/test/src/vitest-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
: {}),

browser: {
...inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test?.browser,
commands: {
getInitialGlobals: () => {
const envConfig = JSON.parse(process.env.VITEST_STORYBOOK_CONFIG ?? '{}');
Expand Down
8 changes: 4 additions & 4 deletions code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@
"@typescript-eslint/parser": "7.18.0",
"@vitejs/plugin-react": "^4.3.2",
"@vitejs/plugin-vue": "^4.4.0",
"@vitest/browser": "3.0.0-beta.4",
"@vitest/coverage-istanbul": "3.0.0-beta.4",
"@vitest/coverage-v8": "3.0.0-beta.4",
"@vitest/browser": "^3.0.2",
"@vitest/coverage-istanbul": "^3.0.2",
"@vitest/coverage-v8": "^3.0.2",
"create-storybook": "workspace:*",
"cross-env": "^7.0.3",
"danger": "^12.3.3",
Expand Down Expand Up @@ -223,7 +223,7 @@
"util": "^0.12.4",
"vite": "^4.0.0",
"vite-plugin-inspect": "^0.8.5",
"vitest": "3.0.0-beta.4",
"vitest": "^3.0.2",
"wait-on": "^7.0.1"
},
"dependenciesMeta": {
Expand Down
Loading

0 comments on commit 4d2989d

Please sign in to comment.