bt-runner 2.0.6 → 2.1.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/generator.js CHANGED
@@ -30,7 +30,7 @@ function generate(runners, additionalScripts, debug = false, port) {
30
30
  const outputPath = fs.mkdtempSync(path.join(__dirname, "..", "tmp", "browsertests-"));
31
31
  let it = 1;
32
32
  for (const runner of runners) {
33
- writeHtml(outputPath, it, runner.dependencies, additionalScripts, debug);
33
+ writeHtml(outputPath, it, runner.dependencies, additionalScripts);
34
34
  if (!debug) {
35
35
  if (!runner.globals) {
36
36
  runner.globals = [];
@@ -45,7 +45,7 @@ function generate(runners, additionalScripts, debug = false, port) {
45
45
  return outputPath;
46
46
  }
47
47
  exports.generate = generate;
48
- function writeHtml(outputPath, iteration, dependencies, additionalScripts, debug) {
48
+ function writeHtml(outputPath, iteration, dependencies, additionalScripts) {
49
49
  const html = `<!DOCTYPE html>
50
50
  <html>
51
51
  <head>
@@ -54,19 +54,6 @@ function writeHtml(outputPath, iteration, dependencies, additionalScripts, debug
54
54
 
55
55
  <body>
56
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
57
 
71
58
  <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.2.0/mocha.min.js"></script>
72
59
  <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
@@ -88,8 +75,8 @@ function writeHtml(outputPath, iteration, dependencies, additionalScripts, debug
88
75
  function writeTestFile(outputPath, iteration, globals) {
89
76
  const globalsString = globals
90
77
  .map((glob) => `if (!window.${glob}) {
91
- logs.push(["Required library '${glob}' not loaded. Aborting..."])
92
- localDone({ failures: 1, logs: logs })
78
+ console.log("Required library '${glob}' not loaded. Aborting...")
79
+ done({ failures: 1 })
93
80
  return
94
81
  }`)
95
82
  .join("\n");
@@ -105,43 +92,38 @@ function writeTestFile(outputPath, iteration, globals) {
105
92
  client.end(() => done())
106
93
  })
107
94
 
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
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
+ })
113
100
 
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
- }
101
+ client.waitForElementVisible("#main")
122
102
 
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 ---")
103
+ const executeFunction = (done) => {
104
+ const mocha = window.mocha
132
105
 
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)
106
+ //add required test librarys in this if statement
107
+ if (!mocha) {
108
+ console.log("Required library 'mocha' not loaded. Aborting...")
109
+ done({ failures: 1 })
110
+ return
143
111
  }
144
- )
112
+
113
+ ${globalsString}
114
+
115
+ mocha.run(function (failures) {
116
+ done({ failures: failures })
117
+ })
118
+ }
119
+
120
+ const result = await new Promise(resolve => client.timeoutsAsyncScript(1500000).executeAsyncScript(
121
+ executeFunction,
122
+ (result) => resolve(result)
123
+ ))
124
+
125
+ expect(result.value).to.not.be.undefined
126
+ expect(result.value.failures).to.equal(0)
145
127
  })
146
128
  })`;
147
129
  fs.writeFileSync(path.join(outputPath, `mocha${iteration}.test.js`), testContent);
@@ -217,5 +199,5 @@ function writeConfig(outputPath, port) {
217
199
  "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
218
200
  }
219
201
  settings.webdriver.server_path = requireGlobal("chromedriver").path;
220
- fs.writeFileSync(path.join(outputPath, `nightwatch.json`), JSON.stringify(settings));
202
+ fs.writeFileSync(path.join(outputPath, "nightwatch.json"), JSON.stringify(settings));
221
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-runner",
3
- "version": "2.0.6",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Mocha Tests</title>
5
+ </head>
6
+
7
+ <body>
8
+ <div id="mocha"></div>
9
+
10
+
11
+
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>
14
+ <script>
15
+ mocha.setup("bdd")
16
+ mocha.reporter("spec")
17
+ </script>
18
+ <script>
19
+ window.TEST = {}
20
+ window.TEST2 = {}
21
+ </script>
22
+
23
+ <script src="/test/test.js"></script>
24
+
25
+ <div id="main">Test</div>
26
+ </body>
27
+ </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/7.2.0/mocha.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/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,56 @@
1
+ const expect = require("chai").expect
2
+
3
+ describe("Browser Mocha Tests", function () {
4
+ beforeEach((client, done) => {
5
+ client.url("http://localhost:7777/test-browser/index1.html")
6
+ done()
7
+ })
8
+
9
+ after((client, done) => {
10
+ client.end(() => done())
11
+ })
12
+
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
+ args[0] = "BROWSER LOG - " + args[0]
17
+ console.log.apply(console, args)
18
+ })
19
+
20
+ client.waitForElementVisible("#main")
21
+
22
+ const executeFunction = (done) => {
23
+ const mocha = window.mocha
24
+
25
+ //add required test librarys in this if statement
26
+ if (!mocha) {
27
+ console.log("Required library 'mocha' not loaded. Aborting...")
28
+ done({ failures: 1 })
29
+ return
30
+ }
31
+
32
+ if (!window.TEST) {
33
+ console.log("Required library 'TEST' not loaded. Aborting...")
34
+ localDone({ failures: 1 })
35
+ return
36
+ }
37
+ if (!window.TEST2) {
38
+ console.log("Required library 'TEST2' not loaded. Aborting...")
39
+ localDone({ failures: 1 })
40
+ return
41
+ }
42
+
43
+ mocha.run(function (failures) {
44
+ done({ failures: failures })
45
+ })
46
+ }
47
+
48
+ const result = await new Promise(resolve => client.timeoutsAsyncScript(1500000).executeAsyncScript(
49
+ executeFunction,
50
+ (result) => resolve(result)
51
+ ))
52
+
53
+ expect(result.value).to.not.be.undefined
54
+ expect(result.value.failures).to.equal(0)
55
+ })
56
+ })
@@ -0,0 +1 @@
1
+ {"src_folders":["/home/julian/git/jss/docker-node-browsertests/test-runner/tmp/browsertests-71yT6w"],"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/7.2.0/mocha.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/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,55 @@
1
+ const expect = require("chai").expect
2
+
3
+ describe("Browser Mocha Tests", function () {
4
+ beforeEach((client, done) => {
5
+ client.url("http://localhost:7777/test-browser/index1.html")
6
+ done()
7
+ })
8
+
9
+ after((client, done) => {
10
+ client.end(() => done())
11
+ })
12
+
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
+ })
18
+
19
+ client.waitForElementVisible("#main")
20
+
21
+ const executeFunction = (done) => {
22
+ const mocha = window.mocha
23
+
24
+ //add required test librarys in this if statement
25
+ if (!mocha) {
26
+ console.log("Required library 'mocha' not loaded. Aborting...")
27
+ done({ failures: 1 })
28
+ return
29
+ }
30
+
31
+ if (!window.TEST) {
32
+ console.log("Required library 'TEST' not loaded. Aborting...")
33
+ localDone({ failures: 1 })
34
+ return
35
+ }
36
+ if (!window.TEST2) {
37
+ console.log("Required library 'TEST2' not loaded. Aborting...")
38
+ localDone({ failures: 1 })
39
+ return
40
+ }
41
+
42
+ mocha.run(function (failures) {
43
+ done({ failures: failures })
44
+ })
45
+ }
46
+
47
+ const result = await new Promise(resolve => client.timeoutsAsyncScript(1500000).executeAsyncScript(
48
+ executeFunction,
49
+ (result) => resolve(result)
50
+ ))
51
+
52
+ expect(result.value).to.not.be.undefined
53
+ expect(result.value.failures).to.equal(0)
54
+ })
55
+ })
@@ -0,0 +1 @@
1
+ {"src_folders":["/home/julian/git/jss/docker-node-browsertests/test-runner/tmp/browsertests-nIABth"],"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":{"reporter":"List"}},"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,36 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Mocha Tests</title>
5
+ </head>
6
+
7
+ <body>
8
+ <div id="mocha"></div>
9
+
10
+
11
+ <script>
12
+ window.logs = []
13
+ const oldLog = console.log
14
+ console.log = function () {
15
+ oldLog.apply(console, arguments)
16
+ window.logs.push(Array.from(arguments))
17
+ }
18
+ </script>
19
+
20
+
21
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.2.0/mocha.min.js"></script>
22
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
23
+ <script>
24
+ mocha.setup("bdd")
25
+ mocha.reporter("spec")
26
+ </script>
27
+ <script>
28
+ window.TEST = {}
29
+ window.TEST2 = {}
30
+ </script>
31
+
32
+ <script src="/test/test.js"></script>
33
+
34
+ <div id="main">Test</div>
35
+ </body>
36
+ </html>
@@ -0,0 +1,69 @@
1
+ const expect = require("chai").expect
2
+
3
+ describe("Browser Mocha Tests", function () {
4
+ beforeEach((client, done) => {
5
+ client.url("http://localhost:7777/test-browser/index1.html")
6
+ done()
7
+ })
8
+
9
+ after((client, done) => {
10
+ client.end(() => done())
11
+ })
12
+
13
+ it("Should run the Mocha tests without error", (client) => {
14
+ const outsideLog = console.log
15
+
16
+ client.waitForElementVisible("#main")
17
+ client.timeoutsAsyncScript(1500000).executeAsync(
18
+ (_data, done) => {
19
+ const oldLog = console.log
20
+ console.log = function () {
21
+ oldLog.apply(console, arguments)
22
+ outsideLog.apply(console, arguments)
23
+ window.logs.push(Array.from(arguments))
24
+ }
25
+
26
+ const localDone = typeof _data === "function" ? _data : done
27
+
28
+ const mocha = window.mocha
29
+
30
+ //add required test librarys in this if statement
31
+ if (!mocha) {
32
+ logs.push(["Required library 'mocha' not loaded. Aborting..."])
33
+ localDone({ failures: 1, logs: logs })
34
+ return
35
+ }
36
+
37
+ if (!window.TEST) {
38
+ logs.push(["Required library 'TEST' not loaded. Aborting..."])
39
+ localDone({ failures: 1, logs: logs })
40
+ return
41
+ }
42
+ if (!window.TEST2) {
43
+ logs.push(["Required library 'TEST2' not loaded. Aborting..."])
44
+ localDone({ failures: 1, logs: logs })
45
+ return
46
+ }
47
+
48
+ mocha.run(function (failures) {
49
+ localDone({ failures: failures, logs: logs })
50
+ })
51
+ },
52
+ [],
53
+ (result) => {
54
+ console.log("\n--- browser mocha output ---")
55
+
56
+ if (result && result.value && result.value.logs) {
57
+ for (const logs of result.value.logs) {
58
+ console.log.apply(null, logs)
59
+ }
60
+ }
61
+
62
+ console.log("--- finished browser mocha output ---")
63
+
64
+ expect(result.value).to.not.be.undefined
65
+ expect(result.value.failures).to.equal(0)
66
+ }
67
+ )
68
+ })
69
+ })
@@ -0,0 +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}}