Skip to content

Commit

Permalink
Merge branch 'next' into post-visit-on-failures
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf authored Nov 21, 2024
2 parents 7268a7d + 3a2a920 commit 3f8071b
Show file tree
Hide file tree
Showing 18 changed files with 5,058 additions and 8,168 deletions.
874 changes: 0 additions & 874 deletions .yarn/releases/yarn-3.6.3.cjs

This file was deleted.

934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.5.1.cjs

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
enableTelemetry: 0
compressionLevel: mixed

enableGlobalCache: false

enableTelemetry: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.6.3.cjs
yarnPath: .yarn/releases/yarn-4.5.1.cjs
66 changes: 66 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,69 @@
# v0.19.1 (Mon Jul 15 2024)

#### 🐛 Bug Fix

- Release 0.19.1 [#493](https://github.com/storybookjs/test-runner/pull/493) ([@paulgv](https://github.com/paulgv) [@yannbf](https://github.com/yannbf))
- fix(deps): upgrade `@storybook/csf` to v0.1.11 [#491](https://github.com/storybookjs/test-runner/pull/491) ([@paulgv](https://github.com/paulgv))

#### Authors: 2

- Paul Gascou-Vaillancourt ([@paulgv](https://github.com/paulgv))
- Yann Braga ([@yannbf](https://github.com/yannbf))

---

# v0.19.0 (Sat Jun 22 2024)

#### 🚀 Enhancement

- Release 0.19.0 [#486](https://github.com/storybookjs/test-runner/pull/486) ([@yannbf](https://github.com/yannbf) [email protected] [@ysgk](https://github.com/ysgk))
- Feat: Add errorMessageFormatter [#468](https://github.com/storybookjs/test-runner/pull/468) ([@yannbf](https://github.com/yannbf) [email protected])

#### 🐛 Bug Fix

- Fix: Combine tags correctly when transforming story files [#485](https://github.com/storybookjs/test-runner/pull/485) ([@yannbf](https://github.com/yannbf))
- Fix contents of eject functionality [#483](https://github.com/storybookjs/test-runner/pull/483) ([@yannbf](https://github.com/yannbf))
- Unpin @swc/core from 1.5.7 [#481](https://github.com/storybookjs/test-runner/pull/481) ([@ysgk](https://github.com/ysgk))

#### Authors: 3

- [@ysgk](https://github.com/ysgk)
- Foxhoundn ([@Foxhoundn](https://github.com/Foxhoundn))
- Yann Braga ([@yannbf](https://github.com/yannbf))

---

# v0.18.2 (Wed May 29 2024)

#### 🐛 Bug Fix

- Release 0.18.2 [#476](https://github.com/storybookjs/test-runner/pull/476) ([@shilman](https://github.com/shilman) [@valentinpalkovic](https://github.com/valentinpalkovic) [@yannbf](https://github.com/yannbf))
- Fix 8.1.4+ support for v5 index.json [#475](https://github.com/storybookjs/test-runner/pull/475) ([@shilman](https://github.com/shilman) [@yannbf](https://github.com/yannbf))
- Pin `@swc/core` to 1.5.7 [#474](https://github.com/storybookjs/test-runner/pull/474) ([@shilman](https://github.com/shilman))

#### Authors: 3

- Michael Shilman ([@shilman](https://github.com/shilman))
- Valentin Palkovic ([@valentinpalkovic](https://github.com/valentinpalkovic))
- Yann Braga ([@yannbf](https://github.com/yannbf))

---

# v0.18.1 (Fri May 17 2024)

#### 🐛 Bug Fix

- Release 0.18.1 [#466](https://github.com/storybookjs/test-runner/pull/466) ([@yannbf](https://github.com/yannbf))
- Fix Windows support in coverage generation [#461](https://github.com/storybookjs/test-runner/pull/461) ([@yannbf](https://github.com/yannbf))
- Fix getStoryContext type [#462](https://github.com/storybookjs/test-runner/pull/462) ([@yannbf](https://github.com/yannbf))
- Fix: Skip requiring a main.js file in index.json mode [#464](https://github.com/storybookjs/test-runner/pull/464) ([@yannbf](https://github.com/yannbf))

#### Authors: 1

- Yann Braga ([@yannbf](https://github.com/yannbf))

---

# v0.18.0 (Thu May 09 2024)

#### 🚀 Enhancement
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Storybook test runner turns all of your stories into executable tests.
- [getHttpHeaders](#gethttpheaders)
- [tags (experimental)](#tags-experimental)
- [logLevel](#loglevel)
- [errorMessageFormatter](#errormessageformatter)
- [Utility functions](#utility-functions)
- [getStoryContext](#getstorycontext)
- [waitForPageReady](#waitforpageready)
Expand Down Expand Up @@ -92,7 +93,8 @@ Use the following table to use the correct version of this package, based on the

| Test runner version | Storybook version |
| ------------------- | ----------------- |
| ^0.17.0 | ^8.0.0 |
| ^0.19.0 | ^8.2.0 |
| ~0.17.0 | ^8.0.0 |
| ~0.16.0 | ^7.0.0 |
| ~0.9.4 | ^6.4.0 |

Expand Down Expand Up @@ -220,28 +222,35 @@ module.exports = {

## Filtering tests (experimental)

You might want to skip certain stories in the test-runner, run tests only against a subset of stories, or exclude certain stories entirely from your tests. This is possible via the `tags` annotation. By default, the test-runner includes every story with the `"test"` tag. This tag is included by default in Storybook 8 for all stories, unless the user tells otherwise via [tag negation](https://storybook.js.org/docs/writing-stories/tags#removing-tags).
You might want to skip certain stories in the test-runner, run tests only against a subset of stories, or exclude certain stories entirely from your tests. This is possible via the `tags` annotation. By default, the test-runner includes every story with the `'test'` tag. This tag is included by default in Storybook 8 for all stories, unless the user tells otherwise via [tag negation](https://storybook.js.org/docs/writing-stories/tags#removing-tags).

This annotation can be part of a story, therefore only applying to it, or the component meta (the default export), which applies to all stories in the file:
This annotation can be part of a story, therefore only applying to that story, or the component meta (the default export), which applies to all stories in the file:

```ts
const meta = {
component: Button,
tags: ['design', 'test-only'],
tags: ['atom'],
};
export default meta;

// will inherit tags from meta with value ['design', 'test-only']
// will inherit tags from project and meta to be ['dev', 'test', 'atom']
export const Primary = {};

export const Secondary = {
// will override tags to be just ['skip']
tags: ['skip'],
// will combine with project and meta tags to be ['dev', 'test', 'atom', 'design']
tags: ['design'],
};

export const Tertiary = {
// will combine with project and meta tags to be ['dev', 'atom']
tags: ['!test'],
};
```

> **Note**
> You can't import constants from another file and use them to define tags in your stories. The tags in your stories or meta **have to be** defined inline, as an array of strings. This is a limitation due to Storybook's static analysis.
> You can't import constants from another file and use them to define tags in your stories. The tags in your stories or meta **must be** defined inline, as an array of strings. This is a restriction due to Storybook's static analysis.
For more information on how tags combine (and can be selectively removed), please see the [official docs](https://storybook.js.org/docs/writing-stories/tags).

Once your stories have your own custom tags, you can filter them via the [tags property](#tags-experimental) in your test-runner configuration file. You can also use the CLI flags `--includeTags`, `--excludeTags` or `--skipTags` for the same purpose. The CLI flags will take precedence over the tags in the test-runner config, therefore overriding them.

Expand Down Expand Up @@ -699,7 +708,7 @@ import type { TestRunnerConfig } from '@storybook/test-runner';

const config: TestRunnerConfig = {
tags: {
include: [], // string array, e.g. ['test-only']
include: [], // string array, e.g. ['test', 'design'] - by default, the value will be ['test']
exclude: [], // string array, e.g. ['design', 'docs-only']
skip: [], // string array, e.g. ['design']
},
Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/test-runner",
"version": "0.18.0",
"version": "0.19.1",
"description": "Test runner for Storybook stories",
"keywords": [
"storybook-addons",
Expand Down Expand Up @@ -56,10 +56,7 @@
"@babel/template": "^7.22.5",
"@babel/types": "^7.22.5",
"@jest/types": "^29.6.3",
"@storybook/core-common": "next",
"@storybook/csf": "^0.1.11",
"@storybook/csf-tools": "next",
"@storybook/preview-api": "next",
"@swc/core": "^1.5.22",
"@swc/jest": "^0.2.23",
"expect-playwright": "^0.8.0",
Expand All @@ -81,11 +78,11 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@storybook/addon-coverage": "^1.0.0",
"@storybook/addon-essentials": "next",
"@storybook/addon-interactions": "next",
"@storybook/react": "next",
"@storybook/react-vite": "next",
"@storybook/test": "next",
"@storybook/addon-essentials": "^8.0.0",
"@storybook/addon-interactions": "^8.0.0",
"@storybook/react": "^8.0.0",
"@storybook/react-vite": "^8.0.0",
"@storybook/test": "^8.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^16.4.1",
"@types/node-fetch": "^2.6.11",
Expand All @@ -107,7 +104,7 @@
"react": "^17.0.1",
"react-dom": "^17.0.1",
"read-pkg-up": "^7.0.1",
"storybook": "next",
"storybook": "^8.0.0",
"tempy": "^1.0.1",
"ts-dedent": "^2.0.0",
"ts-jest": "^29.0.0",
Expand All @@ -116,6 +113,9 @@
"vite": "^4.4.5",
"wait-on": "^7.2.0"
},
"peerDependencies": {
"storybook": "^8.2.0 || ^8.3.0-0 || ^8.4.0-0 || ^8.5.0-0 || ^8.6.0-0"
},
"engines": {
"node": "^16.10.0 || ^18.0.0 || >=20.0.0"
},
Expand All @@ -139,5 +139,6 @@
"react-native"
],
"icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png"
}
},
"packageManager": "[email protected]"
}
2 changes: 1 addition & 1 deletion src/config/jest-playwright.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { getProjectRoot } from '@storybook/core-common';
import { getProjectRoot } from 'storybook/internal/common';
import type { Config } from '@jest/types';

const getTestRunnerPath = () => process.env.STORYBOOK_TEST_RUNNER_PATH ?? '@storybook/test-runner';
Expand Down
5 changes: 3 additions & 2 deletions src/csf/transformCsf.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-underscore-dangle */
import { loadCsf } from '@storybook/csf-tools';
import { toId, storyNameFromExport, combineTags } from '@storybook/csf';
import { loadCsf } from 'storybook/internal/csf-tools';
import * as t from '@babel/types';
import generate from '@babel/generator';
import { toId, storyNameFromExport, combineTags } from '@storybook/csf';
import dedent from 'ts-dedent';

import { getTagOptions } from '../util/getTagOptions';
Expand Down Expand Up @@ -124,6 +124,7 @@ export const transformCsf = (
const annotations = csf._storyAnnotations[key];
acc[key] = {};
if (annotations?.play) {
// @ts-expect-error type mismatch – check later
acc[key].play = annotations.play;
}

Expand Down
4 changes: 2 additions & 2 deletions src/playwright/transformPlaywright.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as storybookMain from '../util/getStorybookMain';

import { transformPlaywright } from './transformPlaywright';

jest.mock('@storybook/core-common', () => ({
...jest.requireActual('@storybook/core-common'),
jest.mock('storybook/internal/common', () => ({
...jest.requireActual('storybook/internal/common'),
getProjectRoot: jest.fn(() => '/foo/bar'),
normalizeStories: jest.fn(() => [
{
Expand Down
4 changes: 2 additions & 2 deletions src/playwright/transformPlaywright.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { relative } from 'path';
import template from '@babel/template';
import { userOrAutoTitle } from '@storybook/preview-api';
import { userOrAutoTitle } from 'storybook/internal/preview-api';
import dedent from 'ts-dedent';

import { getStorybookMetadata } from '../util';
import { transformCsf } from '../csf/transformCsf';
import type { TestPrefixer } from '../csf/transformCsf';
import dedent from 'ts-dedent';

const coverageErrorMessage = dedent`
[Test runner] An error occurred when evaluating code coverage:
Expand Down
7 changes: 3 additions & 4 deletions src/test-storybook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import canBindToHost from 'can-bind-to-host';
import dedent from 'ts-dedent';
import path, { join, resolve } from 'path';
import tempy from 'tempy';
import { getInterpretedFile } from 'storybook/internal/common';
import { readConfig } from 'storybook/internal/csf-tools';
import { glob } from 'glob';

import { JestOptions, getCliOptions } from './util/getCliOptions';
import { getStorybookMetadata } from './util/getStorybookMetadata';
import { getTestRunnerConfig } from './util/getTestRunnerConfig';
import { transformPlaywrightJson } from './playwright/transformPlaywrightJson';

import { glob } from 'glob';
import { TestRunnerConfig } from './playwright/hooks';
import { getInterpretedFile } from '@storybook/core-common';
import { readConfig } from '@storybook/csf-tools';

// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'test';
Expand Down
4 changes: 2 additions & 2 deletions src/util/getStorybookMain.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getStorybookMain, resetStorybookMainCache, storybookMainConfig } from './getStorybookMain';
import * as coreCommon from '@storybook/core-common';
import * as coreCommon from 'storybook/internal/common';

jest.mock('@storybook/core-common');
jest.mock('storybook/internal/common');

describe('getStorybookMain', () => {
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/util/getStorybookMain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join, resolve } from 'path';
import { serverRequire } from '@storybook/core-common';
import type { StorybookConfig } from '@storybook/types';
import { serverRequire } from 'storybook/internal/common';
import type { StorybookConfig } from 'storybook/internal/types';
import dedent from 'ts-dedent';

export const storybookMainConfig = new Map<string, StorybookConfig>();
Expand Down
8 changes: 4 additions & 4 deletions src/util/getStorybookMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { StorybookConfig } from '@storybook/types';
import * as storybookMain from './getStorybookMain';
import { StorybookConfig } from 'storybook/internal/types';

import * as storybookMain from './getStorybookMain';
import { getStorybookMetadata } from './getStorybookMetadata';

jest.mock('@storybook/core-common', () => ({
...jest.requireActual('@storybook/core-common'),
jest.mock('storybook/internal/common', () => ({
...jest.requireActual('storybook/internal/common'),
getProjectRoot: jest.fn(() => '/foo/bar'),
normalizeStories: jest.fn(() => [
{
Expand Down
7 changes: 4 additions & 3 deletions src/util/getStorybookMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { join } from 'path';
import { normalizeStories, getProjectRoot } from '@storybook/core-common';
import { normalizeStories, getProjectRoot } from 'storybook/internal/common';
import { StoriesEntry } from 'storybook/internal/types';

import { getStorybookMain } from './getStorybookMain';
import { StoriesEntry } from '@storybook/types';

export const getStorybookMetadata = () => {
const workingDir = getProjectRoot();
Expand All @@ -21,7 +22,7 @@ export const getStorybookMetadata = () => {
.map((dir) => join(workingDir, dir))
.join(';');

// @ts-ignore -- this is added in @storybook/core-[email protected], which we don't depend on
// @ts-expect-error -- this is added in storybook/internal/[email protected], which we don't depend on
const lazyCompilation = !!main.core?.builder?.options?.lazyCompilation;

return {
Expand Down
8 changes: 4 additions & 4 deletions src/util/getTestRunnerConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const testRunnerConfig: TestRunnerConfig = {
},
};

jest.mock('@storybook/core-common', () => ({
jest.mock('storybook/internal/common', () => ({
serverRequire: jest.fn(),
}));

Expand All @@ -37,21 +37,21 @@ describe('getTestRunnerConfig', () => {

it('should load the test runner config', () => {
const configDir = '.storybook';
(require('@storybook/core-common').serverRequire as jest.Mock).mockReturnValueOnce(
(require('storybook/internal/common').serverRequire as jest.Mock).mockReturnValueOnce(
testRunnerConfig
);

const result = getTestRunnerConfig(configDir);

expect(result).toEqual(testRunnerConfig);
expect(require('@storybook/core-common').serverRequire).toHaveBeenCalledWith(
expect(require('storybook/internal/common').serverRequire).toHaveBeenCalledWith(
join(resolve('.storybook', 'test-runner'))
);
});

it('should cache the test runner config', () => {
const configDir = '.storybook';
(require('@storybook/core-common').serverRequire as jest.Mock).mockReturnValueOnce(
(require('storybook/internal/common').serverRequire as jest.Mock).mockReturnValueOnce(
testRunnerConfig
);

Expand Down
2 changes: 1 addition & 1 deletion src/util/getTestRunnerConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join, resolve } from 'path';
import { serverRequire } from '@storybook/core-common';
import { serverRequire } from 'storybook/internal/common';
import { TestRunnerConfig } from '../playwright/hooks';

let testRunnerConfig: TestRunnerConfig;
Expand Down
Loading

0 comments on commit 3f8071b

Please sign in to comment.