From aee510c7fa28295159164ef554bae36fc5abaf22 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Mon, 13 Nov 2023 23:46:49 +0100 Subject: [PATCH] do not set test root outside index json mode --- README.md | 12 ++++++++---- src/test-storybook.ts | 2 -- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index be29b7ee..05f35e5e 100644 --- a/README.md +++ b/README.md @@ -775,8 +775,8 @@ module.exports = { rules: storyContext.parameters?.a11y?.config?.rules, }); - // from Storybook 7.0 onwards, the selector should be #storybook-root - await checkA11y(page, '#root', { + // in Storybook 6.x, the selector is #root + await checkA11y(page, '#storybook-root', { detailedReport: true, detailedReportOptions: { html: true, @@ -796,8 +796,8 @@ You can use [Playwright's built in APIs](https://playwright.dev/docs/test-snapsh // .storybook/test-runner.js module.exports = { async postRender(page, context) { - // the #root element wraps the story. From Storybook 7.0 onwards, the selector should be #storybook-root - const elementHandler = await page.$('#root'); + // the #storybook-root element wraps the story. In Storybook 6.x, the selector is #root + const elementHandler = await page.$('#storybook-root'); const innerHTML = await elementHandler.innerHTML(); expect(innerHTML).toMatchSnapshot(); }, @@ -826,6 +826,10 @@ module.exports = { // ./snapshot-resolver.js const path = require('path'); +// 👉 process.env.TEST_ROOT will only be available in --index-json or --stories-json mode. +// if you run this code without these flags, you will have to override it the test root, else it will break. +// e.g. process.env.TEST_ROOT = process.cwd() + module.exports = { resolveSnapshotPath: (testPath, snapshotExtension) => path.join(process.cwd(), '__snapshots__', path.basename(testPath) + snapshotExtension), diff --git a/src/test-storybook.ts b/src/test-storybook.ts index ae0cb608..2c220dab 100644 --- a/src/test-storybook.ts +++ b/src/test-storybook.ts @@ -335,8 +335,6 @@ const main = async () => { ); } - process.env.TEST_ROOT = process.cwd(); - if (runnerOptions.indexJson || shouldRunIndexJson) { indexTmpDir = await getIndexTempDir(targetURL); process.env.TEST_ROOT = indexTmpDir;