Skip to content

Commit

Permalink
Merge pull request #387 from storybookjs/fix/unexpected-test-root
Browse files Browse the repository at this point in the history
Fix: Do not set test root outside index json mode
  • Loading branch information
yannbf committed Nov 13, 2023
2 parents 33f2385 + aee510c commit 12fe79b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
},
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 0 additions & 2 deletions src/test-storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 12fe79b

Please sign in to comment.