bt-runner 1.0.17

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.
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ exports.__esModule = true;
22
+ exports.generate = void 0;
23
+ var fs = __importStar(require("fs"));
24
+ var path = __importStar(require("path"));
25
+ function generate(runners, additionalScripts, debug, port) {
26
+ if (debug === void 0) { debug = false; }
27
+ var outputPath = fs.mkdtempSync(path.join(__dirname, "..", "tmp", "browsertests-"));
28
+ var it = 1;
29
+ for (var _i = 0, runners_1 = runners; _i < runners_1.length; _i++) {
30
+ var runner = runners_1[_i];
31
+ writeHtml(outputPath, it, runner.dependencies, additionalScripts, debug);
32
+ if (!debug) {
33
+ if (!runner.globals) {
34
+ runner.globals = [];
35
+ }
36
+ writeTestFile(outputPath, it, runner.globals);
37
+ }
38
+ it++;
39
+ }
40
+ if (!debug) {
41
+ writeConfig(outputPath, port);
42
+ }
43
+ return outputPath;
44
+ }
45
+ exports.generate = generate;
46
+ function writeHtml(outputPath, iteration, dependencies, additionalScripts, debug) {
47
+ var html = "<!DOCTYPE html>\n<html>\n <head>\n <title>Mocha Tests</title>\n </head>\n\n <body>\n <div id=\"mocha\"></div>\n \n " + (debug
48
+ ? ""
49
+ : "\n <script>\n window.logs = []\n console.log = function () {\n window.logs.push(Array.from(arguments))\n }\n </script>\n ") + "\n\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mocha/7.2.0/mocha.min.js\"></script>\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js\"></script>\n <script>\n mocha.setup(\"bdd\")\n mocha.reporter(\"spec\")\n </script>\n <script>\n " + (additionalScripts ? additionalScripts.join("\n") : "") + "\n </script>\n \n " + dependencies.map(function (dependency) { return " <script src=\"/test/" + dependency + "\"></script>"; }).join("\n") + "\n\n <div id=\"main\">Test</div>\n </body>\n</html>";
50
+ fs.writeFileSync(path.join(outputPath, "index" + iteration + ".html"), html);
51
+ }
52
+ function writeTestFile(outputPath, iteration, globals) {
53
+ var globalsString = globals
54
+ .map(function (glob) { return "if (!window." + glob + ") {\n logs.push([\"Required library '" + glob + "' not loaded. Aborting...\"])\n done({ failures: 1, logs: logs })\n return\n }"; })
55
+ .join("\n");
56
+ var testContent = "const expect = require(\"chai\").expect\n\n describe(\"Browser Mocha Tests\", function () {\n beforeEach((client, done) => {\n client.url(\"http://localhost:7777/test-browser/index" + iteration + ".html\")\n done()\n })\n \n after((client, done) => {\n client.end(() => done())\n })\n \n it(\"Should run the Mocha tests without error\", (client) => {\n client.waitForElementVisible(\"#main\")\n client.timeoutsAsyncScript(1500000).executeAsync(\n function (done) {\n const mocha = window.mocha\n \n //add required test librarys in this if statement\n if (!mocha) {\n logs.push([\"Required library 'mocha' not loaded. Aborting...\"])\n done({ failures: 1, logs: logs })\n return\n }\n\n " + globalsString + "\n \n mocha.run(function (failures) {\n done({ failures: failures, logs: logs })\n })\n },\n [],\n (result) => {\n console.log(\"\\n--- browser mocha output ---\")\n\n if (result && result.value && result.value.logs) {\n for (const logs of result.value.logs) {\n console.log.apply(null, logs)\n }\n }\n \n console.log(\"--- finished browser mocha output ---\")\n \n expect(result.value).to.not.be.undefined\n expect(result.value.failures).to.equal(0)\n }\n )\n })\n })";
57
+ fs.writeFileSync(path.join(outputPath, "mocha" + iteration + ".test.js"), testContent);
58
+ }
59
+ function requireGlobal(packageName) {
60
+ var childProcess = require("child_process");
61
+ var path = require("path");
62
+ var fs = require("fs");
63
+ var globalNodeModules = childProcess.execSync("npm root -g").toString().trim();
64
+ var packageDir = path.join(globalNodeModules, packageName);
65
+ if (!fs.existsSync(packageDir))
66
+ packageDir = path.join(globalNodeModules, "npm/node_modules", packageName); //find package required by old npm
67
+ if (!fs.existsSync(packageDir))
68
+ throw new Error("Cannot find global module '" + packageName + "'");
69
+ var packageMeta = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json")).toString());
70
+ var main = path.join(packageDir, packageMeta.main);
71
+ return require(main);
72
+ }
73
+ function writeConfig(outputPath, port) {
74
+ var settings = {
75
+ src_folders: [outputPath],
76
+ filter: "*.test.js",
77
+ webdriver: {
78
+ start_process: true,
79
+ server_path: "",
80
+ port: port
81
+ },
82
+ test_runner: {
83
+ type: "mocha",
84
+ options: {
85
+ ui: "bdd",
86
+ reporter: "spec"
87
+ }
88
+ },
89
+ test_settings: {
90
+ "default": {
91
+ request_timeout_options: {
92
+ timeout: 1500000
93
+ },
94
+ desiredCapabilities: {
95
+ javascriptEnabled: true,
96
+ acceptSslCerts: true,
97
+ acceptInsecureCerts: true,
98
+ browserName: "chrome",
99
+ chromeOptions: {
100
+ args: [
101
+ "headless",
102
+ "disable-gpu",
103
+ "ignore-certificate-errors",
104
+ "no-sandbox",
105
+ "disable-features=NetworkService"
106
+ ],
107
+ binary: "/usr/bin/google-chrome"
108
+ }
109
+ }
110
+ }
111
+ },
112
+ globals: {
113
+ waitForConditionTimeout: 100000,
114
+ asyncHookTimeout: 1500000,
115
+ unitTestsTimeout: 100000,
116
+ customReporterCallbackTimeout: 100000,
117
+ retryAssertionTimeout: 50000
118
+ }
119
+ };
120
+ //@ts-ignore
121
+ if (process.platform === "win32" || process.platform === "win64") {
122
+ settings.test_settings["default"].desiredCapabilities.chromeOptions.binary =
123
+ "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
124
+ }
125
+ settings.webdriver.server_path = requireGlobal("chromedriver").path;
126
+ fs.writeFileSync(path.join(outputPath, "nightwatch.json"), JSON.stringify(settings));
127
+ }
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
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
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
+ }) : (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ o[k2] = m[k];
9
+ }));
10
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
12
+ }) : function(o, v) {
13
+ o["default"] = v;
14
+ });
15
+ var __importStar = (this && this.__importStar) || function (mod) {
16
+ if (mod && mod.__esModule) return mod;
17
+ var result = {};
18
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
+ __setModuleDefault(result, mod);
20
+ return result;
21
+ };
22
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
+ return new (P || (P = Promise))(function (resolve, reject) {
25
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
29
+ });
30
+ };
31
+ var __generator = (this && this.__generator) || function (thisArg, body) {
32
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
33
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
34
+ function verb(n) { return function (v) { return step([n, v]); }; }
35
+ function step(op) {
36
+ if (f) throw new TypeError("Generator is already executing.");
37
+ while (_) try {
38
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
39
+ if (y = 0, t) op = [op[0] & 2, t.value];
40
+ switch (op[0]) {
41
+ case 0: case 1: t = op; break;
42
+ case 4: _.label++; return { value: op[1], done: false };
43
+ case 5: _.label++; y = op[1]; op = [0]; continue;
44
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
45
+ default:
46
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
47
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
48
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
49
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
50
+ if (t[2]) _.ops.pop();
51
+ _.trys.pop(); continue;
52
+ }
53
+ op = body.call(thisArg, _);
54
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
55
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
56
+ }
57
+ };
58
+ var __importDefault = (this && this.__importDefault) || function (mod) {
59
+ return (mod && mod.__esModule) ? mod : { "default": mod };
60
+ };
61
+ exports.__esModule = true;
62
+ var path = __importStar(require("path"));
63
+ var helpers_1 = require("yargs/helpers");
64
+ var yargs_1 = __importDefault(require("yargs/yargs"));
65
+ var generator = __importStar(require("./generator"));
66
+ var nightwatch = __importStar(require("./nightwatch"));
67
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
68
+ var args, nbt, outputPath;
69
+ return __generator(this, function (_a) {
70
+ switch (_a.label) {
71
+ case 0: return [4 /*yield*/, (0, yargs_1["default"])((0, helpers_1.hideBin)(process.argv))
72
+ .option("config", {
73
+ alias: "c",
74
+ type: "string",
75
+ description: "select a config file",
76
+ "default": "nbt.json"
77
+ })
78
+ .option("port", {
79
+ alias: "p",
80
+ type: "number",
81
+ description: "select a port",
82
+ "default": 9515
83
+ }).argv];
84
+ case 1:
85
+ args = _a.sent();
86
+ nbt = require(path.join(process.cwd(), args.config));
87
+ outputPath = generator.generate(nbt.runners, nbt.additionalScripts, false, args.port);
88
+ nightwatch.runNightwatch(outputPath, path.resolve(nbt.testFolder));
89
+ return [2 /*return*/];
90
+ }
91
+ });
92
+ }); })();
@@ -0,0 +1,42 @@
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
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
+ }) : (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ o[k2] = m[k];
9
+ }));
10
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
12
+ }) : function(o, v) {
13
+ o["default"] = v;
14
+ });
15
+ var __importStar = (this && this.__importStar) || function (mod) {
16
+ if (mod && mod.__esModule) return mod;
17
+ var result = {};
18
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
+ __setModuleDefault(result, mod);
20
+ return result;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ exports.__esModule = true;
26
+ var express_1 = __importDefault(require("express"));
27
+ var express_http_proxy_1 = __importDefault(require("express-http-proxy"));
28
+ var path = __importStar(require("path"));
29
+ var generator = __importStar(require("./generator"));
30
+ var app = (0, express_1["default"])();
31
+ var nbt = require(path.join(process.cwd(), "nbt.json"));
32
+ var outputPath = generator.generate(nbt.runners, nbt.additionalScripts, true, 9515);
33
+ app.use("/test-browser", express_1["default"].static(outputPath));
34
+ app.use("/test", express_1["default"].static(path.resolve(nbt.testFolder)));
35
+ if (nbt.proxies) {
36
+ for (var _i = 0, _a = nbt.proxies; _i < _a.length; _i++) {
37
+ var proxy = _a[_i];
38
+ app.use(proxy.local, (0, express_http_proxy_1["default"])(proxy.remote));
39
+ }
40
+ }
41
+ console.log("Server Started. Open at http://localhost:7777/test-browser/index1.html.");
42
+ app.listen(7777, function () { });
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ exports.__esModule = true;
22
+ exports.runNightwatch = void 0;
23
+ var child_process = __importStar(require("child_process"));
24
+ var nightwatch = __importStar(require("nightwatch"));
25
+ var path = __importStar(require("path"));
26
+ var rimraf = require("rimraf");
27
+ function runNightwatch(tempFolder, testFolder) {
28
+ var httpServerProc = child_process.spawn("node", [__dirname + "/server.js", tempFolder, testFolder], {
29
+ stdio: "inherit"
30
+ });
31
+ nightwatch.cli(function (argv) {
32
+ argv.config = path.join(tempFolder, "nightwatch.json");
33
+ var runner = nightwatch.CliRunner(argv);
34
+ runner
35
+ .setup()
36
+ .startWebDriver()["catch"](function (err) {
37
+ console.error(err);
38
+ cleanup(httpServerProc, tempFolder);
39
+ })
40
+ .then(function () {
41
+ return runner.runTests();
42
+ })["catch"](function (err) {
43
+ console.error(err);
44
+ runner.processListener.setExitCode(10);
45
+ cleanup(httpServerProc, tempFolder);
46
+ })
47
+ .then(function () {
48
+ return runner.stopWebDriver();
49
+ })
50
+ .then(function () {
51
+ cleanup(httpServerProc, tempFolder);
52
+ })["catch"](function (err) {
53
+ console.error(err);
54
+ cleanup(httpServerProc, tempFolder);
55
+ });
56
+ });
57
+ }
58
+ exports.runNightwatch = runNightwatch;
59
+ function cleanup(httpServerProc, tempFolder) {
60
+ httpServerProc.kill("SIGINT");
61
+ rimraf.sync(tempFolder);
62
+ process.exit(0);
63
+ }
package/dist/server.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ var express_1 = __importDefault(require("express"));
7
+ var path = require("path");
8
+ var app = (0, express_1["default"])();
9
+ app.use("/test-browser", express_1["default"].static(process.argv[2]));
10
+ app.use("/test", express_1["default"].static(process.argv[3]));
11
+ var config = require(path.join(process.cwd(), "nbt.json"));
12
+ if (config && config.proxies) {
13
+ var httpproxy = require("express-http-proxy");
14
+ for (var _i = 0, _a = config.proxies; _i < _a.length; _i++) {
15
+ var proxy = _a[_i];
16
+ app.use(proxy.local, httpproxy(proxy.remote));
17
+ }
18
+ }
19
+ app.listen(7777, function () { });
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "bt-runner",
3
+ "version": "1.0.17",
4
+ "description": "",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/js-soft/docker-node-browsertests"
8
+ },
9
+ "license": "ISC",
10
+ "author": "js-soft <julian.koenig@js-soft.com> (https://www.js-soft.com/)",
11
+ "main": "index.js",
12
+ "bin": {
13
+ "browsertest-runner": "dist/index.js",
14
+ "browsertest-runner-debug": "dist/index_debug.js"
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "tmp"
19
+ ],
20
+ "scripts": {
21
+ "prepublishOnly": "tsc"
22
+ },
23
+ "dependencies": {
24
+ "chai": "^4.3.4",
25
+ "express": "^4.17.1",
26
+ "express-http-proxy": "^1.6.2",
27
+ "mocha": "^9.1.1",
28
+ "nightwatch": "^1.7.11",
29
+ "rimraf": "^3.0.2",
30
+ "yargs": "^17.1.1"
31
+ },
32
+ "devDependencies": {
33
+ "@types/express": "^4.17.13",
34
+ "@types/express-http-proxy": "^1.6.3",
35
+ "@types/express-serve-static-core": "^4.17.24",
36
+ "@types/node": "^16.9.4",
37
+ "@types/rimraf": "^3.0.2",
38
+ "@types/yargs": "^17.0.2"
39
+ },
40
+ "publishConfig": {
41
+ "registry": "https://registry.npmjs.org"
42
+ }
43
+ }
package/tmp/.gitkeep ADDED
File without changes