Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.16.0 #407

Merged
merged 45 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
cdcc12f
Enable strict mode
bryanjtc Nov 8, 2023
5cbce31
Name ci job
bryanjtc Nov 8, 2023
3d386a7
Add new tests
bryanjtc Nov 8, 2023
cc15dc7
Add new test
bryanjtc Nov 8, 2023
44bae0d
Modify extra arguments test to improve coverage
bryanjtc Nov 8, 2023
dc692b4
refactor: Update various files
bryanjtc Nov 10, 2023
ca36a3d
chore: Update package.json, src/config/jest-playwright.ts, src/csf/tr…
bryanjtc Nov 10, 2023
c7b4bed
feat(typings): Remove unused __getContext variable
bryanjtc Nov 10, 2023
351db47
feat: optimize Storybook configuration and test runner setup
bryanjtc Nov 10, 2023
d8f698c
feat: Add Jest Playwright configuration and test file
bryanjtc Nov 10, 2023
8b3c664
test: add hooks test file
bryanjtc Nov 11, 2023
8247d70
Merge branch 'enable-strict-mode' into improve-types
bryanjtc Nov 11, 2023
1703067
refactor: Update getStorybookMain utility functions
bryanjtc Nov 11, 2023
50cbec2
Merge branch 'next' into enable-strict-mode
bryanjtc Nov 16, 2023
a34d9e8
Fix tests
bryanjtc Nov 16, 2023
1e3e564
Fix types
bryanjtc Nov 16, 2023
de631e4
refactor(transformCsf): Simplify makePlayTest function and remove unn…
bryanjtc Nov 16, 2023
7fa52e5
feat(playwright): add optional tags property to TestRunnerConfig
bryanjtc Nov 16, 2023
f80f870
build: Update tsup.config.ts
bryanjtc Nov 16, 2023
e2afb66
Merge branch 'next' into enable-strict-mode
bryanjtc Nov 16, 2023
e73819e
Merge branch 'enable-strict-mode' into improve-types
bryanjtc Nov 16, 2023
1cd32e7
refactor(playwright): Simplify logic in transformPlaywrightJson.ts
bryanjtc Nov 16, 2023
ecc0d29
refactor: Refactor transformPlaywrightJson module and its test file
bryanjtc Nov 16, 2023
d58470d
Merge branch 'next' into enable-strict-mode
yannbf Nov 21, 2023
ef775c1
fix conflicts and add various fixes
yannbf Nov 21, 2023
96954de
fix
yannbf Nov 21, 2023
94f833f
fix tests gh action
yannbf Nov 21, 2023
1843bee
fix
yannbf Nov 21, 2023
85017e5
Merge pull request #378 from storybookjs/enable-strict-mode
yannbf Nov 21, 2023
be7b73d
Merge branch 'next' into improve-types
yannbf Nov 21, 2023
049359f
fix test
yannbf Nov 21, 2023
f4496c6
Merge pull request #383 from storybookjs/improve-types
yannbf Nov 21, 2023
ae30b04
Bump jest-playwright-preset from v3.0.1 to v4.0.0
kemuridama Nov 22, 2023
ca15e15
Adds feedback form
jonniebigodes Nov 23, 2023
4087d3d
Merge pull request #400 from kemuridama/bump_jest-playwright-preset_f…
yannbf Nov 23, 2023
40aaa6e
Merge pull request #402 from storybookjs/docs_add_feedback_form
yannbf Nov 24, 2023
aaf882b
refactor: extract the setup page scripts into a separate file
yannbf Nov 24, 2023
3e6681c
Merge pull request #403 from storybookjs/refactor/extract-setup-page-…
yannbf Nov 24, 2023
9830af5
fix sync issues between tests
yannbf Nov 24, 2023
6dbd144
fix lint
yannbf Nov 24, 2023
5db9536
Merge pull request #404 from storybookjs/fix/finally-fix-the-sync-issue
yannbf Nov 24, 2023
399dc2c
filter duplicated error messages in browser logs
yannbf Nov 27, 2023
ad3d401
Merge pull request #405 from storybookjs/fix/filter-duplicated-error-…
yannbf Nov 27, 2023
dd7eb64
introduce logLevel configuration
yannbf Nov 27, 2023
99b800b
Merge pull request #406 from storybookjs/feat/log-level
yannbf Nov 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ jobs:
- name: Install dependencies
uses: bahmutov/npm-install@v1

- name: Run jest tests
- name: Run unit tests
run: |
yarn build
yarn test --coverage

- name: Install Playwright Browsers
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Typecheck

on: [push, pull_request]

jobs:
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Use Node.js 18.x
uses: actions/setup-node@v1
with:
node-version: '18.x'

- name: Install dependencies
uses: bahmutov/npm-install@v1

- name: Type check
run: yarn tsc

3 changes: 2 additions & 1 deletion .storybook/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const customSnapshotsDir = `${process.cwd()}/${snapshotsDir}`;
const skipSnapshots = process.env.SKIP_SNAPSHOTS === 'true';

const config: TestRunnerConfig = {
logLevel: 'verbose',
tags: {
exclude: ['exclude'],
include: [],
Expand Down Expand Up @@ -39,7 +40,7 @@ const config: TestRunnerConfig = {
});

const elementHandler = (await page.$('#root')) || (await page.$('#storybook-root'));
const innerHTML = await elementHandler.innerHTML();
const innerHTML = await elementHandler?.innerHTML();
// HTML snapshot tests
expect(innerHTML).toMatchSnapshot();
},
Expand Down
2 changes: 1 addition & 1 deletion MIGRATION.portable-stories.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,4 @@ The examples above will give you the closest possible experience with the Storys

### 5 - Provide feedback

We are looking for feedback on your experience and would appreciate it if you filled [this form](some-google-form-here) to help us shape our tooling in the right direction. Thank you so much!
We are looking for feedback on your experience and would appreciate it if you filled [this form](https://forms.gle/jzcMr6cqmZZpH9Z5A) to help us shape our tooling in the right direction. Thank you so much!
2 changes: 1 addition & 1 deletion MIGRATION.test-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,4 @@ module.exports = {

### Provide feedback

We are looking for feedback on your experience and would appreciate it if you filled [this form](some-google-form-here) to help us shape our tooling in the right direction. Thank you so much!
We are looking for feedback on your experience and would appreciate it if you filled [this form](https://forms.gle/jzcMr6cqmZZpH9Z5A) to help us shape our tooling in the right direction. Thank you so much!
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Storybook test runner turns all of your stories into executable tests.
- [prepare](#prepare)
- [getHttpHeaders](#gethttpheaders)
- [tags (experimental)](#tags-experimental)
- [logLevel](#loglevel)
- [Utility functions](#utility-functions)
- [getStoryContext](#getstorycontext)
- [waitForPageReady](#waitforpageready)
Expand Down Expand Up @@ -705,6 +706,26 @@ export default config;

`tags` are used for filtering your tests. Learn more [here](#filtering-tests-experimental).

#### logLevel

When tests fail and there were browser logs during the rendering of a story, the test-runner provides the logs alongside the error message. The `logLevel` property defines what kind of logs should be displayed:

- **`info` (default):** Shows console logs, warnings, and errors.
- **`warn`:** Shows only warnings and errors.
- **`error`:** Displays only error messages.
- **`verbose`:** Includes all console outputs, including debug information and stack traces.
- **`none`:** Suppresses all log output.

```ts
// .storybook/test-runner.ts
import type { TestRunnerConfig } from '@storybook/test-runner';

const config: TestRunnerConfig = {
logLevel: 'verbose',
};
export default config;
```

### Utility functions

For more specific use cases, the test runner provides utility functions that could be useful to you.
Expand Down
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module.exports = {
testMatch: ['**/*.test.ts'],
moduleNameMapper: {
'@storybook/test-runner/playwright/global-setup': '<rootDir>/playwright/global-setup',
'@storybook/test-runner/playwright/global-teardown': '<rootDir>/playwright/global-teardown',
'@storybook/test-runner/playwright/custom-environment':
'<rootDir>/playwright/custom-environment',
'@storybook/test-runner/playwright/jest-setup': '<rootDir>/playwright/jest-setup',
'@storybook/test-runner/playwright/transform': '<rootDir>/playwright/transform',
},
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"@babel/preset-env": "^7.19.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@jest/types": "^29.6.3",
"@storybook/addon-coverage": "^0.0.9",
"@storybook/addon-essentials": "^7.5.3",
"@storybook/addon-interactions": "^7.5.3",
Expand Down Expand Up @@ -96,6 +95,7 @@
"@babel/generator": "^7.22.5",
"@babel/template": "^7.22.5",
"@babel/types": "^7.22.5",
"@jest/types": "^29.6.3",
"@storybook/core-common": "^7.0.0-beta.0 || ^7.0.0-rc.0 || ^7.0.0",
"@storybook/csf": "^0.1.1",
"@storybook/csf-tools": "^7.0.0-beta.0 || ^7.0.0-rc.0 || ^7.0.0",
Expand All @@ -110,7 +110,7 @@
"jest-circus": "^29.6.4",
"jest-environment-node": "^29.6.4",
"jest-junit": "^16.0.0",
"jest-playwright-preset": "^3.0.1",
"jest-playwright-preset": "^4.0.0",
"jest-runner": "^29.6.4",
"jest-serializer-html": "^7.1.0",
"jest-watch-typeahead": "^2.0.0",
Expand Down
9 changes: 1 addition & 8 deletions playwright/jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
const {
getTestRunnerConfig,
setPreVisit,
setPostVisit,
setupPage,
throwUncaughtPageError,
} = require('../dist');
const { getTestRunnerConfig, setPreVisit, setPostVisit, setupPage } = require('../dist');

const testRunnerConfig = getTestRunnerConfig(process.env.STORYBOOK_CONFIG_DIR);
if (testRunnerConfig) {
Expand All @@ -27,5 +21,4 @@ if (testRunnerConfig) {
// If the transformed tests need a dependency, it has to be globally available
// in order to work both in default (file transformation) and stories/index.json mode.
globalThis.__sbSetupPage = setupPage;
globalThis.__sbThrowUncaughtPageError = throwUncaughtPageError;
globalThis.__sbCollectCoverage = process.env.STORYBOOK_COLLECT_COVERAGE === 'true';
115 changes: 115 additions & 0 deletions src/config/jest-playwright.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { getJestConfig } from './jest-playwright';
import path from 'path';

describe('getJestConfig', () => {
it('returns the correct configuration 1', () => {
const jestConfig = getJestConfig();

expect(jestConfig).toEqual({
rootDir: process.cwd(),
reporters: ['default'],
testMatch: [],
transform: {
'^.+\\.(story|stories)\\.[jt]sx?$': `${path.dirname(
require.resolve('@storybook/test-runner/playwright/transform')
)}/transform.js`,
'^.+\\.[jt]sx?$': path.resolve('../test-runner/node_modules/@swc/jest'),
},
snapshotSerializers: [path.resolve('../test-runner/node_modules/jest-serializer-html')],
testEnvironmentOptions: {
'jest-playwright': {
browsers: undefined,
collectCoverage: false,
exitOnPageError: false,
},
},
watchPlugins: [
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
],
watchPathIgnorePatterns: ['coverage', '.nyc_output', '.cache'],
roots: undefined,
runner: path.resolve('../test-runner/node_modules/jest-playwright-preset/runner.js'),
globalSetup: path.resolve('playwright/global-setup.js'),
globalTeardown: path.resolve('playwright/global-teardown.js'),
testEnvironment: path.resolve('playwright/custom-environment.js'),
setupFilesAfterEnv: [
path.resolve('playwright/jest-setup.js'),
path.resolve('../test-runner/node_modules/expect-playwright/lib'),
path.resolve('../test-runner/node_modules/jest-playwright-preset/lib/extends.js'),
],
});
});

it('parses TEST_BROWSERS environment variable correctly', () => {
interface JestPlaywrightOptions {
browsers?: string[];
collectCoverage?: boolean;
}
process.env.TEST_BROWSERS = 'chromium, firefox, webkit';

const jestConfig: {
testEnvironmentOptions?: {
'jest-playwright'?: JestPlaywrightOptions;
};
} = getJestConfig();

expect(jestConfig.testEnvironmentOptions?.['jest-playwright']?.browsers as string[]).toEqual([
'chromium',
'firefox',
'webkit',
]);
});

it('sets TEST_MATCH environment variable correctly', () => {
process.env.TEST_MATCH = '**/*.test.js';

const jestConfig = getJestConfig();

expect(jestConfig.testMatch).toEqual(['**/*.test.js']);
});

it('returns the correct configuration 2', () => {
process.env.STORYBOOK_JUNIT = 'true';

const jestConfig = getJestConfig();

expect(jestConfig.reporters).toEqual(['default', path.dirname(require.resolve('jest-junit'))]);
expect(jestConfig).toMatchObject({
rootDir: process.cwd(),
roots: undefined,
testMatch: ['**/*.test.js'],
transform: {
'^.+\\.(story|stories)\\.[jt]sx?$': `${path.dirname(
require.resolve('@storybook/test-runner/playwright/transform')
)}/transform.js`,
'^.+\\.[jt]sx?$': path.dirname(require.resolve('@swc/jest')),
},
snapshotSerializers: [path.dirname(require.resolve('jest-serializer-html'))],
testEnvironmentOptions: {
'jest-playwright': {
browsers: ['chromium', 'firefox', 'webkit'],
collectCoverage: false,
},
},
watchPlugins: [
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
],
watchPathIgnorePatterns: ['coverage', '.nyc_output', '.cache'],
});
});

it('returns the correct configuration 3', () => {
process.env.TEST_ROOT = 'test';
process.env.STORYBOOK_STORIES_PATTERN = '**/*.stories.tsx';

const jestConfig = getJestConfig();

expect(jestConfig).toMatchObject({
roots: ['test'],
reporters: ['default', path.resolve('../test-runner/node_modules/jest-junit')],
testMatch: ['**/*.test.js'],
});
});
});
23 changes: 12 additions & 11 deletions src/config/jest-playwright.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'path';
import { getProjectRoot } from '@storybook/core-common';
import type { Config } from '@jest/types';

const TEST_RUNNER_PATH = process.env.STORYBOOK_TEST_RUNNER_PATH || '@storybook/test-runner';
const TEST_RUNNER_PATH = process.env.STORYBOOK_TEST_RUNNER_PATH ?? '@storybook/test-runner';

/**
* IMPORTANT NOTE:
Expand All @@ -15,7 +16,7 @@ const TEST_RUNNER_PATH = process.env.STORYBOOK_TEST_RUNNER_PATH || '@storybook/t
* This function does the same thing as `preset: 'jest-playwright-preset` but makes sure that the
* necessary moving parts are all required within the correct path.
* */
const getJestPlaywrightConfig = () => {
const getJestPlaywrightConfig = (): Config.InitialOptions => {
const presetBasePath = path.dirname(
require.resolve('jest-playwright-preset', {
paths: [path.join(__dirname, '../node_modules')],
Expand All @@ -28,18 +29,18 @@ const getJestPlaywrightConfig = () => {
);
return {
runner: path.join(presetBasePath, 'runner.js'),
globalSetup: require.resolve(TEST_RUNNER_PATH + '/playwright/global-setup.js'),
globalTeardown: require.resolve(TEST_RUNNER_PATH + '/playwright/global-teardown.js'),
testEnvironment: require.resolve(TEST_RUNNER_PATH + '/playwright/custom-environment.js'),
globalSetup: require.resolve(`${TEST_RUNNER_PATH}/playwright/global-setup.js`),
globalTeardown: require.resolve(`${TEST_RUNNER_PATH}/playwright/global-teardown.js`),
testEnvironment: require.resolve(`${TEST_RUNNER_PATH}/playwright/custom-environment.js`),
setupFilesAfterEnv: [
require.resolve(TEST_RUNNER_PATH + '/playwright/jest-setup.js'),
require.resolve(`${TEST_RUNNER_PATH}/playwright/jest-setup.js`),
expectPlaywrightPath,
path.join(presetBasePath, 'lib', 'extends.js'),
],
};
};

export const getJestConfig = () => {
export const getJestConfig = (): Config.InitialOptions => {
const {
TEST_ROOT,
TEST_MATCH,
Expand Down Expand Up @@ -69,23 +70,23 @@ export const getJestConfig = () => {

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

const testMatch = (STORYBOOK_STORIES_PATTERN && STORYBOOK_STORIES_PATTERN.split(';')) || [];
const testMatch = STORYBOOK_STORIES_PATTERN?.split(';') ?? [];

let config = {
const config: Config.InitialOptions = {
rootDir: getProjectRoot(),
roots: TEST_ROOT ? [TEST_ROOT] : undefined,
reporters,
testMatch,
transform: {
'^.+\\.(story|stories)\\.[jt]sx?$': require.resolve(
TEST_RUNNER_PATH + '/playwright/transform'
`${TEST_RUNNER_PATH}/playwright/transform`
),
'^.+\\.[jt]sx?$': swcJestPath,
},
snapshotSerializers: [jestSerializerHtmlPath],
testEnvironmentOptions: {
'jest-playwright': {
browsers: TEST_BROWSERS.split(',')
browsers: TEST_BROWSERS?.split(',')
.map((p) => p.trim().toLowerCase())
.filter(Boolean),
collectCoverage: STORYBOOK_COLLECT_COVERAGE === 'true',
Expand Down
Loading
Loading