Skip to content

Commit

Permalink
Merge pull request #56 from kitsuyui/add-vrt-test
Browse files Browse the repository at this point in the history
Introduce VRT test
  • Loading branch information
kitsuyui authored May 20, 2023
2 parents f7e762a + 6510308 commit b4386a8
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 8 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test-vrt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: test-vrt
on: push
jobs:
test:
runs-on: macos-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: latest
cache: yarn
cache-dependency-path: yarn.lock

- name: Install dependencies
run: yarn install

- name: Test
run: yarn build

- name: Visual Regression Test
run: yarn test:vrt

- uses: actions/upload-artifact@v2
if: failure()
with:
name: playwright-report
path: examples/storybook/playwright-report/
retention-days: 1
1 change: 1 addition & 0 deletions examples/storybook/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
playwright-report
11 changes: 7 additions & 4 deletions examples/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@kitsuyui/react-clock": "file:../../packages/clock",
"@kitsuyui/react-stopwatch": "file:../../packages/stopwatch",
"@kitsuyui/react-timer": "file:../../packages/timer",
"@playwright/test": "^1.33.0",
"@storybook/addon-essentials": "^7.0.8",
"@storybook/addon-interactions": "^7.0.8",
"@storybook/addon-links": "^7.0.8",
"@storybook/blocks": "^7.0.8",
"@storybook/react": "^7.0.8",
"@storybook/react-webpack5": "^7.0.8",
"@storybook/testing-library": "^0.1.0",
"playwright": "^1.33.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.0.8",
"@kitsuyui/react-clock": "file:../../packages/clock",
"@kitsuyui/react-timer": "file:../../packages/timer",
"@kitsuyui/react-stopwatch": "file:../../packages/stopwatch"
"storybook": "^7.0.8"
},
"scripts": {
"start": "storybook dev -p 6006",
"storybook": "storybook dev -p 6006",
"test:vrt": "playwright test",
"build-storybook": "storybook build"
}
}
58 changes: 58 additions & 0 deletions examples/storybook/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { defineConfig, devices } from '@playwright/test'

// https://playwright.dev/docs/test-configuration
export default defineConfig({
// Look for test files in the "tests" directory, relative to this configuration file.
testDir: 'tests',

// Run all tests 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
reporter: 'html',

expect: {
// Maximum time expect() should wait for the condition to be met.
timeout: 5000,

// toHaveScreenshot: {
// // An acceptable amount of pixels that could be different, unset by default.
// maxDiffPixels: 1,
// },

// toMatchSnapshot: {
// // An acceptable ratio of pixels that are different to the total amount of pixels, between 0 and 1.
// maxDiffPixelRatio: 0.0125,
// },
},

use: {
// Base URL to use in actions like `await page.goto('/')`.
baseURL: 'http://127.0.0.1:6006',

// Collect trace when retrying the failed test.
trace: 'on-first-retry',
},
// Configure projects for major browsers.
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
// Run your local dev server before starting the tests.
webServer: {
command: 'yarn start',
url: 'http://127.0.0.1:6006',
reuseExistingServer: !process.env.CI,
},
})
5 changes: 3 additions & 2 deletions examples/storybook/stories/Clock.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ export default {
}

AnalogClock.defaultProps = {
date: new Date(),
// https://museum.seiko.co.jp/en/knowledge/trivia01/
date: new Date('2023-01-01T10:08:42Z'),
timezone: 'UTC',
}

const Template = (args) => <AnalogClock {...args} />

export const Default = Template.bind({})
Default.args = {
date: new Date(),
date: new Date('2023-01-01T10:08:42Z'),
timezone: 'UTC',
}
10 changes: 10 additions & 0 deletions examples/storybook/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { test, expect } from '@playwright/test'

test('clock page', async ({ page }) => {
await page.goto('http://localhost:6006/?path=/story/clock--default')
await page.waitForSelector('iframe[data-is-loaded="true"]')
const screenshot = await page
.locator('#storybook-preview-iframe')
.screenshot()
expect(screenshot).toMatchSnapshot('clock-image.png')
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "turbo build",
"test": "turbo test",
"lint": "turbo lint",
"test:vrt": "turbo test:vrt",
"format:prettier": "prettier --write .",
"format:eslint": "eslint . --ext .js,.jsx,.ts,.tsx --ignore-path .gitignore --fix",
"lint:prettier": "prettier --check .",
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"test": {
"dependsOn": ["^test"]
}
},
"test:vrt": {}
}
}
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,16 @@
picocolors "^1.0.0"
tslib "^2.5.0"

"@playwright/test@^1.33.0":
version "1.33.0"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.33.0.tgz#669ef859efb81b143dfc624eef99d1dd92a81b67"
integrity sha512-YunBa2mE7Hq4CfPkGzQRK916a4tuZoVx/EpLjeWlTVOnD4S2+fdaQZE0LJkbfhN5FTSKNLdcl7MoT5XB37bTkg==
dependencies:
"@types/node" "*"
playwright-core "1.33.0"
optionalDependencies:
fsevents "2.3.2"

"@pmmmwh/react-refresh-webpack-plugin@^0.5.3", "@pmmmwh/react-refresh-webpack-plugin@^0.5.5":
version "0.5.10"
resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.10.tgz#2eba163b8e7dbabb4ce3609ab5e32ab63dda3ef8"
Expand Down Expand Up @@ -6561,7 +6571,7 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@^2.3.2, fsevents@~2.3.2:
fsevents@2.3.2, fsevents@^2.3.2, fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
Expand Down Expand Up @@ -9338,6 +9348,18 @@ pkg-up@^3.1.0:
dependencies:
find-up "^3.0.0"

playwright-core@1.33.0:
version "1.33.0"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.33.0.tgz#269efe29a927cd6d144d05f3c2d2f72bd72447a1"
integrity sha512-aizyPE1Cj62vAECdph1iaMILpT0WUDCq3E6rW6I+dleSbBoGbktvJtzS6VHkZ4DKNEOG9qJpiom/ZxO+S15LAw==

playwright@^1.33.0:
version "1.33.0"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.33.0.tgz#88df1cffe97718ab8a02303e12c9133681ec7fab"
integrity sha512-+zzU3V2TslRX2ETBRgQKsKytYBkJeLZ2xzUj4JohnZnxQnivoUvOvNbRBYWSYykQTO0Y4zb8NwZTYFUO+EpPBQ==
dependencies:
playwright-core "1.33.0"

polished@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/polished/-/polished-4.2.2.tgz#2529bb7c3198945373c52e34618c8fe7b1aa84d1"
Expand Down

0 comments on commit b4386a8

Please sign in to comment.