Browse Source
add image and dom snapshot comparison for storybook components image snapshot comparison can been flaky and produce many false-positives. a higher threshold has been used to mitigate this although it may not identify all regressions. DOM snapshots supplement images to increase the likelihood of capturing regressions.master
8 changed files with 2073 additions and 51 deletions
@ -0,0 +1,27 @@ |
|||||||
|
name: Playwright Tests |
||||||
|
on: |
||||||
|
push: |
||||||
|
branches: [ main, master ] |
||||||
|
pull_request: |
||||||
|
branches: [ main, master ] |
||||||
|
jobs: |
||||||
|
test: |
||||||
|
timeout-minutes: 60 |
||||||
|
runs-on: ubuntu-latest |
||||||
|
steps: |
||||||
|
- uses: actions/checkout@v3 |
||||||
|
- uses: actions/setup-node@v3 |
||||||
|
with: |
||||||
|
node-version: 18 |
||||||
|
- name: Install dependencies |
||||||
|
run: yarn |
||||||
|
- name: Install Playwright Browsers |
||||||
|
run: yarn playwright install --with-deps |
||||||
|
- name: Run Storybook tests |
||||||
|
run: yarn test-storybook:ci |
||||||
|
- uses: actions/upload-artifact@v3 |
||||||
|
if: always() |
||||||
|
with: |
||||||
|
name: playwright-report |
||||||
|
path: playwright-report/ |
||||||
|
retention-days: 30 |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
import type { TestRunnerConfig } from "@storybook/test-runner"; |
||||||
|
import { toMatchImageSnapshot } from 'jest-image-snapshot'; |
||||||
|
|
||||||
|
const customSnapshotsDir = `${process.cwd()}/__snapshots__`; |
||||||
|
|
||||||
|
|
||||||
|
const config: TestRunnerConfig = { |
||||||
|
setup() { |
||||||
|
expect.extend({ toMatchImageSnapshot }); |
||||||
|
}, |
||||||
|
async postRender(page, context) { |
||||||
|
// DOM Snapshot
|
||||||
|
const elementHandler = await page.$('#storybook-root'); |
||||||
|
if (elementHandler) { |
||||||
|
const innerHTML = await elementHandler.innerHTML(); |
||||||
|
expect(innerHTML).toMatchSnapshot(); |
||||||
|
} |
||||||
|
// Image Snapshop
|
||||||
|
const image = await page.screenshot(); |
||||||
|
expect(image).toMatchImageSnapshot({ |
||||||
|
customSnapshotsDir, |
||||||
|
customSnapshotIdentifier: context.id, |
||||||
|
failureThresholdType: 'percent', |
||||||
|
failureThreshold: 0.002, |
||||||
|
}); |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
export default config; |
||||||
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 13 KiB |
@ -0,0 +1,76 @@ |
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP |
||||||
|
|
||||||
|
exports[`Navbar Default smoke-test 1`] = ` |
||||||
|
<div class="navbar bg-neutral"> |
||||||
|
<div class="flex-1"> |
||||||
|
<h4> |
||||||
|
<span class="primary"> |
||||||
|
git |
||||||
|
</span> |
||||||
|
<span class> |
||||||
|
together |
||||||
|
</span> |
||||||
|
<span class> |
||||||
|
.xyz |
||||||
|
</span> |
||||||
|
</h4> |
||||||
|
</div> |
||||||
|
<div class="flex-none gap-4"> |
||||||
|
<div class="btn btn-primary normal-case"> |
||||||
|
Sign up |
||||||
|
</div> |
||||||
|
<button class="btn btn-outline normal-case"> |
||||||
|
Login |
||||||
|
</button> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
`; |
||||||
|
|
||||||
|
exports[`Navbar NIP07Exists smoke-test 1`] = ` |
||||||
|
<div class="navbar bg-neutral"> |
||||||
|
<div class="flex-1"> |
||||||
|
<h4> |
||||||
|
<span class="primary"> |
||||||
|
git |
||||||
|
</span> |
||||||
|
<span class> |
||||||
|
together |
||||||
|
</span> |
||||||
|
<span class> |
||||||
|
.xyz |
||||||
|
</span> |
||||||
|
</h4> |
||||||
|
</div> |
||||||
|
<div class="flex-none gap-4"> |
||||||
|
<button class="btn btn-outline normal-case"> |
||||||
|
Login |
||||||
|
</button> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
`; |
||||||
|
|
||||||
|
exports[`Navbar NoNIP07 smoke-test 1`] = ` |
||||||
|
<div class="navbar bg-neutral"> |
||||||
|
<div class="flex-1"> |
||||||
|
<h4> |
||||||
|
<span class="primary"> |
||||||
|
git |
||||||
|
</span> |
||||||
|
<span class> |
||||||
|
together |
||||||
|
</span> |
||||||
|
<span class> |
||||||
|
.xyz |
||||||
|
</span> |
||||||
|
</h4> |
||||||
|
</div> |
||||||
|
<div class="flex-none gap-4"> |
||||||
|
<div class="btn btn-primary normal-case"> |
||||||
|
Sign up |
||||||
|
</div> |
||||||
|
<button class="btn btn-outline normal-case"> |
||||||
|
Login |
||||||
|
</button> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
`; |
||||||
Loading…
Reference in new issue