Skip to content

Commit 616f6f2

Browse files
committed
chore: switch to new storybook testing addon
1 parent cc718fc commit 616f6f2

File tree

8 files changed

+693
-208
lines changed

8 files changed

+693
-208
lines changed

packages/ui/.storybook/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ const config: StorybookConfig = {
3030
addons: [
3131
getAbsolutePath('@storybook/addon-links'),
3232
getAbsolutePath('@storybook/addon-essentials'),
33-
getAbsolutePath('@storybook/addon-interactions'),
3433
getAbsolutePath('@storybook/addon-coverage'),
35-
// getAbsolutePath('@storybook/addon-a11y'),
34+
getAbsolutePath('@storybook/addon-a11y'),
3635
getAbsolutePath('@storybook/addon-mdx-gfm'),
36+
getAbsolutePath('@storybook/experimental-addon-test'),
3737
],
3838
framework: {
3939
name: getAbsolutePath('@storybook/react-vite'),

packages/ui/.storybook/preview.tsx

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ declare global {
3939
}
4040
}
4141

42-
const SWRCacheDecorator: Decorator = (Story) => {
42+
const SWRCacheDecorator: Decorator = (Story, context) => {
4343
const { cache } = useSWRConfig();
4444
for (const key of cache.keys()) {
4545
cache.delete(key);
@@ -52,10 +52,7 @@ const SWRCacheDecorator: Decorator = (Story) => {
5252
// eslint-disable-next-line react-hooks/rules-of-hooks
5353
return useSWR(
5454
// Make sure SWR caches are unique per story.
55-
[
56-
...(key instanceof Array ? key : [key]),
57-
window.__STORYBOOK_PREVIEW__.currentRender.id,
58-
],
55+
[...(key instanceof Array ? key : [key]), context.id],
5956
fetcher,
6057
config,
6158
);
@@ -70,59 +67,6 @@ const SWRCacheDecorator: Decorator = (Story) => {
7067

7168
export const parameters = {
7269
chromatic: { viewports: [320, 840, 1440] },
73-
a11y: {
74-
// Optional selector to inspect
75-
element: '#storybook-root',
76-
config: {
77-
rules: [
78-
{
79-
// The autocomplete rule will not run based on the CSS selector provided
80-
id: 'autocomplete-valid',
81-
selector: '*:not([autocomplete="nope"])',
82-
},
83-
{
84-
// Setting the enabled option to false will disable checks for this particular rule on all stories.
85-
id: 'image-alt',
86-
enabled: false,
87-
},
88-
{
89-
// Setting the enabled option to false will disable checks for this particular rule on all stories.
90-
id: 'color-contrast',
91-
reviewOnFail: true,
92-
},
93-
{
94-
id: 'link-name',
95-
reviewOnFail: true,
96-
},
97-
{
98-
id: 'duplicate-id',
99-
reviewOnFail: true,
100-
},
101-
{
102-
id: 'landmark-no-duplicate-main',
103-
reviewOnFail: true,
104-
},
105-
{
106-
id: 'landmark-main-is-top-level',
107-
reviewOnFail: true,
108-
},
109-
{
110-
id: 'landmark-unique',
111-
reviewOnFail: true,
112-
},
113-
{
114-
id: 'button-name',
115-
reviewOnFail: true,
116-
},
117-
{
118-
id: 'list',
119-
reviewOnFail: true,
120-
},
121-
],
122-
},
123-
// Axe's options parameter
124-
options: {},
125-
},
12670
};
12771

12872
export const decorators = [

packages/ui/.storybook/test-runner.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { setProjectAnnotations } from '@storybook/react';
2+
import { beforeAll } from 'vitest';
3+
4+
import * as projectAnnotations from './preview';
5+
6+
// This is an important step to apply the right configuration when testing your stories.
7+
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
8+
const project = setProjectAnnotations([projectAnnotations]);
9+
10+
beforeAll(project.beforeAll);

packages/ui/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
}
2323
},
2424
"scripts": {
25+
"playwright-install": "",
2526
"prep:types": "tsc --emitDeclarationOnly",
2627
"prep:scripts": "swc ./src -d ./build",
2728
"prep:fonts": "mkdir -p build && node preloaded-fonts.js",
@@ -33,9 +34,8 @@
3334
"dev": "storybook dev -p 6006 --no-open",
3435
"start": "serve storybook-static -p 6006 > /dev/null 2>&1",
3536
"test:static": "tsc --noEmit && eslint . --quiet",
36-
"test:unit": "vitest run --passWithNoTests",
37-
"test:storybook": "test-storybook --coverage",
38-
"test:integration": "start-test start http://localhost:6006 test:storybook && pnpm report",
37+
"test:unit": "vitest run --project=unit --passWithNoTests",
38+
"test:integration": "playwright install chromium && vitest run --project=storybook --passWithNoTests",
3939
"report": "mkdir -p coverage/storybook && nyc report --reporter=lcov -t coverage/storybook --report-dir coverage/storybook"
4040
},
4141
"dependencies": {
@@ -72,10 +72,10 @@
7272
"@storybook/addon-actions": "^8.5.2",
7373
"@storybook/addon-coverage": "^1.0.5",
7474
"@storybook/addon-essentials": "^8.5.2",
75-
"@storybook/addon-interactions": "^8.5.2",
7675
"@storybook/addon-links": "^8.5.2",
7776
"@storybook/addon-mdx-gfm": "^8.5.2",
7877
"@storybook/blocks": "^8.5.2",
78+
"@storybook/experimental-addon-test": "^8.5.2",
7979
"@storybook/react": "^8.5.2",
8080
"@storybook/react-vite": "^8.5.2",
8181
"@storybook/test": "^8.5.2",
@@ -92,11 +92,13 @@
9292
"@types/react-body-classname": "^1.1.10",
9393
"@types/react-dom": "^18.2.18",
9494
"@vitejs/plugin-react-swc": "^3.5.0",
95+
"@vitest/browser": "3.0.4",
96+
"@vitest/coverage-v8": "3.0.4",
9597
"autoprefixer": "^10.4.16",
96-
"axe-playwright": "^2.0.1",
9798
"cssnano": "^6.0.3",
9899
"happy-dom": "^12.10.3",
99100
"nyc": "^15.1.0",
101+
"playwright": "^1.50.0",
100102
"postcss": "^8.4.32",
101103
"postcss-cli": "^11.0.0",
102104
"postcss-import": "^16.0.0",
@@ -111,6 +113,6 @@
111113
"typescript": "^5.3.3",
112114
"vite": "^5.0.10",
113115
"vite-imagetools": "^6.2.9",
114-
"vitest": "^1.1.1"
116+
"vitest": "^3.0.4"
115117
}
116118
}

packages/ui/vitest.config.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
4+
import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin';
5+
import { defineConfig } from 'vitest/config';
6+
7+
const dirname =
8+
typeof __dirname !== 'undefined'
9+
? __dirname
10+
: path.dirname(fileURLToPath(import.meta.url));
11+
12+
// More info at: https://storybook.js.org/docs/writing-tests/test-addon
13+
export default defineConfig({
14+
test: {
15+
workspace: [
16+
{
17+
test: {
18+
name: 'unit',
19+
},
20+
},
21+
{
22+
plugins: [
23+
// The plugin will run tests for the stories defined in your Storybook config
24+
// See options at: https://storybook.js.org/docs/writing-tests/test-addon#storybooktest
25+
storybookTest({ configDir: path.join(dirname, '.storybook') }),
26+
],
27+
test: {
28+
name: 'storybook',
29+
browser: {
30+
enabled: true,
31+
headless: true,
32+
provider: 'playwright',
33+
instances: [
34+
{
35+
browser: 'chromium',
36+
},
37+
],
38+
},
39+
setupFiles: ['.storybook/vitest.setup.ts'],
40+
},
41+
},
42+
],
43+
},
44+
});

packages/ui/vitest.shims.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@vitest/browser/providers/playwright" />

0 commit comments

Comments
 (0)