Skip to content

Commit

Permalink
Merge branch 'master' into feature/storybook-8
Browse files Browse the repository at this point in the history
  • Loading branch information
jpzwarte committed Mar 18, 2024
2 parents 24501cf + 2f04ee7 commit bc1b090
Show file tree
Hide file tree
Showing 17 changed files with 5,585 additions and 8,064 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/verify-storybook-builder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Verify Storybook Builder

on: pull_request

jobs:
verify-storybook-builder:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node 20
uses: actions/setup-node@v4
env:
FORCE_COLOR: 0
with:
node-version: 20
cache: npm

- name: Install Dependencies
run: npm ci

- name: Build packages
run: npm run build

- name: Symlink built packages binaries (e.g. "wds")
run: npm ci

- name: Install Playwright Browsers
run: npx playwright install --with-deps

- name: Run tests
run: npm run test:storybook-builder

- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: packages/storybook-framework-web-components/playwright-report/
retention-days: 30
13,392 changes: 5,334 additions & 8,058 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
"search": "rocket search",
"start": "rocket start",
"start:build": "node packages/dev-server/dist/bin.js --root-dir _site --open",
"test": "npm run test:node && npm run test:browser",
"test": "npm run test:node && npm run test:browser && npm run test:storybook-builder",
"test:browser": "npm run test:browser --workspaces --if-present",
"test:node": "npm run test:node --workspaces --if-present",
"test:storybook-builder": "npm test --prefix ./packages/storybook-framework-web-components",
"types": "wireit",
"update": "npm run update:mjs-dts-entrypoints && npm run update:tsconfigs",
"update-dependency": "node scripts/update-dependency.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/storybook-builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @web/storybook-builder

## 0.1.8

### Patch Changes

- 331e6215: fix tocbot default import by @storybook/blocks

## 0.1.7

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook-builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web/storybook-builder",
"version": "0.1.7",
"version": "0.1.8",
"publishConfig": {
"access": "public"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ export function esbuildPluginCommonjsNamedExports(module: string, namedExports:
contents: `
import { default as commonjsExports } from '${module}?force-original';
${namedExports
.map(name => `export const ${name} = commonjsExports.${name};`)
.map(name => {
if (name === 'default') {
return `export default commonjsExports;`;
} else {
return `export const ${name} = commonjsExports.${name};`;
}
})
.join('\n')}
`,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function rollupPluginPrebundleModules(env: Record<string, string>): Plugi
/* for @storybook/addon-docs */
// tocbot can't be automatically transformed by @chialab/esbuild-plugin-commonjs
// so we need a manual wrapper
esbuildPluginCommonjsNamedExports('tocbot', ['init', 'destroy']),
esbuildPluginCommonjsNamedExports('tocbot', ['default', 'init', 'destroy']),

esbuildPluginCommonjs(),
],
Expand Down
4 changes: 4 additions & 0 deletions packages/storybook-framework-web-components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
test-results/
playwright-report/
storybook-build/
16 changes: 14 additions & 2 deletions packages/storybook-framework-web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
"node": ">=16.0.0"
},
"scripts": {
"build": "tsc"
"build": "tsc",
"test": "npm run test:build && npm run test:ui:build && npm run test:ui:runtime",
"test:build": "storybook build -c ./tests/fixtures/all-in-one/.storybook -o ./tests/fixtures/all-in-one/storybook-build",
"test:start:build": "wds -r ./tests/fixtures/all-in-one/storybook-build -p 3000",
"test:start:runtime": "storybook dev -c ./tests/fixtures/all-in-one/.storybook -p 3000 --no-open",
"test:ui:build": "npx playwright test -c playwright.build.config.ts",
"test:ui:runtime": "npx playwright test -c playwright.runtime.config.ts"
},
"files": [
"*.d.ts",
Expand All @@ -58,6 +64,12 @@
"@web/storybook-builder": "^0.1.0"
},
"devDependencies": {
"@storybook/types": "^8.0.0"
"@playwright/test": "^1.22.2",
"@storybook/addon-essentials": "^8.0.0",
"@storybook/addon-interactions": "^8.0.0",
"@storybook/addon-links": "^8.0.0",
"@storybook/types": "^8.0.0",
"@web/dev-server": "^0.4.0",
"storybook": "^8.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { defineConfig, devices } from '@playwright/test';

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',

/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Run your local dev server before starting the tests */
webServer: {
command: '',
url: 'http://127.0.0.1:3000',
reuseExistingServer: !process.env.CI,
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import baseConfig from './playwright.base.config.ts';

// @ts-ignore
baseConfig.webServer.command = 'npm run test:start:build';

export default baseConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import baseConfig from './playwright.base.config.ts';

// @ts-ignore
baseConfig.webServer.command = 'npm run test:start:runtime';

export default baseConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect, test } from '@playwright/test';
import { Manager } from './manager.js';
import { Preview } from './preview.js';

/** @type import('./manager.js').Manager */
let manager;
/** @type import('./preview.js').Preview */
let preview;

test.describe('all in one', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/');
manager = new Manager(page);
preview = new Preview(page);
});

test('renders test story', async ({ page }) => {
await expect(page).toHaveTitle(/^Test \/ Stories - Test Story/);
expect(await preview.storyParent().innerHTML()).toContain('<div>Test Story works</div>');
});

test('renders core manager toolbar', async () => {
await expect(manager.toolbarItemByTitle('Remount component')).toBeVisible();
await expect(manager.toolbarItemByTitle('Zoom in')).toBeVisible();
await expect(manager.toolbarItemByTitle('Zoom out')).toBeVisible();
await expect(manager.toolbarItemByTitle('Reset zoom')).toBeVisible();
});

test('renders @storybook/addon-backgrounds toolbar', async () => {
await expect(manager.toolbarItemByTitle('Change the background of the preview')).toBeVisible();
await expect(manager.toolbarItemByTitle('Apply a grid to the preview')).toBeVisible();
});

test('renders @storybook/addon-viewport toolbar', async () => {
await expect(manager.toolbarItemByTitle('Change the size of the preview')).toBeVisible();
});

test('renders @storybook/addon-measure toolbar', async () => {
await expect(manager.toolbarItemByTitle('Enable measure')).toBeVisible();
});

test('renders @storybook/addon-outline toolbar', async () => {
await expect(manager.toolbarItemByTitle('Apply outlines to the preview')).toBeVisible();
});

test('renders @storybook/addon-controls panel', async () => {
const panelButton = manager.panelButtonByText('Controls');
await panelButton.click();
await expect(panelButton).toHaveClass(/tabbutton-active/);
});

test('renders @storybook/addon-actions panel', async () => {
const panelButton = manager.panelButtonByText('Actions');
await panelButton.click();
await expect(panelButton).toHaveClass(/tabbutton-active/);
});

test('renders @storybook/addon-interactions panel', async () => {
const panelButton = manager.panelButtonByText('Interactions');
await panelButton.click();
await expect(panelButton).toHaveClass(/tabbutton-active/);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type { import('@web/storybook-framework-web-components').StorybookConfig } */
const config = {
stories: ['../stories/**/*.stories.js'],
addons: [
'@storybook/addon-essentials',
'@storybook/addon-links',
'@storybook/addon-interactions',
],
framework: {
name: '@web/storybook-framework-web-components',
},
};
export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { html } from 'lit';

export default {
title: 'Test/Stories',
};

export const TestStory = () => html`<div>Test Story works</div>`;
24 changes: 24 additions & 0 deletions packages/storybook-framework-web-components/tests/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export class Manager {
/**
* @param {import('@playwright/test').Page} page
*/
constructor(page) {
this.page = page;
}

/**
* @param {string} title
*/
toolbarItemByTitle(title) {
return this.page.locator(`[title="${title}"]`);
}

/**
* @param {string} text
*/
panelButtonByText(text) {
return this.page
.locator('[role="tablist"] button')
.filter({ hasText: new RegExp(`^${text}$`) });
}
}
16 changes: 16 additions & 0 deletions packages/storybook-framework-web-components/tests/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export class Preview {
/**
* @param {import('@playwright/test').Page} page
*/
constructor(page) {
this.page = page;
}

previewIframe() {
return this.page.frameLocator('#storybook-preview-iframe');
}

storyParent() {
return this.previewIframe().locator('#storybook-root > #root-inner');
}
}

0 comments on commit bc1b090

Please sign in to comment.