Skip to content

Commit 316a616

Browse files
authored
Add visual test structure (#3)
* Add visual test structure * Fix configuration * Add webkit snapshots * Upload artifact only on failure * Fix MANIFEST * Skip autofocus for now
1 parent fe64b32 commit 316a616

27 files changed

+425
-24
lines changed

.github/workflows/ci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,56 @@ jobs:
3434
run: yarn run test
3535
working-directory: packages/components
3636

37+
visual-test:
38+
runs-on: ubuntu-latest
39+
timeout-minutes: 10
40+
steps:
41+
- name: Checkout 🛎️
42+
uses: actions/checkout@v2
43+
44+
- name: Setup Node 💾
45+
uses: actions/setup-node@v2
46+
with:
47+
node-version: '14'
48+
49+
- name: Get yarn cache directory path
50+
id: yarn-cache-dir-path
51+
run: echo "::set-output name=dir::$(yarn cache dir)"
52+
- name: Setup yarn cache
53+
uses: actions/cache@v2
54+
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
55+
with:
56+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
57+
key: yarn-${{ hashFiles('**/yarn.lock') }}
58+
restore-keys: |
59+
yarn-
60+
61+
- name: Install Dependencies 📥
62+
run: yarn install
63+
64+
- name: Install Playwright Browsers
65+
run: yarn run playwright install --with-deps
66+
working-directory: packages/components
67+
68+
- name: Run Visual Tests 🧪
69+
run: yarn run test:visual
70+
working-directory: packages/components
71+
72+
- name: Update Snapshots
73+
if: ${{ failure() }}
74+
run: |
75+
mv test-results test-assets
76+
yarn run test:visual -u
77+
working-directory: packages/components
78+
79+
- uses: actions/upload-artifact@v2
80+
if: ${{ failure() }}
81+
with:
82+
name: jupyter-ui-test
83+
path: |
84+
packages/components/test-assets/
85+
packages/components/src/**/*-snapshots/*
86+
3787
lint:
3888
runs-on: ubuntu-latest
3989
timeout-minutes: 10

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,6 @@ yarn-error.log*
128128

129129
# Cache
130130
temp
131+
132+
# Visual testing
133+
packages/components/test-results

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ graft jupyter_ui_demo/labextension
1414
# Javascript files
1515
include packages/components/api-extractor.json
1616
include packages/components/package.json
17+
include packages/components/jest.config.js
18+
include packages/components/playwright.config.ts
1719
include packages/components/rollup.config.js
1820
include packages/components/tsconfig.json
1921
graft packages/components/.storybook

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
![Extension status](https://img.shields.io/badge/status-draft-critical 'Not yet working')
66
[![NPM Version](https://img.shields.io/npm/v/@jupyter-notebook/web-components?color=blue)](https://www.npmjs.com/package/@jupyter-notebook/web-components)
7-
![Toolkit CI Status](https://github.com/jupyterlab-contrib/jupyter-ui-toolkit/actions/workflows/ci.yml/badge.svg)
7+
[![Toolkit CI Status](https://github.com/jupyterlab-contrib/jupyter-ui-toolkit/actions/workflows/ci.yml/badge.svg)](https://github.com/jupyterlab-contrib/jupyter-ui-toolkit/actions/workflows/ci.yml)
88
![Deploy Docs Status](https://github.com/jupyterlab-contrib/jupyter-ui-toolkit/actions/workflows/docs-cd.yml/badge.svg)
99
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyterlab-contrib/jupyter-ui-toolkit/main)
1010

packages/components/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ src/utilities/storybook/
1717
src/**/*.spec.ts
1818
src/**/*.stories.ts
1919
src/**/fixtures/
20+
playwright.config.ts

packages/components/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const config = {
2+
testMatch: ['**/?(*.)+(spec).ts']
3+
};
4+
5+
module.exports = config;

packages/components/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"eslint:check": "eslint . --ext .ts",
2727
"eslint": "eslint . --ext .ts --fix",
2828
"prepublishOnly": "yarn run build",
29-
"test": "jest --verbose --coverage"
29+
"test": "jest --verbose --coverage",
30+
"test:visual": "playwright test"
3031
},
3132
"dependencies": {
3233
"@microsoft/fast-element": "^1.6.0",
@@ -39,6 +40,7 @@
3940
"@babel/preset-typescript": "^7.13.0",
4041
"@microsoft/api-extractor": "^7.18.9",
4142
"@microsoft/eslint-config-fast-dna": "^1.2.0",
43+
"@playwright/test": "^1.17.0",
4244
"@rollup/plugin-commonjs": "^17.1.0",
4345
"@rollup/plugin-node-resolve": "^11.2.0",
4446
"@rollup/plugin-typescript": "^8.2.0",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { PlaywrightTestConfig, devices } from '@playwright/test';
2+
3+
const config: PlaywrightTestConfig = {
4+
forbidOnly: !!process.env.CI,
5+
retries: process.env.CI ? 2 : 0,
6+
testMatch: '**/*.test.ts',
7+
webServer: {
8+
command: 'yarn run start',
9+
port: 6006,
10+
timeout: 120 * 1000,
11+
// It is safe to reuse the server for stories testing
12+
reuseExistingServer: true
13+
},
14+
use: {
15+
baseURL: process.env.TARGET_URL ?? 'http://localhost:6006',
16+
trace: 'on-first-retry'
17+
},
18+
projects: [
19+
{
20+
name: 'chromium',
21+
use: { ...devices['Desktop Chrome'] }
22+
},
23+
{
24+
name: 'firefox',
25+
use: { ...devices['Desktop Firefox'] }
26+
},
27+
{
28+
name: 'webkit',
29+
use: { ...devices['Desktop Safari'] }
30+
}
31+
]
32+
};
33+
34+
export default config;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.describe('Badge', () => {
4+
test('Default', async ({ page }) => {
5+
await page.goto('/iframe.html?id=library-badge--default');
6+
7+
expect(
8+
await page.locator('#root :nth-child(1)').first().screenshot()
9+
).toMatchSnapshot('badge-default.png');
10+
});
11+
});
439 Bytes
Loading

0 commit comments

Comments
 (0)