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.19.0 #486

Merged
merged 22 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
85dee13
fix getStoryContext type
yannbf May 16, 2024
4f056b4
add errorMessageFormatter config
yannbf May 16, 2024
ab7d2c2
add test
yannbf May 16, 2024
1079c22
Format the full error message before passing it to the Error class
May 21, 2024
791bdd8
Unpin @swc/core from 1.5.7
ysgk Jun 10, 2024
7316142
Merge pull request #481 from ysgk/unpin-swc-core
yannbf Jun 13, 2024
3c11018
fix contents of eject functionality
yannbf Jun 13, 2024
fa76d30
Merge pull request #483 from storybookjs/yann/fix-eject
yannbf Jun 13, 2024
3f1a718
Merge branch 'next' into yann/error-log-formatter
yannbf Jun 13, 2024
1939323
Fix: Combine tags correctly when transforming story files
yannbf Jun 21, 2024
2559864
merge tags from preview annotations with meta and story tags
yannbf Jun 21, 2024
5da6582
include "test" as default filter
yannbf Jun 21, 2024
a54e616
fix tags precedence
yannbf Jun 21, 2024
1076614
Merge pull request #485 from storybookjs/yann/fix-tags-filtering
yannbf Jun 21, 2024
f9cf364
Merge branch 'next' into yann/error-log-formatter
yannbf Jun 21, 2024
c3d4641
remove unnecessary resolution
yannbf Jun 21, 2024
1f25446
apply error formatting to all error events
yannbf Jun 22, 2024
d12895b
fix type
yannbf Jun 22, 2024
897ddba
document errorMessageFormatter
yannbf Jun 22, 2024
969e5dc
Merge pull request #468 from Foxhoundn/yann/error-log-formatter
yannbf Jun 22, 2024
7d26a7f
Merge branch 'main' into release/0.19.0
yannbf Jun 22, 2024
c86b694
Merge branch 'main' into release/0.19.0
yannbf Jun 22, 2024
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
8 changes: 7 additions & 1 deletion .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Preview } from '@storybook/react';
import { isTestRunner } from './is-test-runner';

const withSkippableTests = (StoryFn, { parameters }) => {
Expand All @@ -8,4 +9,9 @@ const withSkippableTests = (StoryFn, { parameters }) => {
return StoryFn();
};

export const decorators = [withSkippableTests];
const preview: Preview = {
tags: ['global-tag'],
decorators: [withSkippableTests],
};

export default preview;
3 changes: 3 additions & 0 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

const config: TestRunnerConfig = {
logLevel: 'verbose',
errorMessageFormatter: (message) => {
return message;

Check warning on line 12 in .storybook/test-runner.ts

View check run for this annotation

Codecov / codecov/patch

.storybook/test-runner.ts#L11-L12

Added lines #L11 - L12 were not covered by tests
},
tags: {
exclude: ['exclude'],
include: [],
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ 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.
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:

Expand Down Expand Up @@ -729,6 +729,23 @@ const config: TestRunnerConfig = {
export default config;
```

#### errorMessageFormatter

The `errorMessageFormatter` property defines a function that will pre-format the error messages before they get reported in the CLI:

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

const config: TestRunnerConfig = {
errorMessageFormatter: (message) => {
// manipulate the error message as you like
return message;
},
};
export default config;
```

### Utility functions

For more specific use cases, the test runner provides utility functions that could be useful to you.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@storybook/csf": "^0.1.2",
"@storybook/csf-tools": "^8.0.0",
"@storybook/preview-api": "^8.0.0",
"@swc/core": "1.5.7",
"@swc/core": "^1.5.22",
"@swc/jest": "^0.2.23",
"expect-playwright": "^0.8.0",
"jest": "^29.6.4",
Expand Down
14 changes: 11 additions & 3 deletions src/csf/transformCsf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { loadCsf } from '@storybook/csf-tools';
import * as t from '@babel/types';
import generate from '@babel/generator';
import { toId, storyNameFromExport } from '@storybook/csf';
import { toId, storyNameFromExport, combineTags } from '@storybook/csf';
import dedent from 'ts-dedent';

import { getTagOptions } from '../util/getTagOptions';
Expand Down Expand Up @@ -108,7 +108,8 @@ export const transformCsf = (
beforeEachPrefixer,
insertTestIfEmpty,
makeTitle,
}: TransformOptions
previewAnnotations = { tags: [] },
}: TransformOptions & { previewAnnotations?: Record<string, any> }
) => {
const { includeTags, excludeTags, skipTags } = getTagOptions();

Expand All @@ -126,7 +127,14 @@ export const transformCsf = (
acc[key].play = annotations.play;
}

acc[key].tags = csf._stories[key].tags || csf.meta?.tags || [];
acc[key].tags = combineTags(
'test',
'dev',
...previewAnnotations.tags,
...(csf.meta?.tags || []),
...(csf._stories[key].tags || [])
);

return acc;
},
{}
Expand Down
5 changes: 5 additions & 0 deletions src/playwright/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export interface TestRunnerConfig {
* @default 'info'
*/
logLevel?: 'info' | 'warn' | 'error' | 'verbose' | 'none';

/**
* Defines a custom function to process the error message. Useful to sanitize error messages or to add additional information.
*/
errorMessageFormatter?: (error: string) => string;
}

export const setPreVisit = (preVisit: TestHook) => {
Expand Down
Loading
Loading