bt-runner 3.0.0 → 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.
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/generator.js +0 -204
- package/dist/index_custom.js +0 -100
package/dist/index.js
CHANGED
@@ -55,7 +55,7 @@ async function run() {
|
|
55
55
|
const testFolder = path.resolve(nbt.testFolder);
|
56
56
|
const httpServerProc = child_process.spawn("node", [`${__dirname}/../dist/server.js`, tempFolder, testFolder], {
|
57
57
|
stdio: "inherit",
|
58
|
-
env: { PORT: port.toString() }
|
58
|
+
env: { ...process.env, PORT: port.toString() }
|
59
59
|
});
|
60
60
|
let exitCode = 0;
|
61
61
|
try {
|
package/package.json
CHANGED
package/dist/generator.js
DELETED
@@ -1,204 +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
|
-
runners.forEach((runner, index) => {
|
32
|
-
writeHtml(outputPath, index + 1, runner.dependencies, additionalScripts);
|
33
|
-
});
|
34
|
-
if (!debug) {
|
35
|
-
writeConfig(outputPath, port);
|
36
|
-
writeSingleTestFile(outputPath, runners);
|
37
|
-
}
|
38
|
-
return outputPath;
|
39
|
-
}
|
40
|
-
exports.generate = generate;
|
41
|
-
function writeHtml(outputPath, runnerNumber, dependencies, additionalScripts) {
|
42
|
-
const html = `<!DOCTYPE html>
|
43
|
-
<html>
|
44
|
-
<head>
|
45
|
-
<title>Mocha Tests</title>
|
46
|
-
</head>
|
47
|
-
|
48
|
-
<body>
|
49
|
-
<div id="mocha"></div>
|
50
|
-
|
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>
|
53
|
-
<script>
|
54
|
-
mocha.setup("bdd")
|
55
|
-
mocha.reporter("spec")
|
56
|
-
</script>
|
57
|
-
<script>
|
58
|
-
${additionalScripts ? additionalScripts.join("\n") : ""}
|
59
|
-
</script>
|
60
|
-
|
61
|
-
${dependencies.map((dependency) => ` <script src="/test/${dependency}"></script>`).join("\n")}
|
62
|
-
|
63
|
-
<div id="main">Test</div>
|
64
|
-
</body>
|
65
|
-
</html>`;
|
66
|
-
fs.writeFileSync(path.join(outputPath, `index${runnerNumber}.html`), html);
|
67
|
-
}
|
68
|
-
function writeSingleTestFile(outputPath, runners) {
|
69
|
-
const tests = runners.map((runner, iteration) => runnerToTest(runner, iteration + 1));
|
70
|
-
const testContent = `const expect = require("chai").expect
|
71
|
-
|
72
|
-
describe("Browser Mocha Tests", function () {
|
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
|
-
|
79
|
-
done()
|
80
|
-
})
|
81
|
-
|
82
|
-
after((client, done) => {
|
83
|
-
client.end(() => done())
|
84
|
-
})
|
85
|
-
|
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")
|
102
|
-
|
103
|
-
client.waitForElementVisible("#main")
|
104
|
-
|
105
|
-
const executeFunction = (done) => {
|
106
|
-
const mocha = window.mocha
|
107
|
-
|
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
|
113
|
-
}
|
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)
|
129
|
-
})
|
130
|
-
`;
|
131
|
-
}
|
132
|
-
function requireGlobal(packageName) {
|
133
|
-
var childProcess = require("child_process");
|
134
|
-
var path = require("path");
|
135
|
-
var fs = require("fs");
|
136
|
-
var globalNodeModules = childProcess.execSync("npm root -g").toString().trim();
|
137
|
-
var packageDir = path.join(globalNodeModules, packageName);
|
138
|
-
if (!fs.existsSync(packageDir))
|
139
|
-
packageDir = path.join(globalNodeModules, "npm/node_modules", packageName); //find package required by old npm
|
140
|
-
if (!fs.existsSync(packageDir))
|
141
|
-
throw new Error("Cannot find global module '" + packageName + "'");
|
142
|
-
var packageMeta = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json")).toString());
|
143
|
-
var main = path.join(packageDir, packageMeta.main);
|
144
|
-
return require(main);
|
145
|
-
}
|
146
|
-
function writeConfig(outputPath, port) {
|
147
|
-
const settings = {
|
148
|
-
src_folders: [outputPath],
|
149
|
-
filter: "*.test.js",
|
150
|
-
webdriver: {
|
151
|
-
start_process: true,
|
152
|
-
server_path: "",
|
153
|
-
port: port,
|
154
|
-
timeout_options: {
|
155
|
-
timeout: 1500000
|
156
|
-
}
|
157
|
-
},
|
158
|
-
test_runner: {
|
159
|
-
type: "mocha",
|
160
|
-
options: {
|
161
|
-
ui: "bdd",
|
162
|
-
reporter: "spec"
|
163
|
-
}
|
164
|
-
},
|
165
|
-
test_settings: {
|
166
|
-
default: {
|
167
|
-
request_timeout_options: {
|
168
|
-
timeout: 1500000
|
169
|
-
},
|
170
|
-
desiredCapabilities: {
|
171
|
-
javascriptEnabled: true,
|
172
|
-
acceptSslCerts: true,
|
173
|
-
acceptInsecureCerts: true,
|
174
|
-
browserName: "chrome",
|
175
|
-
"goog:chromeOptions": {
|
176
|
-
w3c: true,
|
177
|
-
args: [
|
178
|
-
"--headless",
|
179
|
-
"--disable-gpu",
|
180
|
-
"--ignore-certificate-errors",
|
181
|
-
"--no-sandbox",
|
182
|
-
"--disable-features=NetworkService"
|
183
|
-
],
|
184
|
-
binary: "/usr/bin/google-chrome"
|
185
|
-
}
|
186
|
-
}
|
187
|
-
}
|
188
|
-
},
|
189
|
-
globals: {
|
190
|
-
waitForConditionTimeout: 100000,
|
191
|
-
asyncHookTimeout: 1500000,
|
192
|
-
unitTestsTimeout: 100000,
|
193
|
-
customReporterCallbackTimeout: 100000,
|
194
|
-
retryAssertionTimeout: 50000
|
195
|
-
}
|
196
|
-
};
|
197
|
-
//@ts-ignore
|
198
|
-
if (process.platform === "win32" || process.platform === "win64") {
|
199
|
-
settings.test_settings.default.desiredCapabilities["goog:chromeOptions"].binary =
|
200
|
-
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
|
201
|
-
}
|
202
|
-
settings.webdriver.server_path = requireGlobal("chromedriver").path;
|
203
|
-
fs.writeFileSync(path.join(outputPath, "nightwatch.json"), JSON.stringify(settings));
|
204
|
-
}
|
package/dist/index_custom.js
DELETED
@@ -1,100 +0,0 @@
|
|
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
|
-
});
|