bt-runner 1.0.20 → 2.0.0-beta.3

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
@@ -18,16 +18,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- exports.__esModule = true;
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
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];
23
+ const fs = __importStar(require("fs"));
24
+ const path = __importStar(require("path"));
25
+ function generate(runners, additionalScripts, debug = false, port) {
26
+ const outputPath = fs.mkdtempSync(path.join(__dirname, "..", "tmp", "browsertests-"));
27
+ let it = 1;
28
+ for (const runner of runners) {
31
29
  writeHtml(outputPath, it, runner.dependencies, additionalScripts, debug);
32
30
  if (!debug) {
33
31
  if (!runner.globals) {
@@ -44,17 +42,103 @@ function generate(runners, additionalScripts, debug, port) {
44
42
  }
45
43
  exports.generate = generate;
46
44
  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
45
+ const html = `<!DOCTYPE html>
46
+ <html>
47
+ <head>
48
+ <title>Mocha Tests</title>
49
+ </head>
50
+
51
+ <body>
52
+ <div id="mocha"></div>
53
+
54
+ ${debug
48
55
  ? ""
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);
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
+
67
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/7.2.0/mocha.min.js"></script>
68
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/chai/4.2.0/chai.min.js"></script>
69
+ <script>
70
+ mocha.setup("bdd")
71
+ mocha.reporter("spec")
72
+ </script>
73
+ <script>
74
+ ${additionalScripts ? additionalScripts.join("\n") : ""}
75
+ </script>
76
+
77
+ ${dependencies.map((dependency) => ` <script src="/test/${dependency}"></script>`).join("\n")}
78
+
79
+ <div id="main">Test</div>
80
+ </body>
81
+ </html>`;
82
+ fs.writeFileSync(path.join(outputPath, `index${iteration}.html`), html);
51
83
  }
52
84
  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 }"; })
85
+ const globalsString = globals
86
+ .map((glob) => `if (!window.${glob}) {
87
+ logs.push(["Required library '${glob}' not loaded. Aborting..."])
88
+ done({ failures: 1, logs: logs })
89
+ return
90
+ }`)
55
91
  .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);
92
+ const testContent = `const expect = require("chai").expect
93
+
94
+ describe("Browser Mocha Tests", function () {
95
+ beforeEach((client, done) => {
96
+ client.url("http://localhost:7777/test-browser/index${iteration}.html")
97
+ done()
98
+ })
99
+
100
+ after((client, done) => {
101
+ client.end(() => done())
102
+ })
103
+
104
+ it("Should run the Mocha tests without error", (client) => {
105
+ client.waitForElementVisible("#main")
106
+ client.timeoutsAsyncScript(1500000).executeAsync(
107
+ (_data, done) => {
108
+ const mocha = window.mocha
109
+
110
+ //add required test librarys in this if statement
111
+ if (!mocha) {
112
+ logs.push(["Required library 'mocha' not loaded. Aborting..."])
113
+ done({ failures: 1, logs: logs })
114
+ return
115
+ }
116
+
117
+ ${globalsString}
118
+
119
+ mocha.run(function (failures) {
120
+ done({ failures: failures, logs: logs })
121
+ })
122
+ },
123
+ [],
124
+ (result) => {
125
+ console.log("\\n--- browser mocha output ---")
126
+
127
+ if (result && result.value && result.value.logs) {
128
+ for (const logs of result.value.logs) {
129
+ console.log.apply(null, logs)
130
+ }
131
+ }
132
+
133
+ console.log("--- finished browser mocha output ---")
134
+
135
+ expect(result.value).to.not.be.undefined
136
+ expect(result.value.failures).to.equal(0)
137
+ }
138
+ )
139
+ })
140
+ })`;
141
+ fs.writeFileSync(path.join(outputPath, `mocha${iteration}.test.js`), testContent);
58
142
  }
59
143
  function requireGlobal(packageName) {
60
144
  var childProcess = require("child_process");
@@ -71,7 +155,7 @@ function requireGlobal(packageName) {
71
155
  return require(main);
72
156
  }
73
157
  function writeConfig(outputPath, port) {
74
- var settings = {
158
+ const settings = {
75
159
  src_folders: [outputPath],
76
160
  filter: "*.test.js",
77
161
  webdriver: {
@@ -87,7 +171,7 @@ function writeConfig(outputPath, port) {
87
171
  }
88
172
  },
89
173
  test_settings: {
90
- "default": {
174
+ default: {
91
175
  request_timeout_options: {
92
176
  timeout: 1500000
93
177
  },
@@ -96,13 +180,14 @@ function writeConfig(outputPath, port) {
96
180
  acceptSslCerts: true,
97
181
  acceptInsecureCerts: true,
98
182
  browserName: "chrome",
99
- chromeOptions: {
183
+ "goog:chromeOptions": {
184
+ w3c: true,
100
185
  args: [
101
- "headless",
102
- "disable-gpu",
103
- "ignore-certificate-errors",
104
- "no-sandbox",
105
- "disable-features=NetworkService"
186
+ "--headless",
187
+ "--disable-gpu",
188
+ "--ignore-certificate-errors",
189
+ "--no-sandbox",
190
+ "--disable-features=NetworkService"
106
191
  ],
107
192
  binary: "/usr/bin/google-chrome"
108
193
  }
@@ -119,9 +204,9 @@ function writeConfig(outputPath, port) {
119
204
  };
120
205
  //@ts-ignore
121
206
  if (process.platform === "win32" || process.platform === "win64") {
122
- settings.test_settings["default"].desiredCapabilities.chromeOptions.binary =
207
+ settings.test_settings.default.desiredCapabilities["goog:chromeOptions"].binary =
123
208
  "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
124
209
  }
125
210
  settings.webdriver.server_path = requireGlobal("chromedriver").path;
126
- fs.writeFileSync(path.join(outputPath, "nightwatch.json"), JSON.stringify(settings));
211
+ fs.writeFileSync(path.join(outputPath, `nightwatch.json`), JSON.stringify(settings));
127
212
  }
package/dist/index.js CHANGED
@@ -19,74 +19,52 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  __setModuleDefault(result, mod);
20
20
  return result;
21
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
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
59
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
60
24
  };
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
- }
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const child_process = __importStar(require("child_process"));
27
+ const Nightwatch = __importStar(require("nightwatch"));
28
+ const path = __importStar(require("path"));
29
+ const helpers_1 = require("yargs/helpers");
30
+ const yargs_1 = __importDefault(require("yargs/yargs"));
31
+ const generator = __importStar(require("./generator"));
32
+ const rimraf = require("rimraf");
33
+ Nightwatch.cli(async function (argv) {
34
+ const args = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
35
+ .option("config", {
36
+ alias: "c",
37
+ type: "string",
38
+ description: "select a config file",
39
+ default: "nbt.json"
40
+ })
41
+ .option("port", {
42
+ alias: "p",
43
+ type: "number",
44
+ description: "select a port",
45
+ default: 9515
46
+ }).argv;
47
+ const nbt = require(path.join(process.cwd(), args.config));
48
+ const tempFolder = generator.generate(nbt.runners, nbt.additionalScripts, false, args.port);
49
+ const testFolder = path.resolve(nbt.testFolder);
50
+ var httpServerProc = child_process.spawn("node", [`${__dirname}/server.js`, tempFolder, testFolder], {
51
+ stdio: "inherit"
91
52
  });
92
- }); })();
53
+ argv.config = path.join(tempFolder, "nightwatch.json");
54
+ const runner = Nightwatch.CliRunner(argv);
55
+ try {
56
+ await runner.setup({});
57
+ await runner.runTests();
58
+ }
59
+ catch (err) {
60
+ console.error("An error occurred:", err);
61
+ }
62
+ finally {
63
+ cleanup(httpServerProc, tempFolder);
64
+ }
65
+ });
66
+ function cleanup(httpServerProc, tempFolder) {
67
+ httpServerProc.kill("SIGINT");
68
+ rimraf.sync(tempFolder);
69
+ process.exit(0);
70
+ }
@@ -22,21 +22,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
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)));
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const express_1 = __importDefault(require("express"));
27
+ const express_http_proxy_1 = __importDefault(require("express-http-proxy"));
28
+ const path = __importStar(require("path"));
29
+ const generator = __importStar(require("./generator"));
30
+ const app = (0, express_1.default)();
31
+ const nbt = require(path.join(process.cwd(), "nbt.json"));
32
+ const 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
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));
36
+ for (const proxy of nbt.proxies) {
37
+ app.use(proxy.local, (0, express_http_proxy_1.default)(proxy.remote));
39
38
  }
40
39
  }
41
40
  console.log("Server Started. Open at http://localhost:7777/test-browser/index1.html.");
42
- app.listen(7777, function () { });
41
+ app.listen(7777, () => { });
@@ -23,9 +23,8 @@ exports.runNightwatch = void 0;
23
23
  var child_process = __importStar(require("child_process"));
24
24
  var nightwatch = __importStar(require("nightwatch"));
25
25
  var path = __importStar(require("path"));
26
- var rimraf = require("rimraf");
27
26
  function runNightwatch(tempFolder, testFolder) {
28
- var httpServerProc = child_process.spawn("node", [__dirname + "/server.js", tempFolder, testFolder], {
27
+ var httpServerProc = child_process.spawn("node", ["".concat(__dirname, "/server.js"), tempFolder, testFolder], {
29
28
  stdio: "inherit"
30
29
  });
31
30
  nightwatch.cli(function (argv) {
@@ -56,8 +55,3 @@ function runNightwatch(tempFolder, testFolder) {
56
55
  });
57
56
  }
58
57
  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 CHANGED
@@ -2,18 +2,17 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
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"));
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const express_1 = __importDefault(require("express"));
7
+ const path = require("path");
8
+ const 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
+ const config = require(path.join(process.cwd(), "nbt.json"));
12
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];
13
+ const httpproxy = require("express-http-proxy");
14
+ for (const proxy of config.proxies) {
16
15
  app.use(proxy.local, httpproxy(proxy.remote));
17
16
  }
18
17
  }
19
- app.listen(7777, function () { });
18
+ app.listen(7777, () => { });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bt-runner",
3
- "version": "1.0.20",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,19 +23,19 @@
23
23
  "dependencies": {
24
24
  "chai": "^4.3.4",
25
25
  "express": "^4.17.1",
26
- "express-http-proxy": "^1.6.2",
27
- "mocha": "^9.1.2",
28
- "nightwatch": "1.7.11",
26
+ "express-http-proxy": "^1.6.3",
27
+ "mocha": "^9.1.3",
28
+ "nightwatch": "^2.0.0-beta.1",
29
29
  "rimraf": "^3.0.2",
30
- "yargs": "^17.2.1"
30
+ "yargs": "^17.3.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/express": "^4.17.13",
34
34
  "@types/express-http-proxy": "^1.6.3",
35
- "@types/express-serve-static-core": "^4.17.24",
36
- "@types/node": "^16.10.3",
35
+ "@types/express-serve-static-core": "^4.17.26",
36
+ "@types/node": "^16.11.12",
37
37
  "@types/rimraf": "^3.0.2",
38
- "@types/yargs": "^17.0.3"
38
+ "@types/yargs": "^17.0.7"
39
39
  },
40
40
  "publishConfig": {
41
41
  "registry": "https://registry.npmjs.org"