Debian Codegraph @

wasm/browser/tests/selenium_runner.js

raw
1 import fs from "fs";
2 import { spawn } from "child_process";
3 import MochaWebdriverRunner from "mocha-webdriver-runner";
4 const { runMochaWebDriverTest } = MochaWebdriverRunner;
5
6 const httpServerPs = spawn(`node tests/server.cjs`, {
7 shell: true,
8 env: { ...process.env, PORT: "8081" },
9 });
10
11 const webDriverCapabilities = {
12 browserName: "chrome",
13 "goog:chromeOptions": {
14 args: [
15 "--no-sandbox",
16 "--headless",
17 // https://stackoverflow.com/a/50642913/3714556
18 "--disable-dev-shm-usage",
19 "--auto-select-desktop-capture-source",
20 "--disable-gesture-requirement-for-media-playback",
21 "--autoplay-policy=no-user-gesture-required",
22 "--disable-cache",
23 ],
24 },
25 };
26
27 const CI_BIN = process.env["CHROME_BIN"];
28 if (CI_BIN && fs.existsSync(CI_BIN)) {
29 webDriverCapabilities["goog:chromeOptions"]["binary"] = CI_BIN;
30 }
31
32 (async function () {
33 let result;
34 await new Promise((resolve) => setTimeout(resolve, 1000));
35 try {
36 result = await runMochaWebDriverTest(
37 webDriverCapabilities,
38 "http://localhost:8081/index.html?ci=true",
39 {
40 reporter: "mocha-junit-reporter",
41 reporterOptions: {
42 mochaFile: "tests/results.junit.xml",
43 useFullSuiteTitle: true,
44 rootSuiteTitle: undefined,
45 outputs: true,
46 },
47 captureConsoleLog: true,
48 },
49 );
50 } catch (error) {
51 console.error(error);
52 process.exit(-1);
53 }
54
55 httpServerPs.kill();
56 if (result && result.success) {
57 process.exit(0);
58 } else {
59 console.error(JSON.stringify(result || {}, null, 2));
60 process.exit(0);
61 }
62 })();