bt-runner 2.0.5 → 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.
- package/dist/IRunner.js +2 -0
- package/dist/generate.js +62 -0
- package/dist/generator.js +62 -75
- package/dist/getPort.js +20 -0
- package/dist/index.js +63 -19
- package/dist/index_custom.js +100 -0
- package/dist/index_debug.js +13 -4
- package/dist/server.js +1 -1
- package/package.json +7 -10
- package/tmp/{browsertests-VXDG77 → browsertests-9PMQFx}/index1.html +2 -13
- package/tmp/browsertests-9PMQFx/index2.html +25 -0
- package/tmp/{browsertests-prIGUG → browsertests-CRhBRJ}/index1.html +2 -13
- package/tmp/browsertests-CRhBRJ/index2.html +25 -0
- package/tmp/browsertests-CRhBRJ/mocha.test.js +100 -0
- package/tmp/{browsertests-VXDG77 → browsertests-CRhBRJ}/nightwatch.json +1 -1
- package/tmp/browsertests-Ef8QDb/index1.html +25 -0
- package/tmp/browsertests-Ef8QDb/index2.html +25 -0
- package/tmp/browsertests-Ef8QDb/mocha.test.js +100 -0
- package/tmp/browsertests-Ef8QDb/nightwatch.json +1 -0
- package/tmp/browsertests-FNrySD/index1.html +25 -0
- package/tmp/browsertests-FNrySD/index2.html +25 -0
- package/tmp/browsertests-FNrySD/mocha.test.js +100 -0
- package/tmp/browsertests-FNrySD/nightwatch.json +1 -0
- package/tmp/browsertests-HnV7W1/index1.html +25 -0
- package/tmp/browsertests-HnV7W1/index2.html +25 -0
- package/tmp/browsertests-HnV7W1/mocha.test.js +100 -0
- package/tmp/browsertests-HnV7W1/nightwatch.json +1 -0
- package/tmp/browsertests-Kr11Ep/index1.html +25 -0
- package/tmp/browsertests-Kr11Ep/index2.html +25 -0
- package/tmp/browsertests-Kr11Ep/mocha.test.js +100 -0
- package/tmp/browsertests-Kr11Ep/nightwatch.json +1 -0
- package/tmp/browsertests-QTo9jV/index1.html +25 -0
- package/tmp/browsertests-QTo9jV/index2.html +25 -0
- package/tmp/browsertests-QTo9jV/mocha.test.js +100 -0
- package/tmp/browsertests-QTo9jV/nightwatch.json +1 -0
- package/tmp/browsertests-VXReLQ/index1.html +25 -0
- package/tmp/browsertests-VXReLQ/index2.html +25 -0
- package/tmp/browsertests-VXReLQ/mocha.test.js +100 -0
- package/tmp/browsertests-VXReLQ/nightwatch.json +1 -0
- package/tmp/browsertests-dat86a/index1.html +25 -0
- package/tmp/browsertests-dat86a/index2.html +25 -0
- package/tmp/browsertests-dat86a/mocha.test.js +94 -0
- package/tmp/browsertests-dat86a/nightwatch.json +1 -0
- package/tmp/browsertests-eI4Px3/index1.html +25 -0
- package/tmp/browsertests-eI4Px3/index2.html +25 -0
- package/tmp/browsertests-eI4Px3/mocha.test.js +100 -0
- package/tmp/browsertests-eI4Px3/nightwatch.json +1 -0
- package/tmp/browsertests-eQY4O5/index1.html +25 -0
- package/tmp/browsertests-eQY4O5/index2.html +25 -0
- package/tmp/browsertests-eQY4O5/mocha.test.js +100 -0
- package/tmp/browsertests-eQY4O5/nightwatch.json +1 -0
- package/tmp/browsertests-gOUWdm/index1.html +25 -0
- package/tmp/browsertests-gOUWdm/index2.html +25 -0
- package/tmp/browsertests-gOUWdm/mocha.test.js +100 -0
- package/tmp/browsertests-gOUWdm/nightwatch.json +1 -0
- package/tmp/browsertests-jhoSdz/index1.html +25 -0
- package/tmp/browsertests-jhoSdz/index2.html +25 -0
- package/tmp/browsertests-jhoSdz/mocha.test.js +100 -0
- package/tmp/browsertests-jhoSdz/nightwatch.json +1 -0
- package/tmp/browsertests-koaNEn/index1.html +25 -0
- package/tmp/browsertests-koaNEn/index2.html +25 -0
- package/tmp/browsertests-koaNEn/mocha.test.js +100 -0
- package/tmp/browsertests-koaNEn/nightwatch.json +1 -0
- package/tmp/browsertests-ngYMnq/index1.html +25 -0
- package/tmp/browsertests-ngYMnq/index2.html +25 -0
- package/tmp/browsertests-ngYMnq/mocha.test.js +100 -0
- package/tmp/browsertests-ngYMnq/nightwatch.json +1 -0
- package/tmp/browsertests-oAq8xk/index1.html +25 -0
- package/tmp/browsertests-oAq8xk/index2.html +25 -0
- package/tmp/browsertests-oAq8xk/mocha.test.js +100 -0
- package/tmp/browsertests-oAq8xk/nightwatch.json +1 -0
- package/tmp/browsertests-q1rpZj/index1.html +25 -0
- package/tmp/browsertests-q1rpZj/index2.html +25 -0
- package/tmp/browsertests-q1rpZj/mocha.test.js +100 -0
- package/tmp/browsertests-q1rpZj/nightwatch.json +1 -0
- package/tmp/browsertests-zYgHlc/index1.html +25 -0
- package/tmp/browsertests-zYgHlc/index2.html +25 -0
- package/tmp/browsertests-zYgHlc/mocha.test.js +100 -0
- package/tmp/browsertests-zYgHlc/nightwatch.json +1 -0
- package/tmp/browsertests-VXDG77/mocha1.test.js +0 -60
- package/tmp/browsertests-prIGUG/mocha1.test.js +0 -60
- package/tmp/browsertests-prIGUG/nightwatch.json +0 -1
package/dist/IRunner.js
ADDED
package/dist/generate.js
ADDED
@@ -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
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
3
|
if (k2 === undefined) k2 = k;
|
4
|
-
Object.
|
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);
|
5
9
|
}) : (function(o, m, k, k2) {
|
6
10
|
if (k2 === undefined) k2 = k;
|
7
11
|
o[k2] = m[k];
|
@@ -24,24 +28,17 @@ const fs = __importStar(require("fs"));
|
|
24
28
|
const path = __importStar(require("path"));
|
25
29
|
function generate(runners, additionalScripts, debug = false, port) {
|
26
30
|
const outputPath = fs.mkdtempSync(path.join(__dirname, "..", "tmp", "browsertests-"));
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if (!debug) {
|
31
|
-
if (!runner.globals) {
|
32
|
-
runner.globals = [];
|
33
|
-
}
|
34
|
-
writeTestFile(outputPath, it, runner.globals);
|
35
|
-
}
|
36
|
-
it++;
|
37
|
-
}
|
31
|
+
runners.forEach((runner, index) => {
|
32
|
+
writeHtml(outputPath, index + 1, runner.dependencies, additionalScripts);
|
33
|
+
});
|
38
34
|
if (!debug) {
|
39
35
|
writeConfig(outputPath, port);
|
36
|
+
writeSingleTestFile(outputPath, runners);
|
40
37
|
}
|
41
38
|
return outputPath;
|
42
39
|
}
|
43
40
|
exports.generate = generate;
|
44
|
-
function writeHtml(outputPath,
|
41
|
+
function writeHtml(outputPath, runnerNumber, dependencies, additionalScripts) {
|
45
42
|
const html = `<!DOCTYPE html>
|
46
43
|
<html>
|
47
44
|
<head>
|
@@ -50,22 +47,9 @@ function writeHtml(outputPath, iteration, dependencies, additionalScripts, debug
|
|
50
47
|
|
51
48
|
<body>
|
52
49
|
<div id="mocha"></div>
|
53
|
-
|
54
|
-
${debug
|
55
|
-
? ""
|
56
|
-
: `
|
57
|
-
<script>
|
58
|
-
window.logs = []
|
59
|
-
const oldLog = console.log
|
60
|
-
console.log = function () {
|
61
|
-
oldLog.apply(console, arguments)
|
62
|
-
window.logs.push(Array.from(arguments))
|
63
|
-
}
|
64
|
-
</script>
|
65
|
-
`}
|
66
50
|
|
67
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/
|
68
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.
|
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>
|
69
53
|
<script>
|
70
54
|
mocha.setup("bdd")
|
71
55
|
mocha.reporter("spec")
|
@@ -79,21 +63,19 @@ function writeHtml(outputPath, iteration, dependencies, additionalScripts, debug
|
|
79
63
|
<div id="main">Test</div>
|
80
64
|
</body>
|
81
65
|
</html>`;
|
82
|
-
fs.writeFileSync(path.join(outputPath, `index${
|
66
|
+
fs.writeFileSync(path.join(outputPath, `index${runnerNumber}.html`), html);
|
83
67
|
}
|
84
|
-
function
|
85
|
-
const
|
86
|
-
.map((glob) => `if (!window.${glob}) {
|
87
|
-
logs.push(["Required library '${glob}' not loaded. Aborting..."])
|
88
|
-
localDone({ failures: 1, logs: logs })
|
89
|
-
return
|
90
|
-
}`)
|
91
|
-
.join("\n");
|
68
|
+
function writeSingleTestFile(outputPath, runners) {
|
69
|
+
const tests = runners.map((runner, iteration) => runnerToTest(runner, iteration + 1));
|
92
70
|
const testContent = `const expect = require("chai").expect
|
93
71
|
|
94
72
|
describe("Browser Mocha Tests", function () {
|
95
|
-
|
96
|
-
client.
|
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
|
+
|
97
79
|
done()
|
98
80
|
})
|
99
81
|
|
@@ -101,46 +83,51 @@ function writeTestFile(outputPath, iteration, globals) {
|
|
101
83
|
client.end(() => done())
|
102
84
|
})
|
103
85
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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")
|
109
102
|
|
110
|
-
|
111
|
-
|
112
|
-
//add required test librarys in this if statement
|
113
|
-
if (!mocha) {
|
114
|
-
logs.push(["Required library 'mocha' not loaded. Aborting..."])
|
115
|
-
localDone({ failures: 1, logs: logs })
|
116
|
-
return
|
117
|
-
}
|
103
|
+
client.waitForElementVisible("#main")
|
118
104
|
|
119
|
-
|
120
|
-
|
121
|
-
mocha.run(function (failures) {
|
122
|
-
localDone({ failures: failures, logs: logs })
|
123
|
-
})
|
124
|
-
},
|
125
|
-
[],
|
126
|
-
(result) => {
|
127
|
-
console.log("\\n--- browser mocha output ---")
|
105
|
+
const executeFunction = (done) => {
|
106
|
+
const mocha = window.mocha
|
128
107
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
console.log("--- finished browser mocha output ---")
|
136
|
-
|
137
|
-
expect(result.value).to.not.be.undefined
|
138
|
-
expect(result.value.failures).to.equal(0)
|
108
|
+
//add required test librarys in this if statement
|
109
|
+
if (!mocha) {
|
110
|
+
console.log("Required library 'mocha' not loaded. Aborting...")
|
111
|
+
done({ failures: 1 })
|
112
|
+
return
|
139
113
|
}
|
140
|
-
|
114
|
+
|
115
|
+
${globalsString}
|
116
|
+
|
117
|
+
mocha.run(function (failures) {
|
118
|
+
done({ failures: failures })
|
119
|
+
})
|
120
|
+
}
|
121
|
+
|
122
|
+
const result = await new Promise(resolve => client.timeoutsAsyncScript(1500000).executeAsyncScript(
|
123
|
+
executeFunction,
|
124
|
+
(result) => resolve(result)
|
125
|
+
))
|
126
|
+
|
127
|
+
expect(result.value).to.not.be.undefined
|
128
|
+
expect(result.value.failures).to.equal(0)
|
141
129
|
})
|
142
|
-
|
143
|
-
fs.writeFileSync(path.join(outputPath, `mocha${iteration}.test.js`), testContent);
|
130
|
+
`;
|
144
131
|
}
|
145
132
|
function requireGlobal(packageName) {
|
146
133
|
var childProcess = require("child_process");
|
@@ -213,5 +200,5 @@ function writeConfig(outputPath, port) {
|
|
213
200
|
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
|
214
201
|
}
|
215
202
|
settings.webdriver.server_path = requireGlobal("chromedriver").path;
|
216
|
-
fs.writeFileSync(path.join(outputPath,
|
203
|
+
fs.writeFileSync(path.join(outputPath, "nightwatch.json"), JSON.stringify(settings));
|
217
204
|
}
|
package/dist/getPort.js
ADDED
@@ -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
@@ -2,7 +2,11 @@
|
|
2
2
|
"use strict";
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
4
4
|
if (k2 === undefined) k2 = k;
|
5
|
-
Object.
|
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);
|
6
10
|
}) : (function(o, m, k, k2) {
|
7
11
|
if (k2 === undefined) k2 = k;
|
8
12
|
o[k2] = m[k];
|
@@ -24,13 +28,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
28
|
};
|
25
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
30
|
const child_process = __importStar(require("child_process"));
|
27
|
-
const Nightwatch = __importStar(require("nightwatch"));
|
28
31
|
const path = __importStar(require("path"));
|
32
|
+
const puppeteer_1 = __importDefault(require("puppeteer"));
|
29
33
|
const helpers_1 = require("yargs/helpers");
|
30
34
|
const yargs_1 = __importDefault(require("yargs/yargs"));
|
31
|
-
const
|
35
|
+
const generate_1 = __importDefault(require("./generate"));
|
36
|
+
const getPort_1 = __importDefault(require("./getPort"));
|
32
37
|
const rimraf = require("rimraf");
|
33
|
-
|
38
|
+
async function run() {
|
39
|
+
const port = await (0, getPort_1.default)();
|
34
40
|
const args = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
35
41
|
.option("config", {
|
36
42
|
alias: "c",
|
@@ -45,26 +51,64 @@ Nightwatch.cli(async function (argv) {
|
|
45
51
|
default: 9515
|
46
52
|
}).argv;
|
47
53
|
const nbt = require(path.join(process.cwd(), args.config));
|
48
|
-
const tempFolder =
|
54
|
+
const tempFolder = (0, generate_1.default)(nbt.runners, nbt.additionalScripts);
|
49
55
|
const testFolder = path.resolve(nbt.testFolder);
|
50
|
-
|
51
|
-
stdio: "inherit"
|
56
|
+
const httpServerProc = child_process.spawn("node", [`${__dirname}/../dist/server.js`, tempFolder, testFolder], {
|
57
|
+
stdio: "inherit",
|
58
|
+
env: { PORT: port.toString() }
|
52
59
|
});
|
53
|
-
|
54
|
-
const runner = Nightwatch.CliRunner(argv);
|
60
|
+
let exitCode = 0;
|
55
61
|
try {
|
56
|
-
await
|
57
|
-
|
62
|
+
const success = await runTests(port, nbt.runners);
|
63
|
+
if (!success)
|
64
|
+
exitCode = 1;
|
58
65
|
}
|
59
|
-
catch (
|
60
|
-
console.error(
|
66
|
+
catch (e) {
|
67
|
+
console.error(e);
|
68
|
+
exitCode = 1;
|
61
69
|
}
|
62
70
|
finally {
|
63
|
-
|
71
|
+
httpServerProc.kill("SIGINT");
|
72
|
+
rimraf.sync(tempFolder);
|
64
73
|
}
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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;
|
70
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
|
+
});
|
package/dist/index_debug.js
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
"use strict";
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
4
4
|
if (k2 === undefined) k2 = k;
|
5
|
-
Object.
|
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);
|
6
10
|
}) : (function(o, m, k, k2) {
|
7
11
|
if (k2 === undefined) k2 = k;
|
8
12
|
o[k2] = m[k];
|
@@ -26,10 +30,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
30
|
const express_1 = __importDefault(require("express"));
|
27
31
|
const express_http_proxy_1 = __importDefault(require("express-http-proxy"));
|
28
32
|
const path = __importStar(require("path"));
|
29
|
-
const
|
33
|
+
const generate_1 = __importDefault(require("./generate"));
|
30
34
|
const app = (0, express_1.default)();
|
31
35
|
const nbt = require(path.join(process.cwd(), "nbt.json"));
|
32
|
-
const outputPath =
|
36
|
+
const outputPath = (0, generate_1.default)(nbt.runners, nbt.additionalScripts);
|
33
37
|
app.use("/test-browser", express_1.default.static(outputPath));
|
34
38
|
app.use("/test", express_1.default.static(path.resolve(nbt.testFolder)));
|
35
39
|
if (nbt.proxies) {
|
@@ -37,5 +41,10 @@ if (nbt.proxies) {
|
|
37
41
|
app.use(proxy.local, (0, express_http_proxy_1.default)(proxy.remote));
|
38
42
|
}
|
39
43
|
}
|
40
|
-
|
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.`);
|
41
50
|
app.listen(7777, () => { });
|
package/dist/server.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "bt-runner",
|
3
|
-
"version": "
|
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
|
-
"
|
25
|
-
"express": "^4.17.3",
|
24
|
+
"express": "^4.18.1",
|
26
25
|
"express-http-proxy": "^1.6.3",
|
27
|
-
"
|
28
|
-
"nightwatch": "^2.0.7",
|
26
|
+
"puppeteer": "^16.2.0",
|
29
27
|
"rimraf": "^3.0.2",
|
30
|
-
"yargs": "^17.
|
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/
|
36
|
-
"@types/node": "^17.0.18",
|
33
|
+
"@types/node": "^18.7.11",
|
37
34
|
"@types/rimraf": "^3.0.2",
|
38
|
-
"@types/yargs": "^17.0.
|
35
|
+
"@types/yargs": "^17.0.11"
|
39
36
|
},
|
40
37
|
"publishConfig": {
|
41
|
-
"
|
38
|
+
"access": "public"
|
42
39
|
}
|
43
40
|
}
|
@@ -6,20 +6,9 @@
|
|
6
6
|
|
7
7
|
<body>
|
8
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
9
|
|
21
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/
|
22
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.
|
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>
|
23
12
|
<script>
|
24
13
|
mocha.setup("bdd")
|
25
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>
|
@@ -6,20 +6,9 @@
|
|
6
6
|
|
7
7
|
<body>
|
8
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
9
|
|
21
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/
|
22
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.
|
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>
|
23
12
|
<script>
|
24
13
|
mocha.setup("bdd")
|
25
14
|
mocha.reporter("spec")
|