Skip to content

Commit edd48eb

Browse files
committed
test: Add Storybook tests to CI
1 parent 158ab08 commit edd48eb

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

.github/workflows/webui.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ jobs:
3232
run: npm run check
3333
working-directory: tools/server/webui
3434

35+
- name: Install Playwright browsers
36+
run: npx playwright install --with-deps
37+
working-directory: tools/server/webui
38+
39+
- name: Build Storybook
40+
run: npm run build-storybook
41+
working-directory: tools/server/webui
42+
43+
- name: Run Storybook tests
44+
run: |
45+
npm run test:storybook
46+
working-directory: tools/server/webui
47+
3548
- name: Build application
3649
run: npm run build
3750
working-directory: tools/server/webui
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { setProjectAnnotations } from '@storybook/sveltekit';
2+
import * as previewAnnotations from './preview';
3+
import { beforeAll } from 'vitest';
4+
5+
const project = setProjectAnnotations([previewAnnotations]);
6+
7+
beforeAll(async () => {
8+
if (project.beforeAll) {
9+
await project.beforeAll();
10+
}
11+
});

tools/server/webui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"test:unit": "vitest",
1616
"test": "npm run test:unit -- --run && npm run test:e2e",
1717
"test:e2e": "playwright test",
18+
"test:storybook": "vitest --project=storybook",
1819
"storybook": "storybook dev -p 6006",
1920
"build-storybook": "storybook build"
2021
},

tools/server/webui/vite.config.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { readFileSync, writeFileSync, existsSync } from 'fs';
55
import { resolve } from 'path';
66
import { defineConfig } from 'vite';
77
import devtoolsJson from 'vite-plugin-devtools-json';
8+
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
89

910
const GUIDE_FOR_FRONTEND = `
1011
<!--
@@ -78,7 +79,12 @@ function llamaCppBuildPlugin() {
7879
}
7980

8081
export default defineConfig({
81-
plugins: [tailwindcss(), sveltekit(), devtoolsJson(), llamaCppBuildPlugin()],
82+
plugins: [
83+
tailwindcss(),
84+
sveltekit(),
85+
devtoolsJson(),
86+
llamaCppBuildPlugin(),
87+
],
8288
test: {
8389
projects: [
8490
{
@@ -104,6 +110,25 @@ export default defineConfig({
104110
include: ['src/**/*.{test,spec}.{js,ts}'],
105111
exclude: ['src/**/*.svelte.{test,spec}.{js,ts}']
106112
}
113+
},
114+
{
115+
extends: './vite.config.ts',
116+
test: {
117+
name: 'storybook',
118+
environment: 'browser',
119+
browser: {
120+
enabled: true,
121+
provider: 'playwright',
122+
instances: [{ browser: 'chromium', headless: true }]
123+
},
124+
include: ['src/**/*.stories.{js,ts,svelte}'],
125+
setupFiles: ['./.storybook/vitest.setup.ts']
126+
},
127+
plugins: [
128+
storybookTest({
129+
storybookScript: 'pnpm run storybook --no-open',
130+
}),
131+
]
107132
}
108133
]
109134
},

0 commit comments

Comments
 (0)