Skip to content

Commit

Permalink
add multiple roots if main.js points to external projects
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Aug 2, 2023
1 parent c19da16 commit 6f8f876
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/config/jest-playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,25 @@ export const getJestConfig = () => {

const reporters = STORYBOOK_JUNIT ? ['default', jestJunitPath] : ['default'];

const testMatch = (STORYBOOK_STORIES_PATTERN && STORYBOOK_STORIES_PATTERN.split(';')) || [];
const testRoots = new Set(['<rootDir>']);

testMatch.forEach((match) => {
// if any of the stories pattern contains <rootDir>/.. it means the user might be referencing
// stories outside of the project they're executing the test-runner from, e.g. monorepo
if (match.startsWith('<rootDir>/..')) {
const rootDirLevels = match.split('/..').length - 1;
// so we add those directories as roots to make sure jest can find the files
const rootDir = ['<rootDir>'].concat(Array(rootDirLevels).fill('..')).join(path.sep);
testRoots.add(`<rootDir>/` + rootDir);
}
});

let config = {
rootDir: process.cwd(),
roots: TEST_ROOT ? [TEST_ROOT] : undefined,
reporters,
testMatch: STORYBOOK_STORIES_PATTERN && STORYBOOK_STORIES_PATTERN.split(';'),
testMatch,
transform: {
'^.+\\.stories\\.[jt]sx?$': '@storybook/test-runner/playwright/transform',
'^.+\\.[jt]sx?$': swcJestPath,
Expand Down

0 comments on commit 6f8f876

Please sign in to comment.