bt-runner 3.3.0 → 4.0.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/dist/index.js CHANGED
@@ -33,17 +33,24 @@ const yargs_1 = __importDefault(require("yargs/yargs"));
33
33
  const util_1 = require("./util");
34
34
  async function run() {
35
35
  const port = await (0, util_1.getPort)();
36
- const args = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)).option("config", {
36
+ const args = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
37
+ .option("config", {
37
38
  alias: "c",
38
39
  type: "string",
39
40
  description: "select a config file",
40
41
  default: "nbt.json"
42
+ })
43
+ .option("debug", {
44
+ alias: "d",
45
+ type: "boolean",
46
+ description: "run in debug mode",
47
+ default: false
41
48
  }).argv;
42
49
  const config = require(path.join(process.cwd(), args.config));
43
50
  const server = util_1.Server.create(config, port).start();
44
51
  let exitCode = 0;
45
52
  try {
46
- const success = await (0, util_1.runTests)(port, config.runners);
53
+ const success = await (0, util_1.runTests)(port, config.runners, args.debug);
47
54
  if (!success)
48
55
  exitCode = 1;
49
56
  }
@@ -59,12 +59,20 @@ class Server {
59
59
  return this;
60
60
  }
61
61
  transformProxy(proxy) {
62
- if ("remote" in proxy)
63
- return proxy;
64
- const remoteFromEnv = process.env[proxy.env];
65
- if (!remoteFromEnv)
66
- throw new Error(`No environment variable found for proxy: ${proxy.env}`);
67
- return { local: proxy.local, remote: remoteFromEnv };
62
+ let remote = proxy.remote;
63
+ const regex = /{{([a-z_]+)}}/i;
64
+ while (regex.test(remote)) {
65
+ const match = regex.exec(remote);
66
+ if (match) {
67
+ const envVar = match[1];
68
+ const envValue = process.env[envVar];
69
+ console.log(envValue);
70
+ if (!envValue)
71
+ throw new Error(`Environment variable ${envVar} is not defined`);
72
+ remote = remote.replace(match[0], envValue);
73
+ }
74
+ }
75
+ return { local: proxy.local, remote };
68
76
  }
69
77
  stop() {
70
78
  this.server?.close();
@@ -21,8 +21,6 @@ function generateHtml(dependencies, additionalScripts) {
21
21
  ${additionalScripts ? additionalScripts.join("\n") : ""}
22
22
  </script>
23
23
 
24
- ${dependencies.map((dependency) => ` <script src="/test/${dependency}"></script>`).join("\n")}
25
-
26
24
  <div id="main">Test</div>
27
25
  </body>
28
26
  </html>`;
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.runTests = void 0;
7
7
  const puppeteer_1 = __importDefault(require("puppeteer"));
8
- async function runTests(serverPort, testRunners) {
8
+ async function runTests(serverPort, testRunners, debug) {
9
9
  const browser = await puppeteer_1.default.launch({
10
- headless: true,
10
+ headless: !debug,
11
11
  args: ["--disable-gpu", "--disable-dev-shm-usage", "--disable-setuid-sandbox", "--no-sandbox"]
12
12
  });
13
13
  const page = await browser.newPage();
@@ -26,6 +26,9 @@ async function runTests(serverPort, testRunners) {
26
26
  globalThis.process.env = globalThis.process.env ?? {};
27
27
  globalThis.process.env = { ...globalThis.process.env, ...params };
28
28
  }, process.env);
29
+ for (const dependency of runner.dependencies) {
30
+ await page.addScriptTag({ url: `/test/${dependency}` });
31
+ }
29
32
  const globals = runner.globals ?? [];
30
33
  globals.push("mocha");
31
34
  const result = await page.evaluate(async (globals) => {
@@ -39,6 +42,10 @@ async function runTests(serverPort, testRunners) {
39
42
  resolve({ failures: failures });
40
43
  }));
41
44
  }, runner.globals ?? []);
45
+ if (debug) {
46
+ console.log("Press any key to continue...");
47
+ await new Promise((resolve) => process.stdin.once("data", resolve));
48
+ }
42
49
  if (result.failures != 0) {
43
50
  await browser.close();
44
51
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-runner",
3
- "version": "3.3.0",
3
+ "version": "4.0.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,8 +10,7 @@
10
10
  "author": "js-soft <julian.koenig@js-soft.com> (https://www.js-soft.com/)",
11
11
  "main": "index.js",
12
12
  "bin": {
13
- "browsertest-runner": "dist/index.js",
14
- "browsertest-runner-debug": "dist/index_debug.js"
13
+ "browsertest-runner": "dist/index.js"
15
14
  },
16
15
  "files": [
17
16
  "dist"
@@ -1,57 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- const path = __importStar(require("path"));
28
- const util_1 = require("./util");
29
- const port = 7777;
30
- const config = require(path.join(process.cwd(), "nbt.json"));
31
- const server = util_1.Server.create(config, port).start();
32
- const urls = config.runners
33
- .map((_runner, index) => `- http://localhost:7777/test-browser/index${index + 1}.html`)
34
- .join("\n");
35
- console.log(`Server Started. Open under the following URL's
36
- ${urls}
37
- and type "mocha.run()" in the debug console to run the tests.`);
38
- const signals = [
39
- "SIGHUP",
40
- "SIGINT",
41
- "SIGQUIT",
42
- "SIGILL",
43
- "SIGTRAP",
44
- "SIGABRT",
45
- "SIGBUS",
46
- "SIGFPE",
47
- "SIGUSR1",
48
- "SIGSEGV",
49
- "SIGUSR2",
50
- "SIGTERM"
51
- ];
52
- for (const signal of signals) {
53
- process.on(signal, () => {
54
- server.stop();
55
- process.exit(0);
56
- });
57
- }