Skip to content

Commit 728e81f

Browse files
committed
test: add storybook builder tests
1 parent 859e1b2 commit 728e81f

File tree

13 files changed

+6346
-542
lines changed

13 files changed

+6346
-542
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Verify Storybook Builder
2+
3+
on: pull_request
4+
5+
jobs:
6+
verify-storybook-builder:
7+
timeout-minutes: 60
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Setup Node 20
13+
uses: actions/setup-node@v4
14+
env:
15+
FORCE_COLOR: 0
16+
with:
17+
node-version: 20
18+
cache: npm
19+
20+
- name: Install Dependencies
21+
run: npm ci
22+
23+
- name: Build packages
24+
run: npm run build
25+
26+
- name: Symlink built packages binaries (e.g. "wds")
27+
run: npm ci
28+
29+
- name: Install Playwright Browsers
30+
run: npx playwright install --with-deps
31+
32+
- name: Run tests
33+
run: npm run test:storybook-builder
34+
35+
- uses: actions/upload-artifact@v3
36+
if: always()
37+
with:
38+
name: playwright-report
39+
path: packages/storybook-framework-web-components/playwright-report/
40+
retention-days: 30

package-lock.json

+6,110-539
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
"search": "rocket search",
3232
"start": "rocket start",
3333
"start:build": "node packages/dev-server/dist/bin.js --root-dir _site --open",
34-
"test": "npm run test:node && npm run test:browser",
34+
"test": "npm run test:node && npm run test:browser && npm run test:storybook-builder",
3535
"test:browser": "npm run test:browser --workspaces --if-present",
3636
"test:node": "npm run test:node --workspaces --if-present",
37+
"test:storybook-builder": "npm test --prefix ./packages/storybook-framework-web-components",
3738
"types": "wireit",
3839
"update": "npm run update:mjs-dts-entrypoints && npm run update:tsconfigs",
3940
"update-dependency": "node scripts/update-dependency.js",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
test-results/
3+
playwright-report/
4+
storybook-build/

packages/storybook-framework-web-components/package.json

+14-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
"node": ">=16.0.0"
3232
},
3333
"scripts": {
34-
"build": "tsc"
34+
"build": "tsc",
35+
"test": "npm run test:build && npm run test:ui:build && npm run test:ui:runtime",
36+
"test:build": "storybook build -c ./tests/fixtures/all-in-one/.storybook -o ./tests/fixtures/all-in-one/storybook-build",
37+
"test:start:build": "wds -r ./tests/fixtures/all-in-one/storybook-build -p 3000",
38+
"test:start:runtime": "storybook dev -c ./tests/fixtures/all-in-one/.storybook -p 3000 --no-open",
39+
"test:ui:build": "npx playwright test -c playwright.build.config.ts",
40+
"test:ui:runtime": "npx playwright test -c playwright.runtime.config.ts"
3541
},
3642
"files": [
3743
"*.d.ts",
@@ -58,6 +64,12 @@
5864
"@web/storybook-builder": "^0.1.0"
5965
},
6066
"devDependencies": {
61-
"@storybook/types": "^7.0.0"
67+
"@playwright/test": "^1.22.2",
68+
"@storybook/addon-essentials": "^7.0.0",
69+
"@storybook/addon-interactions": "^7.0.0",
70+
"@storybook/addon-links": "^7.0.0",
71+
"@storybook/types": "^7.0.0",
72+
"@web/dev-server": "^0.4.0",
73+
"storybook": "^7.0.0"
6274
}
6375
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
/**
4+
* See https://playwright.dev/docs/test-configuration.
5+
*/
6+
export default defineConfig({
7+
testDir: './tests',
8+
/* Run tests in files in parallel */
9+
fullyParallel: true,
10+
/* Fail the build on CI if you accidentally left test.only in the source code. */
11+
forbidOnly: !!process.env.CI,
12+
/* Retry on CI only */
13+
retries: process.env.CI ? 2 : 0,
14+
/* Opt out of parallel tests on CI. */
15+
workers: process.env.CI ? 1 : undefined,
16+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
17+
reporter: 'html',
18+
19+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
20+
use: {
21+
baseURL: 'http://127.0.0.1:3000',
22+
23+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
24+
trace: 'on-first-retry',
25+
},
26+
27+
/* Run your local dev server before starting the tests */
28+
webServer: {
29+
command: '',
30+
url: 'http://127.0.0.1:3000',
31+
reuseExistingServer: !process.env.CI,
32+
},
33+
34+
/* Configure projects for major browsers */
35+
projects: [
36+
{
37+
name: 'chromium',
38+
use: { ...devices['Desktop Chrome'] },
39+
},
40+
],
41+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import baseConfig from './playwright.base.config.ts';
2+
3+
// @ts-ignore
4+
baseConfig.webServer.command = 'npm run test:start:build';
5+
6+
export default baseConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import baseConfig from './playwright.base.config.ts';
2+
3+
// @ts-ignore
4+
baseConfig.webServer.command = 'npm run test:start:runtime';
5+
6+
export default baseConfig;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { expect, test } from '@playwright/test';
2+
import { Manager } from './manager.js';
3+
import { Preview } from './preview.js';
4+
5+
/** @type import('./manager.js').Manager */
6+
let manager;
7+
/** @type import('./preview.js').Preview */
8+
let preview;
9+
10+
test.describe('all in one', () => {
11+
test.beforeEach(async ({ page }) => {
12+
await page.goto('/');
13+
manager = new Manager(page);
14+
preview = new Preview(page);
15+
});
16+
17+
test('renders test story', async ({ page }) => {
18+
await expect(page).toHaveTitle(/^Test \/ Stories - Test Story/);
19+
expect(await preview.storyParent().innerHTML()).toContain('<div>Test Story works</div>');
20+
});
21+
22+
test('renders core manager toolbar', async () => {
23+
await expect(manager.toolbarItemByTitle('Remount component')).toBeVisible();
24+
await expect(manager.toolbarItemByTitle('Zoom in')).toBeVisible();
25+
await expect(manager.toolbarItemByTitle('Zoom out')).toBeVisible();
26+
await expect(manager.toolbarItemByTitle('Reset zoom')).toBeVisible();
27+
});
28+
29+
test('renders @storybook/addon-backgrounds toolbar', async () => {
30+
await expect(manager.toolbarItemByTitle('Change the background of the preview')).toBeVisible();
31+
await expect(manager.toolbarItemByTitle('Apply a grid to the preview')).toBeVisible();
32+
});
33+
34+
test('renders @storybook/addon-viewport toolbar', async () => {
35+
await expect(manager.toolbarItemByTitle('Change the size of the preview')).toBeVisible();
36+
});
37+
38+
test('renders @storybook/addon-measure toolbar', async () => {
39+
await expect(manager.toolbarItemByTitle('Enable measure')).toBeVisible();
40+
});
41+
42+
test('renders @storybook/addon-outline toolbar', async () => {
43+
await expect(manager.toolbarItemByTitle('Apply outlines to the preview')).toBeVisible();
44+
});
45+
46+
test('renders @storybook/addon-controls panel', async () => {
47+
const panelButton = manager.panelButtonByText('Controls');
48+
await panelButton.click();
49+
await expect(panelButton).toHaveClass(/tabbutton-active/);
50+
});
51+
52+
test('renders @storybook/addon-actions panel', async () => {
53+
const panelButton = manager.panelButtonByText('Actions');
54+
await panelButton.click();
55+
await expect(panelButton).toHaveClass(/tabbutton-active/);
56+
});
57+
58+
test('renders @storybook/addon-interactions panel', async () => {
59+
const panelButton = manager.panelButtonByText('Interactions');
60+
await panelButton.click();
61+
await expect(panelButton).toHaveClass(/tabbutton-active/);
62+
});
63+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** @type { import('@web/storybook-framework-web-components').StorybookConfig } */
2+
const config = {
3+
stories: ['../stories/**/*.stories.js'],
4+
addons: [
5+
'@storybook/addon-essentials',
6+
'@storybook/addon-links',
7+
'@storybook/addon-interactions',
8+
],
9+
framework: {
10+
name: '@web/storybook-framework-web-components',
11+
},
12+
};
13+
export default config;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { html } from 'lit';
2+
3+
export default {
4+
title: 'Test/Stories',
5+
};
6+
7+
export const TestStory = () => html`<div>Test Story works</div>`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export class Manager {
2+
/**
3+
* @param {import('@playwright/test').Page} page
4+
*/
5+
constructor(page) {
6+
this.page = page;
7+
}
8+
9+
/**
10+
* @param {string} title
11+
*/
12+
toolbarItemByTitle(title) {
13+
return this.page.locator(`[title="${title}"]`);
14+
}
15+
16+
/**
17+
* @param {string} text
18+
*/
19+
panelButtonByText(text) {
20+
return this.page
21+
.locator('[role="tablist"] button')
22+
.filter({ hasText: new RegExp(`^${text}$`) });
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export class Preview {
2+
/**
3+
* @param {import('@playwright/test').Page} page
4+
*/
5+
constructor(page) {
6+
this.page = page;
7+
}
8+
9+
previewIframe() {
10+
return this.page.frameLocator('#storybook-preview-iframe');
11+
}
12+
13+
storyParent() {
14+
return this.previewIframe().locator('#storybook-root > #root-inner');
15+
}
16+
}

0 commit comments

Comments
 (0)