bt-runner 2.1.0 → 3.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.
Files changed (81) hide show
  1. package/dist/IRunner.js +2 -0
  2. package/dist/generate.js +62 -0
  3. package/dist/generator.js +33 -32
  4. package/dist/getPort.js +20 -0
  5. package/dist/index.js +58 -18
  6. package/dist/index_custom.js +100 -0
  7. package/dist/index_debug.js +8 -3
  8. package/dist/server.js +1 -1
  9. package/package.json +3 -6
  10. package/tmp/{browsertests-71yT6w → browsertests-9PMQFx}/index1.html +2 -2
  11. package/tmp/browsertests-9PMQFx/index2.html +25 -0
  12. package/tmp/{browsertests-nIABth → browsertests-CRhBRJ}/index1.html +2 -2
  13. package/tmp/browsertests-CRhBRJ/index2.html +25 -0
  14. package/tmp/{browsertests-nIABth/mocha1.test.js → browsertests-CRhBRJ/mocha.test.js} +54 -9
  15. package/tmp/{browsertests-sBNC3W → browsertests-CRhBRJ}/nightwatch.json +1 -1
  16. package/tmp/{browsertests-3rqPiu → browsertests-Ef8QDb}/index1.html +2 -4
  17. package/tmp/browsertests-Ef8QDb/index2.html +25 -0
  18. package/tmp/{browsertests-71yT6w/mocha1.test.js → browsertests-Ef8QDb/mocha.test.js} +54 -10
  19. package/tmp/{browsertests-71yT6w → browsertests-Ef8QDb}/nightwatch.json +1 -1
  20. package/tmp/{browsertests-sBNC3W → browsertests-FNrySD}/index1.html +2 -13
  21. package/tmp/browsertests-FNrySD/index2.html +25 -0
  22. package/tmp/browsertests-FNrySD/mocha.test.js +100 -0
  23. package/tmp/browsertests-FNrySD/nightwatch.json +1 -0
  24. package/tmp/browsertests-HnV7W1/index1.html +25 -0
  25. package/tmp/browsertests-HnV7W1/index2.html +25 -0
  26. package/tmp/browsertests-HnV7W1/mocha.test.js +100 -0
  27. package/tmp/browsertests-HnV7W1/nightwatch.json +1 -0
  28. package/tmp/browsertests-Kr11Ep/index1.html +25 -0
  29. package/tmp/browsertests-Kr11Ep/index2.html +25 -0
  30. package/tmp/browsertests-Kr11Ep/mocha.test.js +100 -0
  31. package/tmp/browsertests-Kr11Ep/nightwatch.json +1 -0
  32. package/tmp/browsertests-QTo9jV/index1.html +25 -0
  33. package/tmp/browsertests-QTo9jV/index2.html +25 -0
  34. package/tmp/browsertests-QTo9jV/mocha.test.js +100 -0
  35. package/tmp/browsertests-QTo9jV/nightwatch.json +1 -0
  36. package/tmp/browsertests-VXReLQ/index1.html +25 -0
  37. package/tmp/browsertests-VXReLQ/index2.html +25 -0
  38. package/tmp/browsertests-VXReLQ/mocha.test.js +100 -0
  39. package/tmp/browsertests-VXReLQ/nightwatch.json +1 -0
  40. package/tmp/browsertests-dat86a/index1.html +25 -0
  41. package/tmp/browsertests-dat86a/index2.html +25 -0
  42. package/tmp/browsertests-dat86a/mocha.test.js +94 -0
  43. package/tmp/browsertests-dat86a/nightwatch.json +1 -0
  44. package/tmp/browsertests-eI4Px3/index1.html +25 -0
  45. package/tmp/browsertests-eI4Px3/index2.html +25 -0
  46. package/tmp/browsertests-eI4Px3/mocha.test.js +100 -0
  47. package/tmp/browsertests-eI4Px3/nightwatch.json +1 -0
  48. package/tmp/browsertests-eQY4O5/index1.html +25 -0
  49. package/tmp/browsertests-eQY4O5/index2.html +25 -0
  50. package/tmp/browsertests-eQY4O5/mocha.test.js +100 -0
  51. package/tmp/browsertests-eQY4O5/nightwatch.json +1 -0
  52. package/tmp/browsertests-gOUWdm/index1.html +25 -0
  53. package/tmp/browsertests-gOUWdm/index2.html +25 -0
  54. package/tmp/browsertests-gOUWdm/mocha.test.js +100 -0
  55. package/tmp/browsertests-gOUWdm/nightwatch.json +1 -0
  56. package/tmp/browsertests-jhoSdz/index1.html +25 -0
  57. package/tmp/browsertests-jhoSdz/index2.html +25 -0
  58. package/tmp/browsertests-jhoSdz/mocha.test.js +100 -0
  59. package/tmp/browsertests-jhoSdz/nightwatch.json +1 -0
  60. package/tmp/browsertests-koaNEn/index1.html +25 -0
  61. package/tmp/browsertests-koaNEn/index2.html +25 -0
  62. package/tmp/browsertests-koaNEn/mocha.test.js +100 -0
  63. package/tmp/browsertests-koaNEn/nightwatch.json +1 -0
  64. package/tmp/browsertests-ngYMnq/index1.html +25 -0
  65. package/tmp/browsertests-ngYMnq/index2.html +25 -0
  66. package/tmp/browsertests-ngYMnq/mocha.test.js +100 -0
  67. package/tmp/browsertests-ngYMnq/nightwatch.json +1 -0
  68. package/tmp/browsertests-oAq8xk/index1.html +25 -0
  69. package/tmp/browsertests-oAq8xk/index2.html +25 -0
  70. package/tmp/browsertests-oAq8xk/mocha.test.js +100 -0
  71. package/tmp/browsertests-oAq8xk/nightwatch.json +1 -0
  72. package/tmp/browsertests-q1rpZj/index1.html +25 -0
  73. package/tmp/browsertests-q1rpZj/index2.html +25 -0
  74. package/tmp/browsertests-q1rpZj/mocha.test.js +100 -0
  75. package/tmp/browsertests-q1rpZj/nightwatch.json +1 -0
  76. package/tmp/browsertests-zYgHlc/index1.html +25 -0
  77. package/tmp/browsertests-zYgHlc/index2.html +25 -0
  78. package/tmp/browsertests-zYgHlc/mocha.test.js +100 -0
  79. package/tmp/browsertests-zYgHlc/nightwatch.json +1 -0
  80. package/tmp/browsertests-nIABth/nightwatch.json +0 -1
  81. package/tmp/browsertests-sBNC3W/mocha1.test.js +0 -69
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const fs = __importStar(require("fs"));
27
+ const path = __importStar(require("path"));
28
+ function generate(runners, additionalScripts) {
29
+ const outputPath = fs.mkdtempSync(path.join(__dirname, "..", "tmp", "browsertests-"));
30
+ runners.forEach((runner, index) => {
31
+ writeHtml(outputPath, index + 1, runner.dependencies, additionalScripts);
32
+ });
33
+ return outputPath;
34
+ }
35
+ exports.default = generate;
36
+ function writeHtml(outputPath, runnerNumber, dependencies, additionalScripts) {
37
+ const html = `<!DOCTYPE html>
38
+ <html>
39
+ <head>
40
+ <title>Mocha Tests</title>
41
+ </head>
42
+
43
+ <body>
44
+ <div id="mocha"></div>
45
+
46
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/10.0.0/mocha.min.js"></script>
47
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.3.6/chai.min.js"></script>
48
+ <script>
49
+ mocha.setup("bdd")
50
+ mocha.reporter("spec")
51
+ </script>
52
+ <script>
53
+ ${additionalScripts ? additionalScripts.join("\n") : ""}
54
+ </script>
55
+
56
+ ${dependencies.map((dependency) => ` <script src="/test/${dependency}"></script>`).join("\n")}
57
+
58
+ <div id="main">Test</div>
59
+ </body>
60
+ </html>`;
61
+ fs.writeFileSync(path.join(outputPath, `index${runnerNumber}.html`), html);
62
+ }
package/dist/generator.js CHANGED
@@ -28,24 +28,17 @@ const fs = __importStar(require("fs"));
28
28
  const path = __importStar(require("path"));
29
29
  function generate(runners, additionalScripts, debug = false, port) {
30
30
  const outputPath = fs.mkdtempSync(path.join(__dirname, "..", "tmp", "browsertests-"));
31
- let it = 1;
32
- for (const runner of runners) {
33
- writeHtml(outputPath, it, runner.dependencies, additionalScripts);
34
- if (!debug) {
35
- if (!runner.globals) {
36
- runner.globals = [];
37
- }
38
- writeTestFile(outputPath, it, runner.globals);
39
- }
40
- it++;
41
- }
31
+ runners.forEach((runner, index) => {
32
+ writeHtml(outputPath, index + 1, runner.dependencies, additionalScripts);
33
+ });
42
34
  if (!debug) {
43
35
  writeConfig(outputPath, port);
36
+ writeSingleTestFile(outputPath, runners);
44
37
  }
45
38
  return outputPath;
46
39
  }
47
40
  exports.generate = generate;
48
- function writeHtml(outputPath, iteration, dependencies, additionalScripts) {
41
+ function writeHtml(outputPath, runnerNumber, dependencies, additionalScripts) {
49
42
  const html = `<!DOCTYPE html>
50
43
  <html>
51
44
  <head>
@@ -55,8 +48,8 @@ function writeHtml(outputPath, iteration, dependencies, additionalScripts) {
55
48
  <body>
56
49
  <div id="mocha"></div>
57
50
 
58
- <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.2.0/mocha.min.js"></script>
59
- <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
51
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/10.0.0/mocha.min.js"></script>
52
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.3.6/chai.min.js"></script>
60
53
  <script>
61
54
  mocha.setup("bdd")
62
55
  mocha.reporter("spec")
@@ -70,21 +63,19 @@ function writeHtml(outputPath, iteration, dependencies, additionalScripts) {
70
63
  <div id="main">Test</div>
71
64
  </body>
72
65
  </html>`;
73
- fs.writeFileSync(path.join(outputPath, `index${iteration}.html`), html);
66
+ fs.writeFileSync(path.join(outputPath, `index${runnerNumber}.html`), html);
74
67
  }
75
- function writeTestFile(outputPath, iteration, globals) {
76
- const globalsString = globals
77
- .map((glob) => `if (!window.${glob}) {
78
- console.log("Required library '${glob}' not loaded. Aborting...")
79
- done({ failures: 1 })
80
- return
81
- }`)
82
- .join("\n");
68
+ function writeSingleTestFile(outputPath, runners) {
69
+ const tests = runners.map((runner, iteration) => runnerToTest(runner, iteration + 1));
83
70
  const testContent = `const expect = require("chai").expect
84
71
 
85
72
  describe("Browser Mocha Tests", function () {
86
- beforeEach((client, done) => {
87
- client.url("http://localhost:7777/test-browser/index${iteration}.html")
73
+ before((client, done) => {
74
+ client.captureBrowserConsoleLogs((event) => {
75
+ const args = event.args.map((arg) => arg.value)
76
+ console.log.apply(console, args)
77
+ })
78
+
88
79
  done()
89
80
  })
90
81
 
@@ -92,11 +83,22 @@ function writeTestFile(outputPath, iteration, globals) {
92
83
  client.end(() => done())
93
84
  })
94
85
 
95
- it("Should run the Mocha tests without error", async (client) => {
96
- client.captureBrowserConsoleLogs((event) => {
97
- const args = event.args.map((arg) => arg.value)
98
- console.log.apply(console, args)
99
- })
86
+ ${tests.join("\n\n")}
87
+ })`;
88
+ fs.writeFileSync(path.join(outputPath, `mocha.test.js`), testContent);
89
+ }
90
+ function runnerToTest(runner, runnerNumber) {
91
+ const globals = runner.globals ?? [];
92
+ const globalsString = globals
93
+ .map((glob) => `if (!window.${glob}) {
94
+ console.log("Required library '${glob}' not loaded. Aborting...")
95
+ done({ failures: 1 })
96
+ return
97
+ }`)
98
+ .join("\n");
99
+ return `
100
+ it("Should run the Mocha tests without error (runner ${runnerNumber})", async (client) => {
101
+ client.url("http://localhost:7777/test-browser/index${runnerNumber}.html")
100
102
 
101
103
  client.waitForElementVisible("#main")
102
104
 
@@ -125,8 +127,7 @@ function writeTestFile(outputPath, iteration, globals) {
125
127
  expect(result.value).to.not.be.undefined
126
128
  expect(result.value.failures).to.equal(0)
127
129
  })
128
- })`;
129
- fs.writeFileSync(path.join(outputPath, `mocha${iteration}.test.js`), testContent);
130
+ `;
130
131
  }
131
132
  function requireGlobal(packageName) {
132
133
  var childProcess = require("child_process");
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const net_1 = __importDefault(require("net"));
7
+ async function default_1(options) {
8
+ return await new Promise((resolve, reject) => {
9
+ const server = net_1.default.createServer();
10
+ server.unref();
11
+ server.on("error", reject);
12
+ server.listen({ ...options, port: 0 }, () => {
13
+ const { port } = server.address();
14
+ server.close(() => {
15
+ resolve(port);
16
+ });
17
+ });
18
+ });
19
+ }
20
+ exports.default = default_1;
package/dist/index.js CHANGED
@@ -28,13 +28,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  const child_process = __importStar(require("child_process"));
31
- const Nightwatch = __importStar(require("nightwatch"));
32
31
  const path = __importStar(require("path"));
32
+ const puppeteer_1 = __importDefault(require("puppeteer"));
33
33
  const helpers_1 = require("yargs/helpers");
34
34
  const yargs_1 = __importDefault(require("yargs/yargs"));
35
- const generator = __importStar(require("./generator"));
35
+ const generate_1 = __importDefault(require("./generate"));
36
+ const getPort_1 = __importDefault(require("./getPort"));
36
37
  const rimraf = require("rimraf");
37
- Nightwatch.cli(async function (argv) {
38
+ async function run() {
39
+ const port = await (0, getPort_1.default)();
38
40
  const args = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
39
41
  .option("config", {
40
42
  alias: "c",
@@ -49,26 +51,64 @@ Nightwatch.cli(async function (argv) {
49
51
  default: 9515
50
52
  }).argv;
51
53
  const nbt = require(path.join(process.cwd(), args.config));
52
- const tempFolder = generator.generate(nbt.runners, nbt.additionalScripts, false, args.port);
54
+ const tempFolder = (0, generate_1.default)(nbt.runners, nbt.additionalScripts);
53
55
  const testFolder = path.resolve(nbt.testFolder);
54
- var httpServerProc = child_process.spawn("node", [`${__dirname}/server.js`, tempFolder, testFolder], {
55
- stdio: "inherit"
56
+ const httpServerProc = child_process.spawn("node", [`${__dirname}/../dist/server.js`, tempFolder, testFolder], {
57
+ stdio: "inherit",
58
+ env: { PORT: port.toString() }
56
59
  });
57
- argv.config = path.join(tempFolder, "nightwatch.json");
58
- const runner = Nightwatch.CliRunner(argv);
60
+ let exitCode = 0;
59
61
  try {
60
- await runner.setup({});
61
- await runner.runTests();
62
+ const success = await runTests(port, nbt.runners);
63
+ if (!success)
64
+ exitCode = 1;
62
65
  }
63
- catch (err) {
64
- console.error("An error occurred:", err);
66
+ catch (e) {
67
+ console.error(e);
68
+ exitCode = 1;
65
69
  }
66
70
  finally {
67
- cleanup(httpServerProc, tempFolder);
71
+ httpServerProc.kill("SIGINT");
72
+ rimraf.sync(tempFolder);
68
73
  }
69
- });
70
- function cleanup(httpServerProc, tempFolder) {
71
- httpServerProc.kill("SIGINT");
72
- rimraf.sync(tempFolder);
73
- process.exit(0);
74
+ process.exit(exitCode);
75
+ }
76
+ async function runTests(serverPort, testRunners) {
77
+ const browser = await puppeteer_1.default.launch({
78
+ headless: true,
79
+ args: ["--disable-gpu", "--disable-dev-shm-usage", "--disable-setuid-sandbox", "--no-sandbox"]
80
+ });
81
+ const page = await browser.newPage();
82
+ page.on("console", (message) => {
83
+ console.log.apply(console, message.args().map((arg) => arg.remoteObject().value));
84
+ });
85
+ for (let i = 0; i < testRunners.length; i++) {
86
+ const runner = testRunners[i];
87
+ const runnerNumber = i + 1;
88
+ console.log(`Running test runner ${runnerNumber}`);
89
+ await page.goto(`http://localhost:${serverPort}/test-browser/index${runnerNumber}.html`);
90
+ const globals = runner.globals ?? [];
91
+ globals.push("mocha");
92
+ const result = await page.evaluate(async (globals) => {
93
+ for (const glob of globals) {
94
+ if (typeof window[glob] === "undefined") {
95
+ console.log(`Required library '${glob}' not loaded. Aborting...`);
96
+ return { failures: 1 };
97
+ }
98
+ }
99
+ return new Promise((resolve) => window.mocha.run(function (failures) {
100
+ resolve({ failures: failures });
101
+ }));
102
+ }, runner.globals ?? []);
103
+ if (result.failures != 0) {
104
+ await browser.close();
105
+ return false;
106
+ }
107
+ console.log();
108
+ console.log();
109
+ }
110
+ await browser.close();
111
+ return true;
74
112
  }
113
+ function cleanup(httpServerProc, tempFolder) { }
114
+ run();
@@ -0,0 +1,100 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ const child_process = __importStar(require("child_process"));
31
+ const path = __importStar(require("path"));
32
+ const puppeteer_1 = __importDefault(require("puppeteer"));
33
+ const helpers_1 = require("yargs/helpers");
34
+ const yargs_1 = __importDefault(require("yargs/yargs"));
35
+ const generator = __importStar(require("./generator"));
36
+ const rimraf = require("rimraf");
37
+ function cleanup(httpServerProc, tempFolder) {
38
+ httpServerProc.kill("SIGINT");
39
+ rimraf.sync(tempFolder);
40
+ process.exit(0);
41
+ }
42
+ async function run() {
43
+ const args = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
44
+ .option("config", {
45
+ alias: "c",
46
+ type: "string",
47
+ description: "select a config file",
48
+ default: "nbt.json"
49
+ })
50
+ .option("port", {
51
+ alias: "p",
52
+ type: "number",
53
+ description: "select a port",
54
+ default: 9515
55
+ }).argv;
56
+ const nbt = require(path.join(process.cwd(), args.config));
57
+ const tempFolder = generator.generate(nbt.runners, nbt.additionalScripts, false, args.port);
58
+ const testFolder = path.resolve(nbt.testFolder);
59
+ var httpServerProc = child_process.spawn("node", [`${__dirname}/server.js`, tempFolder, testFolder], {
60
+ stdio: "inherit"
61
+ });
62
+ const browser = await puppeteer_1.default.launch({ headless: false });
63
+ const page = await browser.newPage();
64
+ page.on("console", (message) => {
65
+ console.log.apply(console, message.args().map((arg) => arg.remoteObject().value));
66
+ });
67
+ const runners = nbt.runners;
68
+ let runnerNumber = 1;
69
+ for (const runner of runners) {
70
+ await page.goto(`http://localhost:7777/test-browser/index${runnerNumber}.html`);
71
+ runner.dependencies.push("mocha");
72
+ const result = await page.evaluate(async (dependencies) => {
73
+ for (const dep of dependencies) {
74
+ // @ts-ignore
75
+ console.log(window.mocha.asd);
76
+ if (!window[dep]) {
77
+ console.log(`Required library '${dep}' not loaded. Aborting...`);
78
+ return { failures: 1 };
79
+ }
80
+ }
81
+ return new Promise((resolve) => window.mocha.run(function (failures) {
82
+ resolve({ failures: failures });
83
+ }));
84
+ }, runner.dependencies);
85
+ // a variable containing a sleep function
86
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
87
+ // await sleep(100000)
88
+ if (result.failures != 0) {
89
+ await browser.close();
90
+ cleanup(httpServerProc, tempFolder);
91
+ process.exit(1);
92
+ }
93
+ runnerNumber++;
94
+ }
95
+ await browser.close();
96
+ cleanup(httpServerProc, tempFolder);
97
+ }
98
+ run().then(() => {
99
+ process.exit(0);
100
+ });
@@ -30,10 +30,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  const express_1 = __importDefault(require("express"));
31
31
  const express_http_proxy_1 = __importDefault(require("express-http-proxy"));
32
32
  const path = __importStar(require("path"));
33
- const generator = __importStar(require("./generator"));
33
+ const generate_1 = __importDefault(require("./generate"));
34
34
  const app = (0, express_1.default)();
35
35
  const nbt = require(path.join(process.cwd(), "nbt.json"));
36
- const outputPath = generator.generate(nbt.runners, nbt.additionalScripts, true, 9515);
36
+ const outputPath = (0, generate_1.default)(nbt.runners, nbt.additionalScripts);
37
37
  app.use("/test-browser", express_1.default.static(outputPath));
38
38
  app.use("/test", express_1.default.static(path.resolve(nbt.testFolder)));
39
39
  if (nbt.proxies) {
@@ -41,5 +41,10 @@ if (nbt.proxies) {
41
41
  app.use(proxy.local, (0, express_http_proxy_1.default)(proxy.remote));
42
42
  }
43
43
  }
44
- console.log("Server Started. Open at http://localhost:7777/test-browser/index1.html.");
44
+ const urls = nbt.runners
45
+ .map((_runner, index) => `- http://localhost:7777/test-browser/index${index + 1}.html`)
46
+ .join("\n");
47
+ console.log(`Server Started. Open under the following URL's
48
+ ${urls}
49
+ and type "mocha.run()" in the debug console to run the tests.`);
45
50
  app.listen(7777, () => { });
package/dist/server.js CHANGED
@@ -15,4 +15,4 @@ if (config && config.proxies) {
15
15
  app.use(proxy.local, httpproxy(proxy.remote));
16
16
  }
17
17
  }
18
- app.listen(7777, () => { });
18
+ app.listen(process.env["PORT"] ?? 7777, () => { });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-runner",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,23 +21,20 @@
21
21
  "prepublishOnly": "tsc"
22
22
  },
23
23
  "dependencies": {
24
- "chai": "^4.3.6",
25
24
  "express": "^4.18.1",
26
25
  "express-http-proxy": "^1.6.3",
27
- "mocha": "^10.0.0",
28
- "nightwatch": "^2.3.3",
26
+ "puppeteer": "^16.2.0",
29
27
  "rimraf": "^3.0.2",
30
28
  "yargs": "^17.5.1"
31
29
  },
32
30
  "devDependencies": {
33
31
  "@types/express": "^4.17.13",
34
32
  "@types/express-http-proxy": "^1.6.3",
35
- "@types/express-serve-static-core": "^4.17.30",
36
33
  "@types/node": "^18.7.11",
37
34
  "@types/rimraf": "^3.0.2",
38
35
  "@types/yargs": "^17.0.11"
39
36
  },
40
37
  "publishConfig": {
41
- "registry": "https://registry.npmjs.org"
38
+ "access": "public"
42
39
  }
43
40
  }
@@ -7,8 +7,8 @@
7
7
  <body>
8
8
  <div id="mocha"></div>
9
9
 
10
- <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.2.0/mocha.min.js"></script>
11
- <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/10.0.0/mocha.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.3.6/chai.min.js"></script>
12
12
  <script>
13
13
  mocha.setup("bdd")
14
14
  mocha.reporter("spec")
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Mocha Tests</title>
5
+ </head>
6
+
7
+ <body>
8
+ <div id="mocha"></div>
9
+
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/10.0.0/mocha.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.3.6/chai.min.js"></script>
12
+ <script>
13
+ mocha.setup("bdd")
14
+ mocha.reporter("spec")
15
+ </script>
16
+ <script>
17
+ window.TEST = {}
18
+ window.TEST2 = {}
19
+ </script>
20
+
21
+ <script src="/test/test.js"></script>
22
+
23
+ <div id="main">Test</div>
24
+ </body>
25
+ </html>
@@ -7,8 +7,8 @@
7
7
  <body>
8
8
  <div id="mocha"></div>
9
9
 
10
- <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.2.0/mocha.min.js"></script>
11
- <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/10.0.0/mocha.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.3.6/chai.min.js"></script>
12
12
  <script>
13
13
  mocha.setup("bdd")
14
14
  mocha.reporter("spec")
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Mocha Tests</title>
5
+ </head>
6
+
7
+ <body>
8
+ <div id="mocha"></div>
9
+
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/10.0.0/mocha.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.3.6/chai.min.js"></script>
12
+ <script>
13
+ mocha.setup("bdd")
14
+ mocha.reporter("spec")
15
+ </script>
16
+ <script>
17
+ window.TEST = {}
18
+ window.TEST2 = {}
19
+ </script>
20
+
21
+ <script src="/test/test.js"></script>
22
+
23
+ <div id="main">Test</div>
24
+ </body>
25
+ </html>
@@ -1,8 +1,12 @@
1
1
  const expect = require("chai").expect
2
2
 
3
3
  describe("Browser Mocha Tests", function () {
4
- beforeEach((client, done) => {
5
- client.url("http://localhost:7777/test-browser/index1.html")
4
+ before((client, done) => {
5
+ client.captureBrowserConsoleLogs((event) => {
6
+ const args = event.args.map((arg) => arg.value)
7
+ console.log.apply(console, args)
8
+ })
9
+
6
10
  done()
7
11
  })
8
12
 
@@ -10,11 +14,51 @@ const expect = require("chai").expect
10
14
  client.end(() => done())
11
15
  })
12
16
 
13
- it("Should run the Mocha tests without error", async (client) => {
14
- client.captureBrowserConsoleLogs((event) => {
15
- const args = event.args.map((arg) => arg.value)
16
- console.log.apply(console, args)
17
- })
17
+
18
+ it("Should run the Mocha tests without error (runner 1)", async (client) => {
19
+ client.url("http://localhost:7777/test-browser/index1.html")
20
+
21
+ client.waitForElementVisible("#main")
22
+
23
+ const executeFunction = (done) => {
24
+ const mocha = window.mocha
25
+
26
+ //add required test librarys in this if statement
27
+ if (!mocha) {
28
+ console.log("Required library 'mocha' not loaded. Aborting...")
29
+ done({ failures: 1 })
30
+ return
31
+ }
32
+
33
+ if (!window.TEST) {
34
+ console.log("Required library 'TEST' not loaded. Aborting...")
35
+ done({ failures: 1 })
36
+ return
37
+ }
38
+ if (!window.TEST2) {
39
+ console.log("Required library 'TEST2' not loaded. Aborting...")
40
+ done({ failures: 1 })
41
+ return
42
+ }
43
+
44
+ mocha.run(function (failures) {
45
+ done({ failures: failures })
46
+ })
47
+ }
48
+
49
+ const result = await new Promise(resolve => client.timeoutsAsyncScript(1500000).executeAsyncScript(
50
+ executeFunction,
51
+ (result) => resolve(result)
52
+ ))
53
+
54
+ expect(result.value).to.not.be.undefined
55
+ expect(result.value.failures).to.equal(0)
56
+ })
57
+
58
+
59
+
60
+ it("Should run the Mocha tests without error (runner 2)", async (client) => {
61
+ client.url("http://localhost:7777/test-browser/index2.html")
18
62
 
19
63
  client.waitForElementVisible("#main")
20
64
 
@@ -30,12 +74,12 @@ const expect = require("chai").expect
30
74
 
31
75
  if (!window.TEST) {
32
76
  console.log("Required library 'TEST' not loaded. Aborting...")
33
- localDone({ failures: 1 })
77
+ done({ failures: 1 })
34
78
  return
35
79
  }
36
80
  if (!window.TEST2) {
37
81
  console.log("Required library 'TEST2' not loaded. Aborting...")
38
- localDone({ failures: 1 })
82
+ done({ failures: 1 })
39
83
  return
40
84
  }
41
85
 
@@ -52,4 +96,5 @@ if (!window.TEST2) {
52
96
  expect(result.value).to.not.be.undefined
53
97
  expect(result.value.failures).to.equal(0)
54
98
  })
99
+
55
100
  })
@@ -1 +1 @@
1
- {"src_folders":["/home/julian/git/jss/docker-node-browsertests/test-runner/tmp/browsertests-sBNC3W"],"filter":"*.test.js","webdriver":{"start_process":true,"server_path":"/home/julian/.local/lib/node_modules/chromedriver/lib/chromedriver/chromedriver","port":9515,"timeout_options":{"timeout":1500000}},"test_runner":{"type":"mocha","options":{"ui":"bdd","reporter":"spec"}},"test_settings":{"default":{"request_timeout_options":{"timeout":1500000},"desiredCapabilities":{"javascriptEnabled":true,"acceptSslCerts":true,"acceptInsecureCerts":true,"browserName":"chrome","goog:chromeOptions":{"w3c":true,"args":["--headless","--disable-gpu","--ignore-certificate-errors","--no-sandbox","--disable-features=NetworkService"],"binary":"/usr/bin/google-chrome"}}}},"globals":{"waitForConditionTimeout":100000,"asyncHookTimeout":1500000,"unitTestsTimeout":100000,"customReporterCallbackTimeout":100000,"retryAssertionTimeout":50000}}
1
+ {"src_folders":["/home/julian/git/jss/docker-node-browsertests/test-runner/tmp/browsertests-CRhBRJ"],"filter":"*.test.js","webdriver":{"start_process":true,"server_path":"/home/julian/.local/lib/node_modules/chromedriver/lib/chromedriver/chromedriver","port":9515,"timeout_options":{"timeout":1500000}},"test_runner":{"type":"mocha","options":{"ui":"bdd","reporter":"spec"}},"test_settings":{"default":{"request_timeout_options":{"timeout":1500000},"desiredCapabilities":{"javascriptEnabled":true,"acceptSslCerts":true,"acceptInsecureCerts":true,"browserName":"chrome","goog:chromeOptions":{"w3c":true,"args":["--headless","--disable-gpu","--ignore-certificate-errors","--no-sandbox","--disable-features=NetworkService"],"binary":"/usr/bin/google-chrome"}}}},"globals":{"waitForConditionTimeout":100000,"asyncHookTimeout":1500000,"unitTestsTimeout":100000,"customReporterCallbackTimeout":100000,"retryAssertionTimeout":50000}}
@@ -6,11 +6,9 @@
6
6
 
7
7
  <body>
8
8
  <div id="mocha"></div>
9
-
10
-
11
9
 
12
- <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.2.0/mocha.min.js"></script>
13
- <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/10.0.0/mocha.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.3.6/chai.min.js"></script>
14
12
  <script>
15
13
  mocha.setup("bdd")
16
14
  mocha.reporter("spec")