Skip to content

Commit 764ddab

Browse files
committed
Add and use playwright for testing.
Add several tests using example maps. Remove nightwatch and old tests.
1 parent 7135303 commit 764ddab

10 files changed

+170
-57
lines changed

.github/workflows/playwright.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: lts/*
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Install Playwright Browsers
19+
run: npx playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: npx playwright test
22+
- uses: actions/upload-artifact@v4
23+
if: ${{ !cancelled() }}
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ favicon.ico
33
data/
44
dist/
55
bundle/
6-
tests_output/
76

87
# Logs
98
logs
@@ -109,3 +108,9 @@ dist
109108

110109
# TernJS port file
111110
.tern-port
111+
tests-examples/
112+
test-results/
113+
playwright-report/
114+
blob-report/
115+
playwright/.cache/
116+
*.js-snapshots

nightwatch.json

-20
This file was deleted.

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@
4242
"topojson": "^3.0.2"
4343
},
4444
"devDependencies": {
45-
"@babel/core": "^7.25.2",
46-
"@babel/preset-env": "^7.25.4",
45+
"@babel/core": "^7.25.7",
46+
"@babel/preset-env": "^7.25.7",
47+
"@playwright/test": "^1.47.2",
4748
"@rollup/plugin-babel": "^6.0.4",
4849
"@rollup/plugin-terser": "^0.4.4",
49-
"geckodriver": "^4.5.0",
50-
"nightwatch": "^3.8.0",
50+
"@types/node": "^22.7.4",
5151
"node-sass": "^9.0.0",
5252
"postcss": "^8.4.47",
53-
"rollup": "^4.22.5",
53+
"rollup": "^4.24.0",
5454
"rollup-plugin-postcss": "^4.0.2",
5555
"rollup-plugin-serve": "^1.1.1"
5656
},
5757
"scripts": {
5858
"build": "rollup -c --bundleConfigAsCjs",
5959
"watch": "rollup -c -w",
6060
"serve": "rollup -c rollup-serve.config.js -w",
61-
"test": "nightwatch tests/*.js"
61+
"test": "playwright test"
6262
}
6363
}

playwright.config.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
// require('dotenv').config({ path: path.resolve(__dirname, '.env') });
9+
10+
/**
11+
* @see https://playwright.dev/docs/test-configuration
12+
*/
13+
export default defineConfig({
14+
testDir: './tests',
15+
/* Run tests in files in parallel */
16+
fullyParallel: true,
17+
/* Fail the build on CI if you accidentally left test.only in the source code. */
18+
forbidOnly: !!process.env.CI,
19+
/* Retry on CI only */
20+
retries: process.env.CI ? 2 : 0,
21+
/* Opt out of parallel tests on CI. */
22+
workers: process.env.CI ? 1 : undefined,
23+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
24+
reporter: 'list',
25+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
26+
use: {
27+
/* Base URL to use in actions like `await page.goto('/')`. */
28+
// baseURL: 'http://127.0.0.1:3000',
29+
30+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
31+
trace: 'on-first-retry',
32+
},
33+
34+
/* Configure projects for major browsers */
35+
projects: [
36+
{
37+
name: 'chromium',
38+
use: { ...devices['Desktop Chrome'] },
39+
},
40+
41+
{
42+
name: 'firefox',
43+
use: { ...devices['Desktop Firefox'] },
44+
},
45+
46+
{
47+
name: 'webkit',
48+
use: { ...devices['Desktop Safari'] },
49+
},
50+
],
51+
52+
/* Run your local dev server before starting the tests */
53+
// webServer: {
54+
// command: 'npm run serve',
55+
// url: 'http://127.0.0.1:8000',
56+
// reuseExistingServer: !process.env.CI,
57+
// },
58+
});
59+

tests/choropleth.spec.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
const url_world = 'http://localhost:8000/examples/world-choropleth.html';
4+
5+
test('has title', async ({ page }) => {
6+
await page.goto(url_world);
7+
await expect(page).toHaveTitle(/World/);
8+
});
9+
10+
test('mauritania in world map', async ({ page }) => {
11+
await page.goto(url_world);
12+
13+
const loc = page.locator('path.unit-MRT');
14+
await expect(loc).toBeVisible();
15+
await expect(loc).toHaveAttribute('d');
16+
await expect(loc).toHaveAttribute('style', /fill/);
17+
18+
const title = await loc.locator('title').textContent();
19+
expect(title).toMatch(/Mauritania/);
20+
});
21+
22+
test('has legend', async ({ page }) => {
23+
await page.goto(url_world);
24+
25+
const loc = page.locator('rect.legend-bar');
26+
await expect(loc).toBeVisible();
27+
await expect(loc).toHaveAttribute('height');
28+
await expect(loc).toHaveAttribute('width');
29+
});
30+
31+
test('has annotation', async ({ page }) => {
32+
await page.goto(url_world);
33+
34+
const loc = page.locator('g.annotation');
35+
await expect(loc).toBeVisible();
36+
await expect(loc).toHaveAttribute('height');
37+
await expect(loc).toHaveAttribute('width');
38+
await expect(loc).toHaveText(/World Wide/)
39+
});

tests/data-array.js

-10
This file was deleted.

tests/geomap.spec.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
const url_world_plain = 'http://localhost:8000/examples/world-plain.html'
4+
5+
test('has title', async ({ page }) => {
6+
await page.goto(url_world_plain);
7+
await expect(page).toHaveTitle(/World/);
8+
});
9+
10+
test('spain in world map', async ({ page }) => {
11+
await page.goto(url_world_plain);
12+
13+
const loc = page.locator('path.unit-ESP');
14+
await expect(loc).toBeVisible();
15+
await expect(loc).toHaveAttribute('d');
16+
await expect(loc).toHaveText('Spain');
17+
});
18+
19+
test('data array', async ({ page }) => {
20+
await page.goto('http://localhost:8000/examples/data-array.html');
21+
22+
const loc = page.locator('path.unit-ESP');
23+
await expect(loc).toBeVisible();
24+
await expect(loc).toHaveAttribute('style', /fill/);
25+
});
26+
27+
test('missing unit id', async ({ page }) => {
28+
await page.goto('http://localhost:8000/examples/missing-unitid.html');
29+
30+
const loc = page.locator('path.unit-');
31+
await expect(loc).toBeVisible();
32+
await expect(loc).toHaveCSS('fill', 'rgb(0, 0, 0)');
33+
});

tests/missing-unitid.js

-10
This file was deleted.

tests/world-plain.js

-10
This file was deleted.

0 commit comments

Comments
 (0)