Skip to content

Commit 1cf49ea

Browse files
committed
[test] Add a regression test for af5fa03 .
1 parent 22d412a commit 1cf49ea

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

.github/workflows/CI.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
- run: make build-bin
8787
- run: make test-dist-bin
8888
- run: make build-sites
89-
- run: make test-dist-sites-experiments
89+
- run: make test-dist-sites-twizzle
9090
- run: make clean
9191

9292
test-make-test-fast:

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ test-dist-lib: \
200200
test-dist-lib-perf \
201201
test-dist-lib-plain-esbuild-compat \
202202
test-dist-lib-build-size \
203-
test-dist-sites-experiments # keep CI.yml in sync with this
203+
test-dist-sites-twizzle # keep CI.yml in sync with this
204204

205205
.PHONY: test-dist-lib-node-import
206206
test-dist-lib-node-import: build-lib-js
@@ -226,9 +226,9 @@ test-dist-lib-plain-esbuild-compat: build-lib-js
226226
test-dist-lib-build-size: build-lib-js
227227
${BUN_RUN} ./script/test/dist/lib/cubing/build-size/main.ts
228228

229-
.PHONY: test-dist-sites-experiments
230-
test-dist-sites-experiments: playwright-install build-sites
231-
${BUN} ./script/test/dist/sites/experiments.cubing.net/main.js
229+
.PHONY: test-dist-sites-twizzle
230+
test-dist-sites-twizzle: playwright-install build-sites
231+
${NODE} ./script/test/dist/sites/alpha.twizzle.net/main.js
232232

233233
.PHONY: test-dist-bin
234234
test-dist-bin: test-dist-bin-shebang test-dist-bin-npm-exec

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"test-dist-lib-perf": "make test-dist-lib-perf",
138138
"test-dist-lib-plain-esbuild-compat": "make test-dist-lib-plain-esbuild-compat",
139139
"test-dist-lib-build-size": "make test-dist-lib-build-size",
140-
"test-dist-sites-experiments": "make test-dist-sites-experiments",
140+
"test-dist-sites-twizzle": "make test-dist-sites-twizzle",
141141
"test-dist-bin": "make test-dist-bin",
142142
"test-dist-bin-shebang": "make test-dist-bin-shebang",
143143
"test-dist-bin-npm-exec": "make test-dist-bin-npm-exec",

script/test/dist/sites/experiments.cubing.net/main.js renamed to script/test/dist/sites/alpha.twizzle.net/main.js

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import { env } from "node:process";
12
import { chromium } from "playwright";
23
import { startServer } from "../../../../lib/experiments-server/index.js";
34

4-
const OPEN_REPL = false; // Set to `true` for testing.
5-
const HEADLESS = !OPEN_REPL;
5+
const OPEN_REPL = env["OPEN_REPL_FOR_BROWSER_TESTS"] === "true"; // Set to `true` for testing.
6+
const HEADLESS = !OPEN_REPL; // TODO: doesn't work?
7+
8+
if (!OPEN_REPL) {
9+
console.error(`To test with a repl and browser, run:
10+
11+
env OPEN_REPL_FOR_BROWSER_TESTS=true make test-dist-sites-twizzle
12+
13+
`);
14+
}
615

716
let exitCode = 0;
817
function assert(description, expected, observed) {
@@ -52,13 +61,53 @@ async function runTest() {
5261
new URL(page.url()).searchParams.get("puzzle"),
5362
);
5463

64+
await page.goto("http://localhost:4443/alpha.twizzle.net/edit/?puzzle=clock");
65+
assert(
66+
"three.js initially loaded",
67+
"undefined",
68+
await page.evaluate(() => {
69+
return typeof globalThis.__THREE__;
70+
}),
71+
);
72+
await (await page.waitForSelector(".puzzle")).selectOption("3x3x3");
73+
74+
// TODO: this implementation is very manual, and therefor brittle to maintain.
75+
await (async () => {
76+
for (
77+
let waitMilliseconds = 1;
78+
waitMilliseconds < 5000;
79+
waitMilliseconds *= 2
80+
) {
81+
await new Promise((resolve) => setTimeout(resolve, waitMilliseconds));
82+
const typeof__THREE__ = await page.evaluate(() => {
83+
return typeof globalThis.__THREE__;
84+
});
85+
if (typeof__THREE__ === "string") {
86+
return;
87+
}
88+
}
89+
})();
90+
assert(
91+
"three.js loaded after switching to 3×3×3",
92+
"string",
93+
await page.evaluate(() => {
94+
return typeof globalThis.__THREE__;
95+
}),
96+
);
97+
5598
if (OPEN_REPL) {
5699
globalThis.page = page;
57100
(await import("node:repl")).start();
58101
} else {
59102
await browser.close();
60103
process.exit(exitCode);
61104
}
105+
106+
// await page.screenshot({
107+
// path: "out.png",
108+
// omitBackground: true,
109+
// fullPage: true,
110+
// });
62111
}
63112

64113
startServer();

0 commit comments

Comments
 (0)