Skip to content

Commit

Permalink
Merge pull request #376 from storybookjs/feat/support-story-filename
Browse files Browse the repository at this point in the history
Feature: Support .story files
  • Loading branch information
yannbf authored Nov 8, 2023
2 parents 1ba363f + c0159ff commit 33f2385
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,14 @@ Here's an example of an ejected file used to extend the tests timeout from Jest:
// ./test-runner-jest.config.js
const { getJestConfig } = require('@storybook/test-runner');

const testRunnerConfig = getJestConfig();

/**
* @type {import('@jest/types').Config.InitialOptions}
*/
module.exports = {
// The default configuration comes from @storybook/test-runner
...getJestConfig(),
...testRunnerConfig,
/** Add your own overrides below
* @see https://jestjs.io/docs/configuration
*/
Expand Down Expand Up @@ -808,12 +810,14 @@ When running with `--stories-json`, tests get generated in a temporary folder an
// ./test-runner-jest.config.js
const { getJestConfig } = require('@storybook/test-runner');

const testRunnerConfig = getJestConfig();

/**
* @type {import('@jest/types').Config.InitialOptions}
*/
module.exports = {
// The default configuration comes from @storybook/test-runner
...getJestConfig(),
...testRunnerConfig,
snapshotResolver: './snapshot-resolver.js',
};
```
Expand Down
9 changes: 6 additions & 3 deletions playwright/test-runner-jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const { getJestConfig } = require('@storybook/test-runner');

// The default configuration comes from @storybook/test-runner
const testRunnerConfig = getJestConfig();

/**
* @type {import('@jest/types').Config.InitialOptions}
*/
module.exports = {
// The default configuration comes from @storybook/test-runner
...getJestConfig(),
/** Add your own overrides below
...testRunnerConfig,
/** Add your own overrides below, and make sure
* to merge testRunnerConfig properties with your own
* @see https://jestjs.io/docs/configuration
*/
};
4 changes: 3 additions & 1 deletion src/config/jest-playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export const getJestConfig = () => {
reporters,
testMatch,
transform: {
'^.+\\.stories\\.[jt]sx?$': require.resolve(TEST_RUNNER_PATH + '/playwright/transform'),
'^.+\\.(story|stories)\\.[jt]sx?$': require.resolve(
TEST_RUNNER_PATH + '/playwright/transform'
),
'^.+\\.[jt]sx?$': swcJestPath,
},
snapshotSerializers: [jestSerializerHtmlPath],
Expand Down
2 changes: 2 additions & 0 deletions src/test-storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ const main = async () => {
);
}

process.env.TEST_ROOT = process.cwd();

if (runnerOptions.indexJson || shouldRunIndexJson) {
indexTmpDir = await getIndexTempDir(targetURL);
process.env.TEST_ROOT = indexTmpDir;
Expand Down
6 changes: 4 additions & 2 deletions test-runner-jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ process.env.STORYBOOK_TEST_RUNNER_PATH = path.resolve(__dirname);

const { getJestConfig } = require('./dist');

const testRunnerConfig = getJestConfig();

module.exports = {
...getJestConfig(),
...testRunnerConfig,
cacheDirectory: 'node_modules/.cache/storybook/test-runner',
transform: {
'^.+\\.stories\\.[jt]sx?$': './playwright/transform',
'^.+\\.(story|stories)\\.[jt]sx?$': './playwright/transform',
'^.+\\.[jt]sx?$': '@swc/jest',
},
globalSetup: './playwright/global-setup.js',
Expand Down

0 comments on commit 33f2385

Please sign in to comment.