Skip to content

Commit 28f0e38

Browse files
authored
Add playwright tests (#425)
* Add playwright tests * Update * Update * Update * Update * Update
1 parent e61fce9 commit 28f0e38

File tree

8 files changed

+614
-0
lines changed

8 files changed

+614
-0
lines changed

.github/workflows/test_widget.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Test Widget
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test_python:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
version: ['3.10', '3.12']
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: astral-sh/setup-uv@v3
14+
with:
15+
version: "latest"
16+
env:
17+
UV_PYTHON: ${{ matrix.version }}
18+
- uses: actions/setup-node@v3
19+
with:
20+
node-version: 22
21+
- uses: pnpm/action-setup@v4
22+
with:
23+
run_install: |
24+
- cwd: tests-widget
25+
package_json_file: tests-widget/package.json
26+
- name: Install Playwright Browsers
27+
run: pnpm exec playwright install --with-deps
28+
working-directory: ./tests-widget
29+
- name: Install vitessce
30+
run: uv sync --extra dev --extra all
31+
- name: Export notebook to HTML
32+
run: uv run jupyter nbconvert --to=html --execute docs/notebooks/widget_from_dict.ipynb
33+
- name: Check that widget renders in HTML output using Playwright
34+
run: pnpm exec playwright test
35+
working-directory: ./tests-widget

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,13 @@ vitessce/yarn.lock
3333
.DS_Store
3434
.nova/
3535
.vscode/
36+
37+
# Playwright
38+
/test-results/
39+
/playwright-report/
40+
/blob-report/
41+
/playwright/.cache/
42+
tests-widget/test-results/
43+
tests-widget/playwright-report/
44+
tests-widget/blob-report/
45+
tests-widget/playwright/.cache/

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ global-exclude *.pyc
1313
global-exclude *.pyo
1414
global-exclude .git
1515
global-exclude .ipynb_checkpoints
16+
global-exclude tests-widget
1617
global-exclude *.map

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ignore =
2020
E128
2121
exclude =
2222
./js/node_modules/,
23+
./tests-widget/,
2324
./docs/,
2425
./demos/,
2526
./binder/,

tests-widget/example.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @ts-check
2+
import { test, expect } from '@playwright/test';
3+
4+
test('Renders Vitessce widget containing a scatterplot view', async ({ page }) => {
5+
test.setTimeout(60_000);
6+
await page.goto('http://localhost:3000/widget_from_dict.html');
7+
8+
// Expect a title "to contain" a substring.
9+
await expect(page).toHaveTitle('widget_from_dict');
10+
11+
await expect(page.getByText('Scatterplot (UMAP)')).toBeVisible();
12+
await expect(page.getByText('523 cells')).toHaveCount(3);
13+
});

tests-widget/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "tests-widget",
3+
"packageManager": "[email protected]",
4+
"private": true,
5+
"version": "1.0.0",
6+
"description": "",
7+
"scripts": {
8+
"start-demo": "http-server --cors='*' --port 3000 ../docs/notebooks"
9+
},
10+
"devDependencies": {
11+
"@playwright/test": "^1.52.0",
12+
"@types/node": "^22.15.18",
13+
"http-server": "^14.1.1"
14+
}
15+
}

tests-widget/playwright.config.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// @ts-check
2+
import { defineConfig, devices } from '@playwright/test';
3+
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
// import dotenv from 'dotenv';
9+
// import path from 'path';
10+
// dotenv.config({ path: path.resolve(__dirname, '.env') });
11+
12+
/**
13+
* @see https://playwright.dev/docs/test-configuration
14+
*/
15+
export default defineConfig({
16+
testDir: '.',
17+
/* Run tests in files in parallel */
18+
fullyParallel: true,
19+
/* Fail the build on CI if you accidentally left test.only in the source code. */
20+
forbidOnly: !!process.env.CI,
21+
/* Retry on CI only */
22+
retries: process.env.CI ? 2 : 0,
23+
/* Opt out of parallel tests on CI. */
24+
workers: process.env.CI ? 1 : undefined,
25+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
26+
reporter: 'html',
27+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
28+
use: {
29+
/* Base URL to use in actions like `await page.goto('/')`. */
30+
// baseURL: 'http://127.0.0.1:3000',
31+
32+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
33+
trace: 'on-first-retry',
34+
},
35+
36+
/* Configure projects for major browsers */
37+
projects: [
38+
{
39+
name: 'chromium',
40+
use: { ...devices['Desktop Chrome'] },
41+
},
42+
43+
/*{
44+
name: 'firefox',
45+
use: { ...devices['Desktop Firefox'] },
46+
},
47+
48+
{
49+
name: 'webkit',
50+
use: { ...devices['Desktop Safari'] },
51+
},*/
52+
53+
/* Test against mobile viewports. */
54+
// {
55+
// name: 'Mobile Chrome',
56+
// use: { ...devices['Pixel 5'] },
57+
// },
58+
// {
59+
// name: 'Mobile Safari',
60+
// use: { ...devices['iPhone 12'] },
61+
// },
62+
63+
/* Test against branded browsers. */
64+
// {
65+
// name: 'Microsoft Edge',
66+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
67+
// },
68+
// {
69+
// name: 'Google Chrome',
70+
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
71+
// },
72+
],
73+
74+
/* Run your local dev server before starting the tests */
75+
webServer: {
76+
command: 'pnpm run start-demo',
77+
url: 'http://localhost:3000/',
78+
// reuseExistingServer: !process.env.CI,
79+
},
80+
});
81+

0 commit comments

Comments
 (0)