Skip to content

Commit 344866f

Browse files
committed
test: Alert component [update-screenshots]
1 parent 49e8c16 commit 344866f

File tree

13 files changed

+264
-34
lines changed

13 files changed

+264
-34
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI/CD Pipeline
22

33
on:
44
push:
5-
branches: [main, 'feature/*']
5+
branches: [main, 'feature/*', 'tests/*']
66
pull_request:
77
branches: [main]
88

@@ -233,17 +233,21 @@ jobs:
233233

234234
- name: Serve Storybook & Run E2E tests
235235
run: |
236+
# Set up directory structure for serving with /design-system/ base path
237+
mkdir -p storybook-serve/design-system
238+
cp -r packages/design-system/storybook-static/* storybook-serve/design-system/
239+
236240
# Start HTTP server for Storybook
237-
npx http-server packages/design-system/storybook-static -p 6006 &
241+
npx http-server storybook-serve -p 6006 &
238242
239243
# Wait for server to be ready
240-
timeout 30 bash -c 'until curl -f http://localhost:6006/iframe.html; do sleep 1; done'
244+
timeout 30 bash -c 'until curl -f http://localhost:6006/design-system/iframe.html; do sleep 1; done'
241245
242246
# Run E2E tests
243247
pnpm --filter=@wallarm/design-system exec playwright test --shard=${{ matrix.shard }}/3 --project=chromium
244248
env:
245249
CI: true
246-
STORYBOOK_URL: http://localhost:6006
250+
STORYBOOK_URL: http://localhost:6006/design-system
247251

248252
- name: Upload test results
249253
uses: actions/upload-artifact@v4
@@ -308,11 +312,15 @@ jobs:
308312

309313
- name: Update screenshots
310314
run: |
315+
# Set up directory structure for serving with /design-system/ base path
316+
mkdir -p storybook-serve/design-system
317+
cp -r packages/design-system/storybook-static/* storybook-serve/design-system/
318+
311319
# Start HTTP server for Storybook
312-
npx http-server packages/design-system/storybook-static -p 6006 &
320+
npx http-server storybook-serve -p 6006 &
313321
314322
# Wait for server to be ready
315-
timeout 30 bash -c 'until curl -f http://localhost:6006/iframe.html; do sleep 1; done'
323+
timeout 30 bash -c 'until curl -f http://localhost:6006/design-system/iframe.html; do sleep 1; done'
316324
317325
# Update screenshots
318326
pnpm --filter=@wallarm/design-system exec playwright test \
@@ -321,7 +329,7 @@ jobs:
321329
--update-snapshots
322330
env:
323331
CI: false
324-
STORYBOOK_URL: http://localhost:6006
332+
STORYBOOK_URL: http://localhost:6006/design-system
325333

326334
- name: Upload updated screenshots
327335
uses: actions/upload-artifact@v4

apps/playground/src/routeTree.gen.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,52 @@
88
// You should NOT make any changes in this file as it will be overwritten.
99
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
1010

11-
import { Route as rootRouteImport } from './routes/__root';
12-
import { Route as IndexRouteImport } from './routes/index';
11+
import { Route as rootRouteImport } from './routes/__root'
12+
import { Route as IndexRouteImport } from './routes/index'
1313

1414
const IndexRoute = IndexRouteImport.update({
1515
id: '/',
1616
path: '/',
1717
getParentRoute: () => rootRouteImport,
18-
} as any);
18+
} as any)
1919

2020
export interface FileRoutesByFullPath {
21-
'/': typeof IndexRoute;
21+
'/': typeof IndexRoute
2222
}
2323
export interface FileRoutesByTo {
24-
'/': typeof IndexRoute;
24+
'/': typeof IndexRoute
2525
}
2626
export interface FileRoutesById {
27-
__root__: typeof rootRouteImport;
28-
'/': typeof IndexRoute;
27+
__root__: typeof rootRouteImport
28+
'/': typeof IndexRoute
2929
}
3030
export interface FileRouteTypes {
31-
fileRoutesByFullPath: FileRoutesByFullPath;
32-
fullPaths: '/';
33-
fileRoutesByTo: FileRoutesByTo;
34-
to: '/';
35-
id: '__root__' | '/';
36-
fileRoutesById: FileRoutesById;
31+
fileRoutesByFullPath: FileRoutesByFullPath
32+
fullPaths: '/'
33+
fileRoutesByTo: FileRoutesByTo
34+
to: '/'
35+
id: '__root__' | '/'
36+
fileRoutesById: FileRoutesById
3737
}
3838
export interface RootRouteChildren {
39-
IndexRoute: typeof IndexRoute;
39+
IndexRoute: typeof IndexRoute
4040
}
4141

4242
declare module '@tanstack/react-router' {
4343
interface FileRoutesByPath {
4444
'/': {
45-
id: '/';
46-
path: '/';
47-
fullPath: '/';
48-
preLoaderRoute: typeof IndexRouteImport;
49-
parentRoute: typeof rootRouteImport;
50-
};
45+
id: '/'
46+
path: '/'
47+
fullPath: '/'
48+
preLoaderRoute: typeof IndexRouteImport
49+
parentRoute: typeof rootRouteImport
50+
}
5151
}
5252
}
5353

5454
const rootRouteChildren: RootRouteChildren = {
5555
IndexRoute: IndexRoute,
56-
};
56+
}
5757
export const routeTree = rootRouteImport
5858
._addFileChildren(rootRouteChildren)
59-
._addFileTypes<FileRouteTypes>();
59+
._addFileTypes<FileRouteTypes>()

packages/configs/playwright-config/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"exports": {
1111
"./base": "./dist/base.js",
12-
"./docker": "./dist/docker.js"
12+
"./docker": "./dist/docker.js",
13+
"./storybook": "./dist/storybook.js"
1314
},
1415
"dependencies": {
1516
"@playwright/test": "catalog:"

packages/configs/playwright-config/src/base.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const baseConfig = defineConfig({
55
forbidOnly: !!process.env.CI,
66
retries: process.env.CI ? 2 : 0,
77
workers: process.env.CI ? 1 : undefined,
8+
timeout: 30000,
89
reporter: 'html',
910
use: {
1011
trace: 'on-first-retry',
@@ -32,6 +33,8 @@ export const baseConfig = defineConfig({
3233
},
3334
},
3435
],
36+
snapshotPathTemplate:
37+
'{testDir}/{testFileDir}/{testFileName}-snapshots/{testName}-{projectName}{ext}',
3538
expect: {
3639
toHaveScreenshot: { maxDiffPixelRatio: 0.2 },
3740
},
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import type { Page } from '@playwright/test';
2+
3+
function storyNameToId(name: string): string {
4+
return name.replace(/\s+/g, '-').toLowerCase();
5+
}
6+
7+
/**
8+
* @example
9+
* ```ts
10+
* const alertStory = createStoryHelper('messaging-alert', [
11+
* 'All Colors',
12+
* 'Title Only',
13+
* 'With Close Button',
14+
* ] as const);
15+
*
16+
* await alertStory.goto(page, 'All Colors'); // → iframe.html?id=messaging-alert--all-colors
17+
* ```
18+
*/
19+
export function createStoryHelper<const T extends readonly string[]>(
20+
componentId: string,
21+
storyNames: T,
22+
) {
23+
type StoryName = T[number];
24+
25+
if (storyNames.length === 0) {
26+
throw new Error(`createStoryHelper: storyNames cannot be empty`);
27+
}
28+
29+
return {
30+
url(storyName: StoryName): string {
31+
const storyId = storyNameToId(storyName);
32+
return `iframe.html?viewMode=story&id=${componentId}--${storyId}`;
33+
},
34+
35+
async goto(page: Page, storyName: StoryName): Promise<void> {
36+
const url = this.url(storyName);
37+
38+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
39+
40+
await page.waitForFunction(
41+
() => {
42+
const root = document.getElementById('storybook-root');
43+
return root && root.children.length > 0;
44+
},
45+
{ timeout: 30000 },
46+
);
47+
48+
await page.evaluate(() => document.fonts.ready);
49+
await page.waitForTimeout(300);
50+
},
51+
52+
get componentId(): string {
53+
return componentId;
54+
},
55+
56+
get stories(): readonly StoryName[] {
57+
return storyNames;
58+
},
59+
};
60+
}

packages/configs/playwright-config/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "@wallarm/typescript-config/nodejs.json",
33
"compilerOptions": {
4-
"outDir": "dist"
4+
"outDir": "dist",
5+
"lib": ["ES2023", "DOM"]
56
},
67
"include": ["src/**/*"],
78
"exclude": ["node_modules", "dist"]

packages/design-system/nginx.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ server {
3939
try_files $uri =404;
4040
}
4141

42+
# GitHub Pages base path support for E2E tests
43+
# Production build uses /design-system/ prefix for GitHub Pages deployment
44+
location /design-system/ {
45+
alias /usr/share/nginx/html/;
46+
}
47+
4248
# Main Storybook routes
4349
location / {
4450
try_files $uri $uri/ /index.html;

packages/design-system/playwright.config.docker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { defineConfig } from '@playwright/test';
22

33
import { dockerConfig } from '@wallarm/playwright-config/docker';
44

5+
const DEFAULT_DOCKER_URL = 'http://host.docker.internal:6006';
6+
const baseURL = process.env.STORYBOOK_URL || DEFAULT_DOCKER_URL;
7+
58
export default defineConfig({
69
...dockerConfig,
710
testDir: './src',
@@ -10,6 +13,6 @@ export default defineConfig({
1013
// UI-specific Docker configuration
1114
use: {
1215
...dockerConfig.use,
13-
baseURL: process.env.STORYBOOK_URL || 'http://host.docker.internal:6006',
16+
baseURL,
1417
},
1518
});

packages/design-system/playwright.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { defineConfig } from '@playwright/test';
22

33
import { baseConfig } from '@wallarm/playwright-config/base';
44

5+
const DEFAULT_URL = 'http://localhost:6006';
6+
const baseURL = process.env.STORYBOOK_URL || DEFAULT_URL;
7+
58
export default defineConfig({
69
...baseConfig,
710
testDir: './src',
811
testMatch: '**/*.e2e.ts',
912
use: {
1013
...baseConfig.use,
11-
baseURL: 'http://localhost:6006',
14+
baseURL,
1215
},
1316
});

0 commit comments

Comments
 (0)