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,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-oAq8xk"],"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-q1rpZj"],"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-zYgHlc"],"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}}
package/dist/generator.js DELETED
@@ -1,221 +0,0 @@
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
- exports.generate = void 0;
27
- const fs = __importStar(require("fs"));
28
- const path = __importStar(require("path"));
29
- function generate(runners, additionalScripts, debug = false, port) {
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, debug);
34
- if (!debug) {
35
- if (!runner.globals) {
36
- runner.globals = [];
37
- }
38
- writeTestFile(outputPath, it, runner.globals);
39
- }
40
- it++;
41
- }
42
- if (!debug) {
43
- writeConfig(outputPath, port);
44
- }
45
- return outputPath;
46
- }
47
- exports.generate = generate;
48
- function writeHtml(outputPath, iteration, dependencies, additionalScripts, debug) {
49
- const html = `<!DOCTYPE html>
50
- <html>
51
- <head>
52
- <title>Mocha Tests</title>
53
- </head>
54
-
55
- <body>
56
- <div id="mocha"></div>
57
-
58
- ${debug
59
- ? ""
60
- : `
61
- <script>
62
- window.logs = []
63
- const oldLog = console.log
64
- console.log = function () {
65
- oldLog.apply(console, arguments)
66
- window.logs.push(Array.from(arguments))
67
- }
68
- </script>
69
- `}
70
-
71
- <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.2.0/mocha.min.js"></script>
72
- <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
73
- <script>
74
- mocha.setup("bdd")
75
- mocha.reporter("spec")
76
- </script>
77
- <script>
78
- ${additionalScripts ? additionalScripts.join("\n") : ""}
79
- </script>
80
-
81
- ${dependencies.map((dependency) => ` <script src="/test/${dependency}"></script>`).join("\n")}
82
-
83
- <div id="main">Test</div>
84
- </body>
85
- </html>`;
86
- fs.writeFileSync(path.join(outputPath, `index${iteration}.html`), html);
87
- }
88
- function writeTestFile(outputPath, iteration, globals) {
89
- const globalsString = globals
90
- .map((glob) => `if (!window.${glob}) {
91
- logs.push(["Required library '${glob}' not loaded. Aborting..."])
92
- localDone({ failures: 1, logs: logs })
93
- return
94
- }`)
95
- .join("\n");
96
- const testContent = `const expect = require("chai").expect
97
-
98
- describe("Browser Mocha Tests", function () {
99
- beforeEach((client, done) => {
100
- client.url("http://localhost:7777/test-browser/index${iteration}.html")
101
- done()
102
- })
103
-
104
- after((client, done) => {
105
- client.end(() => done())
106
- })
107
-
108
- it("Should run the Mocha tests without error", (client) => {
109
- client.waitForElementVisible("#main")
110
- client.timeoutsAsyncScript(1500000).executeAsync(
111
- (_data, done) => {
112
- const localDone = typeof _data === "function" ? _data : done
113
-
114
- const mocha = window.mocha
115
-
116
- //add required test librarys in this if statement
117
- if (!mocha) {
118
- logs.push(["Required library 'mocha' not loaded. Aborting..."])
119
- localDone({ failures: 1, logs: logs })
120
- return
121
- }
122
-
123
- ${globalsString}
124
-
125
- mocha.run(function (failures) {
126
- localDone({ failures: failures, logs: logs })
127
- })
128
- },
129
- [],
130
- (result) => {
131
- console.log("\\n--- browser mocha output ---")
132
-
133
- if (result && result.value && result.value.logs) {
134
- for (const logs of result.value.logs) {
135
- console.log.apply(null, logs)
136
- }
137
- }
138
-
139
- console.log("--- finished browser mocha output ---")
140
-
141
- expect(result.value).to.not.be.undefined
142
- expect(result.value.failures).to.equal(0)
143
- }
144
- )
145
- })
146
- })`;
147
- fs.writeFileSync(path.join(outputPath, `mocha${iteration}.test.js`), testContent);
148
- }
149
- function requireGlobal(packageName) {
150
- var childProcess = require("child_process");
151
- var path = require("path");
152
- var fs = require("fs");
153
- var globalNodeModules = childProcess.execSync("npm root -g").toString().trim();
154
- var packageDir = path.join(globalNodeModules, packageName);
155
- if (!fs.existsSync(packageDir))
156
- packageDir = path.join(globalNodeModules, "npm/node_modules", packageName); //find package required by old npm
157
- if (!fs.existsSync(packageDir))
158
- throw new Error("Cannot find global module '" + packageName + "'");
159
- var packageMeta = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json")).toString());
160
- var main = path.join(packageDir, packageMeta.main);
161
- return require(main);
162
- }
163
- function writeConfig(outputPath, port) {
164
- const settings = {
165
- src_folders: [outputPath],
166
- filter: "*.test.js",
167
- webdriver: {
168
- start_process: true,
169
- server_path: "",
170
- port: port,
171
- timeout_options: {
172
- timeout: 1500000
173
- }
174
- },
175
- test_runner: {
176
- type: "mocha",
177
- options: {
178
- ui: "bdd",
179
- reporter: "spec"
180
- }
181
- },
182
- test_settings: {
183
- default: {
184
- request_timeout_options: {
185
- timeout: 1500000
186
- },
187
- desiredCapabilities: {
188
- javascriptEnabled: true,
189
- acceptSslCerts: true,
190
- acceptInsecureCerts: true,
191
- browserName: "chrome",
192
- "goog:chromeOptions": {
193
- w3c: true,
194
- args: [
195
- "--headless",
196
- "--disable-gpu",
197
- "--ignore-certificate-errors",
198
- "--no-sandbox",
199
- "--disable-features=NetworkService"
200
- ],
201
- binary: "/usr/bin/google-chrome"
202
- }
203
- }
204
- }
205
- },
206
- globals: {
207
- waitForConditionTimeout: 100000,
208
- asyncHookTimeout: 1500000,
209
- unitTestsTimeout: 100000,
210
- customReporterCallbackTimeout: 100000,
211
- retryAssertionTimeout: 50000
212
- }
213
- };
214
- //@ts-ignore
215
- if (process.platform === "win32" || process.platform === "win64") {
216
- settings.test_settings.default.desiredCapabilities["goog:chromeOptions"].binary =
217
- "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
218
- }
219
- settings.webdriver.server_path = requireGlobal("chromedriver").path;
220
- fs.writeFileSync(path.join(outputPath, `nightwatch.json`), JSON.stringify(settings));
221
- }