@cevek/screentest 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -12
- package/dist/global-setup.js +15002 -73
- package/dist/index.js +257 -82
- package/dist/runner.js +12 -7
- package/dist/templates/Dockerfile.firefox-server +1 -1
- package/dist/templates/idle-proxy.mjs +88 -0
- package/dist/templates/launch-server.mjs +36 -11
- package/dist/web/assets/index-CQ8ij0HR.js +72 -0
- package/dist/web/assets/index-DWf2oQZg.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +2 -1
- package/dist/web/assets/index-BWHB66Bb.js +0 -72
- package/dist/web/assets/index-Bi-jx470.css +0 -1
|
@@ -1,22 +1,47 @@
|
|
|
1
1
|
// Long-lived headless Firefox browser-server. Tests on the host connect via
|
|
2
2
|
// WS, see playwright.dev/docs/api/class-browsertype#browser-type-launch-server
|
|
3
3
|
import { firefox } from 'playwright';
|
|
4
|
+
import { parseIdleSeconds, startIdleProxy } from './idle-proxy.mjs';
|
|
4
5
|
|
|
5
6
|
const port = Number.parseInt(process.env.SCREENTEST_PORT ?? '5180', 10);
|
|
6
7
|
const wsPath = process.env.SCREENTEST_WS_PATH ?? 'screentest-firefox';
|
|
8
|
+
const idleSeconds = parseIdleSeconds(process.env.SCREENTEST_DAEMON_IDLE_SECONDS);
|
|
9
|
+
// A Firefox that hangs on close must not leave a running container with no
|
|
10
|
+
// listener: ensureDaemon gives such a container READY_TIMEOUT_MS (daemon.ts)
|
|
11
|
+
// before failing instead of starting anew.
|
|
12
|
+
const FORCE_EXIT_MS = 5_000;
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
// Random loopback port: clients reach Firefox only through the counting proxy.
|
|
15
|
+
const server = await firefox.launchServer({ port: 0, host: '127.0.0.1', wsPath });
|
|
16
|
+
const upstreamPort = Number(new URL(server.wsEndpoint()).port);
|
|
17
|
+
|
|
18
|
+
let closing = false;
|
|
19
|
+
const shutdown = async (reason, code = 0) => {
|
|
20
|
+
if (closing) return;
|
|
21
|
+
closing = true;
|
|
22
|
+
console.log(`[screentest] ${reason}, closing browser-server`);
|
|
23
|
+
proxy.close();
|
|
24
|
+
setTimeout(() => process.exit(code), FORCE_EXIT_MS).unref();
|
|
25
|
+
await server.close().catch(() => {});
|
|
26
|
+
process.exit(code);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const proxy = await startIdleProxy({
|
|
10
30
|
host: '0.0.0.0',
|
|
11
|
-
|
|
31
|
+
port,
|
|
32
|
+
upstreamPort,
|
|
33
|
+
idleMs: idleSeconds * 1000,
|
|
34
|
+
onIdle: () => void shutdown(`no clients for ${idleSeconds}s`),
|
|
12
35
|
});
|
|
13
36
|
|
|
14
|
-
|
|
37
|
+
// Firefox died on its own: exit so `--rm` frees the name for a fresh daemon
|
|
38
|
+
// instead of a proxy that forwards to nothing.
|
|
39
|
+
server.on('close', () => void shutdown('browser-server closed unexpectedly', 1));
|
|
15
40
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
process.on('SIGTERM', () => void shutdown('SIGTERM'));
|
|
22
|
-
process.on('SIGINT', () => void shutdown('SIGINT'));
|
|
41
|
+
console.log(
|
|
42
|
+
`[screentest] firefox browser-server ready on port ${port}` +
|
|
43
|
+
(idleSeconds > 0 ? `, stops after ${idleSeconds}s without clients` : ''),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
process.on('SIGTERM', () => void shutdown('received SIGTERM'));
|
|
47
|
+
process.on('SIGINT', () => void shutdown('received SIGINT'));
|