Skip to content

Commit

Permalink
added snapshot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick committed Nov 6, 2023
1 parent dd2b793 commit c37aa07
Show file tree
Hide file tree
Showing 34 changed files with 5,174 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/storybook-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# .github/workflows/storybook-tests.yml

name: Storybook Tests
on: deployment_status
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: yarn
- name: Install Playwright
run: npx playwright install --with-deps
- name: Run Storybook tests
run: yarn test-storybook
env:
TARGET_URL: '${{ github.event.deployment_status.target_url }}'
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.12.1
16 changes: 16 additions & 0 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// .storybook/test-runner.ts

// pk: https://storybook.js.org/docs/web-components/writing-tests/snapshot-testing

import type { TestRunnerConfig } from '@storybook/test-runner';

const config: TestRunnerConfig = {
async postRender(page, context) {
// the #storybook-root element wraps each story
const elementHandler = await page.$('#storybook-root');
const innerHTML = await elementHandler?.innerHTML();
expect(innerHTML).toMatchSnapshot();
}
};

export default config;
14 changes: 14 additions & 0 deletions .test-runner-jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ./test-runner-jest.config.js


// PK: https://storybook.js.org/docs/web-components/writing-tests/snapshot-testing

const path = require('path');

module.exports = {
resolveSnapshotPath: (testPath, snapshotExtension) =>
path.join(process.cwd(), '__snapshots__', path.basename(testPath) + snapshotExtension),
resolveTestPath: (snapshotFilePath, snapshotExtension) =>
path.join(process.env.TEST_ROOT, path.basename(snapshotFilePath, snapshotExtension)),
testPathForConsistencyCheck: path.join(process.env.TEST_ROOT, 'example.test.js'),
};
Loading

0 comments on commit c37aa07

Please sign in to comment.