Skip to content

Commit 3e2b8b5

Browse files
authored
feat(tests) :: add convenient reproduce script (#1578)
Adds a reproduce script that runs tests against specified SQLPage versions and specified databases via docker images. Helps with #1566 Assisted-By :: Claude Opus 5.5
1 parent e46132a commit 3e2b8b5

5 files changed

Lines changed: 79 additions & 7 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ built executable. Component suites use `fixtures/<suite>/{index.sql,test.ts}` an
6666
import the shared `fixture.ts` harness; root-level `*.spec.ts` files cover the
6767
official site.
6868

69-
To show that an issue exists before you fix it, set `SQLPAGE_RELEASE` to a release tag, such as `SQLPAGE_RELEASE=v0.47.0 npx playwright test fixtures/tracking`. Both servers then run that release's Docker image against the same fixtures, on ports 18080 and 18081, so the test fails on the release and passes on your working tree. Add `--ui` to watch the page in each step.
69+
To show that an issue exists before you fix it, put the reproduction in a fixture and run it against releases with one command, such as `nix run .#reproduce -- repro_721 postgres v0.35.0 v0.36.1 tree`. The second argument is `sqlite` or `postgres`, and `tree` is your working tree. It prints Playwright's output for each version, then a table you can paste into the issue or pull request. Releases run from their Docker images, from v0.29.0 onwards, and Postgres from `docker compose`. Without Nix, run `npm run reproduce --` in `tests/end-to-end` instead.
70+
71+
To run a whole suite against a release instead, set `SQLPAGE_RELEASE` to its tag, such as `SQLPAGE_RELEASE=v0.47.0 npx playwright test fixtures/tracking`. Both servers then run that release's Docker image against the same fixtures, on ports 18080 and 18081, so the test fails on the release and passes on your working tree. Add `--ui` to watch the page in each step.
7072

7173
The fixtures run on in-memory SQLite. To reproduce an issue with another database, start it with `docker compose up --wait <database>` and set `FIXTURES_DATABASE_URL` to its connection string from the [CI matrix](./.github/workflows/ci.yml), such as `FIXTURES_DATABASE_URL='postgres://root:Password123!@127.0.0.1/sqlpage'`. Only the fixtures server uses it, so the official site keeps its own database, and it works with `SQLPAGE_RELEASE` too.
7274

‎flake.nix‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@
134134
PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = "true";
135135
};
136136

137+
# The Nix-built browsers find their own libraries; host libraries leaked in
138+
# through LD_LIBRARY_PATH crash Chromium at launch.
139+
inBrowserWorkspace =
140+
command:
141+
buildBrowserAssets
142+
+ ''
143+
unset LD_LIBRARY_PATH
144+
cd tests/end-to-end
145+
''
146+
+ command;
147+
137148
gatesFor =
138149
pkgs:
139150
lib.mapAttrs
@@ -192,15 +203,20 @@
192203
description = "Drive the components in a browser with Playwright";
193204
packages = cargoRuntime pkgs;
194205
env = cargoEnv pkgs // playwrightEnv pkgs;
195-
script = buildBrowserAssets + ''
196-
# The Nix-built browsers find their own libraries; host libraries
197-
# leaked in through LD_LIBRARY_PATH crash Chromium at launch.
198-
unset LD_LIBRARY_PATH
199-
cd tests/end-to-end
206+
script = inBrowserWorkspace ''
200207
npx playwright test "$@"
201208
'';
202209
};
203210

211+
reproduce = {
212+
description = "Run one Playwright fixture against SQLPage releases on one database, and print the results as a table";
213+
packages = cargoRuntime pkgs ++ [ pkgs.docker-compose ];
214+
env = cargoEnv pkgs // playwrightEnv pkgs;
215+
script = inBrowserWorkspace ''
216+
./reproduce.sh "$@"
217+
'';
218+
};
219+
204220
test-examples = {
205221
description = "Run the Hurl suite of an example against its own containers";
206222
packages = [ pkgs.hurl ];

‎tests/end-to-end/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "index.js",
77
"scripts": {
88
"test": "playwright test --reporter=line",
9-
"gui": "playwright test --ui"
9+
"gui": "playwright test --ui",
10+
"reproduce": "./reproduce.sh"
1011
},
1112
"keywords": [],
1213
"author": "",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "@playwright/test";
2+
import base from "./playwright.config.ts";
3+
4+
export default defineConfig({
5+
...base,
6+
projects: base.projects?.filter((project) => project.name === "fixtures"),
7+
webServer: [base.webServer]
8+
.flat()
9+
.flatMap((server) => (server?.name === "fixtures" ? [server] : [])),
10+
});

‎tests/end-to-end/reproduce.sh‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
usage="Usage: reproduce <fixture> <sqlite|postgres> <release tag or tree>..."
5+
fixture=${1:?$usage}
6+
database=${2:?$usage}
7+
shift 2
8+
if [ $# -eq 0 ]; then
9+
echo "$usage" >&2
10+
exit 2
11+
fi
12+
13+
case $database in
14+
sqlite) ;;
15+
postgres)
16+
docker compose --file ../../docker-compose.yml up --wait postgres
17+
export FIXTURES_DATABASE_URL='postgres://root:Password123!@127.0.0.1/sqlpage'
18+
;;
19+
*)
20+
echo "$usage" >&2
21+
exit 2
22+
;;
23+
esac
24+
25+
results=()
26+
for version in "$@"; do
27+
release=$version
28+
if [ "$version" = tree ]; then
29+
release=
30+
fi
31+
if SQLPAGE_RELEASE=$release npx playwright test --config reproduce.config.ts "fixtures/$fixture" --reporter=line; then
32+
results+=("| $version | ✔ passed |")
33+
else
34+
results+=("| $version | ✘ failed |")
35+
fi
36+
done
37+
38+
echo
39+
echo "| $fixture | $database |"
40+
echo "| --- | --- |"
41+
printf '%s\n' "${results[@]}"
42+
echo
43+
echo "On commit $(git rev-parse --short HEAD): \`nix run .#reproduce -- $fixture $database $*\`"

0 commit comments

Comments
 (0)