Skip to content

Commit

Permalink
Add and use playwright for testing.
Browse files Browse the repository at this point in the history
Add several tests using example maps.
Remove nightwatch and old tests.
  • Loading branch information
yaph committed Oct 4, 2024
1 parent 7135303 commit 764ddab
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 57 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -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@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ favicon.ico
data/
dist/
bundle/
tests_output/

# Logs
logs
Expand Down Expand Up @@ -109,3 +108,9 @@ dist

# TernJS port file
.tern-port
tests-examples/
test-results/
playwright-report/
blob-report/
playwright/.cache/
*.js-snapshots
20 changes: 0 additions & 20 deletions nightwatch.json

This file was deleted.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@
"topojson": "^3.0.2"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
"@babel/core": "^7.25.7",
"@babel/preset-env": "^7.25.7",
"@playwright/test": "^1.47.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-terser": "^0.4.4",
"geckodriver": "^4.5.0",
"nightwatch": "^3.8.0",
"@types/node": "^22.7.4",
"node-sass": "^9.0.0",
"postcss": "^8.4.47",
"rollup": "^4.22.5",
"rollup": "^4.24.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-serve": "^1.1.1"
},
"scripts": {
"build": "rollup -c --bundleConfigAsCjs",
"watch": "rollup -c -w",
"serve": "rollup -c rollup-serve.config.js -w",
"test": "nightwatch tests/*.js"
"test": "playwright test"
}
}
59 changes: 59 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// @ts-check
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config({ path: path.resolve(__dirname, '.env') });

/**
* @see https://playwright.dev/docs/test-configuration
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files 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. See https://playwright.dev/docs/test-reporters */
reporter: 'list',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run serve',
// url: 'http://127.0.0.1:8000',
// reuseExistingServer: !process.env.CI,
// },
});

39 changes: 39 additions & 0 deletions tests/choropleth.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { test, expect } from '@playwright/test';

const url_world = 'http://localhost:8000/examples/world-choropleth.html';

test('has title', async ({ page }) => {
await page.goto(url_world);
await expect(page).toHaveTitle(/World/);
});

test('mauritania in world map', async ({ page }) => {
await page.goto(url_world);

const loc = page.locator('path.unit-MRT');
await expect(loc).toBeVisible();
await expect(loc).toHaveAttribute('d');
await expect(loc).toHaveAttribute('style', /fill/);

const title = await loc.locator('title').textContent();
expect(title).toMatch(/Mauritania/);
});

test('has legend', async ({ page }) => {
await page.goto(url_world);

const loc = page.locator('rect.legend-bar');
await expect(loc).toBeVisible();
await expect(loc).toHaveAttribute('height');
await expect(loc).toHaveAttribute('width');
});

test('has annotation', async ({ page }) => {
await page.goto(url_world);

const loc = page.locator('g.annotation');
await expect(loc).toBeVisible();
await expect(loc).toHaveAttribute('height');
await expect(loc).toHaveAttribute('width');
await expect(loc).toHaveText(/World Wide/)
});
10 changes: 0 additions & 10 deletions tests/data-array.js

This file was deleted.

33 changes: 33 additions & 0 deletions tests/geomap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test, expect } from '@playwright/test';

const url_world_plain = 'http://localhost:8000/examples/world-plain.html'

test('has title', async ({ page }) => {
await page.goto(url_world_plain);
await expect(page).toHaveTitle(/World/);
});

test('spain in world map', async ({ page }) => {
await page.goto(url_world_plain);

const loc = page.locator('path.unit-ESP');
await expect(loc).toBeVisible();
await expect(loc).toHaveAttribute('d');
await expect(loc).toHaveText('Spain');
});

test('data array', async ({ page }) => {
await page.goto('http://localhost:8000/examples/data-array.html');

const loc = page.locator('path.unit-ESP');
await expect(loc).toBeVisible();
await expect(loc).toHaveAttribute('style', /fill/);
});

test('missing unit id', async ({ page }) => {
await page.goto('http://localhost:8000/examples/missing-unitid.html');

const loc = page.locator('path.unit-');
await expect(loc).toBeVisible();
await expect(loc).toHaveCSS('fill', 'rgb(0, 0, 0)');
});
10 changes: 0 additions & 10 deletions tests/missing-unitid.js

This file was deleted.

10 changes: 0 additions & 10 deletions tests/world-plain.js

This file was deleted.

0 comments on commit 764ddab

Please sign in to comment.