bt-runner 2.0.6 → 3.0.1

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 (78) hide show
  1. package/dist/IRunner.js +2 -0
  2. package/dist/generate.js +62 -0
  3. package/dist/getPort.js +20 -0
  4. package/dist/index.js +58 -18
  5. package/dist/index_debug.js +8 -3
  6. package/dist/server.js +1 -1
  7. package/package.json +3 -6
  8. package/tmp/browsertests-9PMQFx/index1.html +25 -0
  9. package/tmp/browsertests-9PMQFx/index2.html +25 -0
  10. package/tmp/browsertests-CRhBRJ/index1.html +25 -0
  11. package/tmp/browsertests-CRhBRJ/index2.html +25 -0
  12. package/tmp/browsertests-CRhBRJ/mocha.test.js +100 -0
  13. package/tmp/browsertests-CRhBRJ/nightwatch.json +1 -0
  14. package/tmp/browsertests-Ef8QDb/index1.html +25 -0
  15. package/tmp/browsertests-Ef8QDb/index2.html +25 -0
  16. package/tmp/browsertests-Ef8QDb/mocha.test.js +100 -0
  17. package/tmp/browsertests-Ef8QDb/nightwatch.json +1 -0
  18. package/tmp/browsertests-FNrySD/index1.html +25 -0
  19. package/tmp/browsertests-FNrySD/index2.html +25 -0
  20. package/tmp/browsertests-FNrySD/mocha.test.js +100 -0
  21. package/tmp/browsertests-FNrySD/nightwatch.json +1 -0
  22. package/tmp/browsertests-HnV7W1/index1.html +25 -0
  23. package/tmp/browsertests-HnV7W1/index2.html +25 -0
  24. package/tmp/browsertests-HnV7W1/mocha.test.js +100 -0
  25. package/tmp/browsertests-HnV7W1/nightwatch.json +1 -0
  26. package/tmp/browsertests-Kr11Ep/index1.html +25 -0
  27. package/tmp/browsertests-Kr11Ep/index2.html +25 -0
  28. package/tmp/browsertests-Kr11Ep/mocha.test.js +100 -0
  29. package/tmp/browsertests-Kr11Ep/nightwatch.json +1 -0
  30. package/tmp/browsertests-QTo9jV/index1.html +25 -0
  31. package/tmp/browsertests-QTo9jV/index2.html +25 -0
  32. package/tmp/browsertests-QTo9jV/mocha.test.js +100 -0
  33. package/tmp/browsertests-QTo9jV/nightwatch.json +1 -0
  34. package/tmp/browsertests-VXReLQ/index1.html +25 -0
  35. package/tmp/browsertests-VXReLQ/index2.html +25 -0
  36. package/tmp/browsertests-VXReLQ/mocha.test.js +100 -0
  37. package/tmp/browsertests-VXReLQ/nightwatch.json +1 -0
  38. package/tmp/browsertests-dat86a/index1.html +25 -0
  39. package/tmp/browsertests-dat86a/index2.html +25 -0
  40. package/tmp/browsertests-dat86a/mocha.test.js +94 -0
  41. package/tmp/browsertests-dat86a/nightwatch.json +1 -0
  42. package/tmp/browsertests-eI4Px3/index1.html +25 -0
  43. package/tmp/browsertests-eI4Px3/index2.html +25 -0
  44. package/tmp/browsertests-eI4Px3/mocha.test.js +100 -0
  45. package/tmp/browsertests-eI4Px3/nightwatch.json +1 -0
  46. package/tmp/browsertests-eQY4O5/index1.html +25 -0
  47. package/tmp/browsertests-eQY4O5/index2.html +25 -0
  48. package/tmp/browsertests-eQY4O5/mocha.test.js +100 -0
  49. package/tmp/browsertests-eQY4O5/nightwatch.json +1 -0
  50. package/tmp/browsertests-gOUWdm/index1.html +25 -0
  51. package/tmp/browsertests-gOUWdm/index2.html +25 -0
  52. package/tmp/browsertests-gOUWdm/mocha.test.js +100 -0
  53. package/tmp/browsertests-gOUWdm/nightwatch.json +1 -0
  54. package/tmp/browsertests-jhoSdz/index1.html +25 -0
  55. package/tmp/browsertests-jhoSdz/index2.html +25 -0
  56. package/tmp/browsertests-jhoSdz/mocha.test.js +100 -0
  57. package/tmp/browsertests-jhoSdz/nightwatch.json +1 -0
  58. package/tmp/browsertests-koaNEn/index1.html +25 -0
  59. package/tmp/browsertests-koaNEn/index2.html +25 -0
  60. package/tmp/browsertests-koaNEn/mocha.test.js +100 -0
  61. package/tmp/browsertests-koaNEn/nightwatch.json +1 -0
  62. package/tmp/browsertests-ngYMnq/index1.html +25 -0
  63. package/tmp/browsertests-ngYMnq/index2.html +25 -0
  64. package/tmp/browsertests-ngYMnq/mocha.test.js +100 -0
  65. package/tmp/browsertests-ngYMnq/nightwatch.json +1 -0
  66. package/tmp/browsertests-oAq8xk/index1.html +25 -0
  67. package/tmp/browsertests-oAq8xk/index2.html +25 -0
  68. package/tmp/browsertests-oAq8xk/mocha.test.js +100 -0
  69. package/tmp/browsertests-oAq8xk/nightwatch.json +1 -0
  70. package/tmp/browsertests-q1rpZj/index1.html +25 -0
  71. package/tmp/browsertests-q1rpZj/index2.html +25 -0
  72. package/tmp/browsertests-q1rpZj/mocha.test.js +100 -0
  73. package/tmp/browsertests-q1rpZj/nightwatch.json +1 -0
  74. package/tmp/browsertests-zYgHlc/index1.html +25 -0
  75. package/tmp/browsertests-zYgHlc/index2.html +25 -0
  76. package/tmp/browsertests-zYgHlc/mocha.test.js +100 -0
  77. package/tmp/browsertests-zYgHlc/nightwatch.json +1 -0
  78. package/dist/generator.js +0 -221
@@ -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
+ }
@@ -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: { ...process.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();
@@ -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.0.6",
3
+ "version": "3.0.1",
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
  }
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -0,0 +1,100 @@
1
+ const expect = require("chai").expect
2
+
3
+ describe("Browser Mocha Tests", function () {
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
+
10
+ done()
11
+ })
12
+
13
+ after((client, done) => {
14
+ client.end(() => done())
15
+ })
16
+
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")
62
+
63
+ client.waitForElementVisible("#main")
64
+
65
+ const executeFunction = (done) => {
66
+ const mocha = window.mocha
67
+
68
+ //add required test librarys in this if statement
69
+ if (!mocha) {
70
+ console.log("Required library 'mocha' not loaded. Aborting...")
71
+ done({ failures: 1 })
72
+ return
73
+ }
74
+
75
+ if (!window.TEST) {
76
+ console.log("Required library 'TEST' not loaded. Aborting...")
77
+ done({ failures: 1 })
78
+ return
79
+ }
80
+ if (!window.TEST2) {
81
+ console.log("Required library 'TEST2' not loaded. Aborting...")
82
+ done({ failures: 1 })
83
+ return
84
+ }
85
+
86
+ mocha.run(function (failures) {
87
+ done({ failures: failures })
88
+ })
89
+ }
90
+
91
+ const result = await new Promise(resolve => client.timeoutsAsyncScript(1500000).executeAsyncScript(
92
+ executeFunction,
93
+ (result) => resolve(result)
94
+ ))
95
+
96
+ expect(result.value).to.not.be.undefined
97
+ expect(result.value.failures).to.equal(0)
98
+ })
99
+
100
+ })
@@ -0,0 +1 @@
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}}
@@ -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>
@@ -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>
@@ -0,0 +1,100 @@
1
+ const expect = require("chai").expect
2
+
3
+ describe("Browser Mocha Tests", function () {
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
+
10
+ done()
11
+ })
12
+
13
+ after((client, done) => {
14
+ client.end(() => done())
15
+ })
16
+
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")
62
+
63
+ client.waitForElementVisible("#main")
64
+
65
+ const executeFunction = (done) => {
66
+ const mocha = window.mocha
67
+
68
+ //add required test librarys in this if statement
69
+ if (!mocha) {
70
+ console.log("Required library 'mocha' not loaded. Aborting...")
71
+ done({ failures: 1 })
72
+ return
73
+ }
74
+
75
+ if (!window.TEST) {
76
+ console.log("Required library 'TEST' not loaded. Aborting...")
77
+ done({ failures: 1 })
78
+ return
79
+ }
80
+ if (!window.TEST2) {
81
+ console.log("Required library 'TEST2' not loaded. Aborting...")
82
+ done({ failures: 1 })
83
+ return
84
+ }
85
+
86
+ mocha.run(function (failures) {
87
+ done({ failures: failures })
88
+ })
89
+ }
90
+
91
+ const result = await new Promise(resolve => client.timeoutsAsyncScript(1500000).executeAsyncScript(
92
+ executeFunction,
93
+ (result) => resolve(result)
94
+ ))
95
+
96
+ expect(result.value).to.not.be.undefined
97
+ expect(result.value.failures).to.equal(0)
98
+ })
99
+
100
+ })
@@ -0,0 +1 @@
1
+ {"src_folders":["/home/julian/git/jss/docker-node-browsertests/test-runner/tmp/browsertests-Ef8QDb"],"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}}
@@ -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>