Skip to content

Commit d075303

Browse files
authored
Merge pull request #247 from hyanwong/basic-smoke-tests
Add some basic smoke tests
2 parents 411cf09 + 065f4ff commit d075303

8 files changed

Lines changed: 408 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.11"
19+
20+
- name: Install Python dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -e .
24+
pip install pytest
25+
26+
- name: Run Python tests
27+
run: python -m pytest tests/ -q
28+
29+
- name: Set up Node
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: "20"
33+
cache: "npm"
34+
35+
- name: Install Playwright package
36+
run: npm install
37+
38+
- name: Cache Playwright browsers
39+
id: playwright-cache
40+
uses: actions/cache@v4
41+
with:
42+
path: ~/.cache/ms-playwright
43+
key: ${{ runner.os }}-playwright-${{ hashFiles('package-lock.json') }}
44+
45+
- name: Install Playwright browser
46+
run: npx playwright install --with-deps chromium
47+
48+
- name: Run Playwright smoke tests
49+
run: npm run test:e2e

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
node_modules/
2+
test-results/
13
.ipynb_checkpoints
24
legacy_code/
35
.DS_Store

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,44 @@ A method for drawing ancestral recombination graphs from tskit tree sequences in
1414

1515
Users can click and drag the nodes (including the sample) along the x-axis to further clean up the layout of the graph. The simulation does not take into account line crosses, which can often be improved with some fiddling. Once a node has been moved by a user, its position is fixed with regards to the force simulation.
1616

17-
See [tutorial.md](https://github.com/kitchensjn/tskit_arg_visualizer/blob/main/docs/tutorial.md) for a walkthrough of the package.
17+
See [tutorial.md](https://github.com/kitchensjn/tskit_arg_visualizer/blob/main/docs/tutorial.md) for a walkthrough of the package.
18+
19+
## Testing (Local and CI)
20+
21+
This repository now includes:
22+
23+
- Python tests (pytest), under `tests/`
24+
- Minimal browser smoke tests (Playwright), under `tests/playwright/`
25+
26+
### Local setup
27+
28+
1. Install Python dependencies and test runner:
29+
30+
```bash
31+
python -m pip install --upgrade pip
32+
pip install -e .
33+
pip install pytest
34+
```
35+
36+
2. Install Playwright tooling:
37+
38+
```bash
39+
npm install
40+
npx playwright install --with-deps chromium
41+
```
42+
43+
3. Run tests:
44+
45+
```bash
46+
python -m pytest tests/ -q
47+
npm run test:e2e
48+
```
49+
50+
### GitHub Actions
51+
52+
CI is defined in `.github/workflows/ci.yml` and runs both:
53+
54+
- `python -m pytest tests/ -q`
55+
- `npm run test:e2e`
56+
57+
If commands change locally, update them in both this README and the workflow file so local and CI behavior stay aligned.

package-lock.json

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "tskit_arg_visualizer-e2e",
3+
"private": true,
4+
"version": "0.0.0",
5+
"description": "Minimal Playwright setup for browser smoke tests",
6+
"scripts": {
7+
"test:e2e": "playwright test",
8+
"test:e2e:headed": "playwright test --headed",
9+
"test:e2e:install": "playwright install --with-deps chromium"
10+
},
11+
"devDependencies": {
12+
"@playwright/test": "^1.54.1"
13+
}
14+
}

playwright.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { defineConfig } = require("@playwright/test");
2+
3+
module.exports = defineConfig({
4+
testDir: "tests/playwright",
5+
timeout: 30 * 1000,
6+
expect: {
7+
timeout: 5 * 1000,
8+
},
9+
use: {
10+
headless: true,
11+
},
12+
projects: [
13+
{
14+
name: "chromium",
15+
use: { browserName: "chromium" },
16+
},
17+
],
18+
});

tests/playwright/smoke.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { test, expect } = require("@playwright/test");
2+
const fs = require("fs");
3+
const os = require("os");
4+
const path = require("path");
5+
6+
// This smoke test intentionally avoids network or project-specific runtime
7+
// dependencies. It verifies that Playwright is wired up and can execute
8+
// JavaScript in a real browser context in CI.
9+
test("opens local HTML and evaluates client-side JS", async ({ page }) => {
10+
const html = [
11+
"<!doctype html>",
12+
"<html>",
13+
"<head><meta charset='utf-8'><title>argviz smoke</title></head>",
14+
"<body>",
15+
" <h1 id='status'>ready</h1>",
16+
" <script>",
17+
" document.getElementById('status').textContent = 'playwright-ok';",
18+
" </script>",
19+
"</body>",
20+
"</html>",
21+
].join("\n");
22+
23+
const htmlPath = path.join(os.tmpdir(), `argviz-playwright-${Date.now()}.html`);
24+
fs.writeFileSync(htmlPath, html, "utf8");
25+
26+
await page.goto(`file://${htmlPath}`);
27+
await expect(page.locator("#status")).toHaveText("playwright-ok");
28+
});

0 commit comments

Comments
 (0)