@brillout/test-e2e 0.1.22 → 0.2.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/cli.js CHANGED
@@ -7,8 +7,10 @@ const source_map_support_1 = __importDefault(require("source-map-support"));
7
7
  const utils_1 = require("./utils");
8
8
  const runTestSuites_1 = require("./runTestSuites");
9
9
  const buildTs_1 = require("./buildTs");
10
+ const Logs_1 = require("./Logs");
10
11
  initSourceMap();
11
12
  initPromiseRejectionHandler();
13
+ initUserExitHandler();
12
14
  cli();
13
15
  function cli() {
14
16
  const filter = (0, utils_1.findFilesParseCliArgs)();
@@ -20,6 +22,11 @@ function initPromiseRejectionHandler() {
20
22
  process.exit(1);
21
23
  });
22
24
  }
25
+ function initUserExitHandler() {
26
+ process.on('SIGINT', function () {
27
+ Logs_1.Logs.flushLogs();
28
+ });
29
+ }
23
30
  function initSourceMap() {
24
31
  source_map_support_1.default.install({
25
32
  retrieveSourceMap: function (source) {
@@ -18,6 +18,7 @@ declare type TestInfo = {
18
18
  serverIsReadyDelay: number;
19
19
  inspect: boolean;
20
20
  onlyFailOnBrowserError: boolean;
21
+ serverUrl: string;
21
22
  };
22
23
  hasStartedRunning?: boolean;
23
24
  skipped?: string;
package/dist/runTests.js CHANGED
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.runTests = void 0;
4
7
  const getCurrentTest_1 = require("./getCurrentTest");
5
8
  const Logs_1 = require("./Logs");
6
9
  const utils_1 = require("./utils");
7
- const picocolors_1 = require("picocolors");
8
- const logsContainError_errMsg = 'The browser/server threw/logged one or more error/warning, see logs below.';
10
+ const picocolors_1 = __importDefault(require("picocolors"));
11
+ const logsContainError_errMsg = (isTermination) => [picocolors_1.default.bold('Encountered an error or warning'), !isTermination ? '' : ' during termination', ', see logs below.'].join('');
9
12
  async function runTests(browser) {
10
13
  const testInfo = (0, getCurrentTest_1.getCurrentTest)();
11
14
  if (utils_1.isTTY) {
@@ -61,7 +64,7 @@ async function runTests(browser) {
61
64
  console.error(err);
62
65
  }
63
66
  if (hasErrorLog) {
64
- console.log(new Error(logsContainError_errMsg));
67
+ console.log(logsContainError_errMsg(false));
65
68
  }
66
69
  Logs_1.Logs.flushLogs();
67
70
  process.exit(1);
@@ -79,7 +82,7 @@ async function runTests(browser) {
79
82
  Logs_1.Logs.clearLogs();
80
83
  }
81
84
  else {
82
- console.log(new Error(logsContainError_errMsg));
85
+ console.log(logsContainError_errMsg(true));
83
86
  Logs_1.Logs.flushLogs();
84
87
  process.exit(1);
85
88
  }
@@ -114,18 +117,18 @@ function runTest(testFn, testFunctionTimeout) {
114
117
  }
115
118
  function logTestsResult(success) {
116
119
  const testInfo = (0, getCurrentTest_1.getCurrentTest)();
117
- const passStyle = (t) => (0, picocolors_1.bold)((0, picocolors_1.white)((0, picocolors_1.bgGreen)(t)));
118
- const failStyle = (t) => (0, picocolors_1.bold)((0, picocolors_1.white)((0, picocolors_1.bgRed)(t)));
119
- const skipStyle = (t) => (0, picocolors_1.bold)((0, picocolors_1.white)((0, picocolors_1.bgYellow)(t)));
120
+ const passStyle = (t) => picocolors_1.default.bold(picocolors_1.default.bgGreen(t));
121
+ const failStyle = (t) => picocolors_1.default.bold(picocolors_1.default.bgRed(t));
122
+ const skipStyle = (t) => picocolors_1.default.bold(picocolors_1.default.bgYellow(t));
120
123
  if (success) {
121
124
  (0, utils_1.assert)(!testInfo.skipped);
122
- console.log(`${passStyle('PASS')} ${testInfo.testFile}`);
125
+ console.log(`${passStyle(' PASS ')} ${testInfo.testFile}`);
123
126
  return;
124
127
  }
125
128
  if (testInfo.skipped) {
126
- console.log(`${skipStyle('WARN')} ${testInfo.testFile} (${testInfo.skipped})`);
129
+ console.log(`${skipStyle(' WARN ')} ${testInfo.testFile} (${testInfo.skipped})`);
127
130
  }
128
131
  else {
129
- console.log(`${failStyle('FAIL')} ${testInfo.testFile}`);
132
+ console.log(`${failStyle(' FAIL ')} ${testInfo.testFile}`);
130
133
  }
131
134
  }
package/dist/setup.d.ts CHANGED
@@ -13,17 +13,17 @@ export { isLinux };
13
13
  export { isWindows };
14
14
  export { isMac };
15
15
  export { sleep };
16
- export declare let urlBase: string;
17
- export declare const urlBaseChange: (url: string) => string;
16
+ export { getServerUrl };
18
17
  export { editFile, editFileRevert } from './editFile';
19
18
  declare function skip(reason: string): void;
20
- declare function run(cmd: string, { additionalTimeout, serverIsReadyMessage, serverIsReadyDelay, inspect, cwd, onlyFailOnBrowserError, }?: {
19
+ declare function run(cmd: string, { additionalTimeout, serverIsReadyMessage, serverIsReadyDelay, inspect, cwd, onlyFailOnBrowserError, serverUrl, }?: {
21
20
  additionalTimeout?: number;
22
21
  serverIsReadyMessage?: string;
23
22
  serverIsReadyDelay?: number;
24
23
  inspect?: boolean;
25
24
  cwd?: string;
26
25
  onlyFailOnBrowserError?: boolean;
26
+ serverUrl?: string;
27
27
  }): void;
28
28
  declare function autoRetry(test: () => void | Promise<void>, { timeout }?: {
29
29
  timeout?: number;
@@ -31,3 +31,4 @@ declare function autoRetry(test: () => void | Promise<void>, { timeout }?: {
31
31
  declare function fetchHtml(pathname: string): Promise<string>;
32
32
  declare function fetch(...args: Parameters<typeof fetch_>): Promise<import("node-fetch").Response>;
33
33
  declare function isMinNodeVersion(minNodeVersion: 14): boolean;
34
+ declare function getServerUrl(): string;
package/dist/setup.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.editFileRevert = exports.editFile = exports.urlBaseChange = exports.urlBase = exports.sleep = exports.isMac = exports.isWindows = exports.isLinux = exports.isGithubAction = exports.isMinNodeVersion = exports.skip = exports.run = exports.expectError = exports.fetch = exports.fetchHtml = exports.autoRetry = exports.partRegex = void 0;
6
+ exports.editFileRevert = exports.editFile = exports.getServerUrl = exports.sleep = exports.isMac = exports.isWindows = exports.isLinux = exports.isGithubAction = exports.isMinNodeVersion = exports.skip = exports.run = exports.expectError = exports.fetch = exports.fetchHtml = exports.autoRetry = exports.partRegex = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const path_1 = require("path");
9
9
  const utils_1 = require("./utils");
@@ -23,12 +23,10 @@ var part_regex_1 = require("@brillout/part-regex");
23
23
  Object.defineProperty(exports, "partRegex", { enumerable: true, get: function () { return part_regex_1.partRegex; } });
24
24
  var Logs_2 = require("./Logs");
25
25
  Object.defineProperty(exports, "expectError", { enumerable: true, get: function () { return Logs_2.expectError; } });
26
- exports.urlBase = 'http://localhost:3000';
27
- const urlBaseChange = (url) => (exports.urlBase = url);
28
- exports.urlBaseChange = urlBaseChange;
29
26
  var editFile_2 = require("./editFile");
30
27
  Object.defineProperty(exports, "editFile", { enumerable: true, get: function () { return editFile_2.editFile; } });
31
28
  Object.defineProperty(exports, "editFileRevert", { enumerable: true, get: function () { return editFile_2.editFileRevert; } });
29
+ const serverUrlDefault = 'http://localhost:3000';
32
30
  const TIMEOUT_NPM_SCRIPT = 2 * 60 * 1000;
33
31
  const TIMEOUT_TEST_FUNCTION = 60 * 1000 * (!(0, utils_1.isGithubAction)() ? 1 : (0, utils_1.isWindows)() ? 5 : 3);
34
32
  const TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!(0, utils_1.isGithubAction)() ? 1 : (0, utils_1.isLinux)() ? 1 : 4);
@@ -41,7 +39,7 @@ function skip(reason) {
41
39
  exports.skip = skip;
42
40
  function run(cmd, {
43
41
  //baseUrl = '',
44
- additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = utils_1.cliConfig.inspect, cwd, onlyFailOnBrowserError = false, } = {}) {
42
+ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = utils_1.cliConfig.inspect, cwd, onlyFailOnBrowserError = false, serverUrl = serverUrlDefault, } = {}) {
45
43
  additionalTimeout += serverIsReadyDelay;
46
44
  const testInfo = (0, getCurrentTest_1.getCurrentTest)();
47
45
  testInfo.runInfo = {
@@ -53,6 +51,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
53
51
  serverIsReadyDelay,
54
52
  inspect,
55
53
  onlyFailOnBrowserError,
54
+ serverUrl,
56
55
  };
57
56
  if (inspect) {
58
57
  Logs_1.Logs.flushEagerly = true;
@@ -176,9 +175,11 @@ async function start() {
176
175
  await terminate();
177
176
  rejectServerStart(new Error(errMsg));
178
177
  }, timeoutTotal);
179
- // Kill any process that listens to port `3000`
178
+ // Kill any process that listens to the server port
180
179
  if (!process.env.CI && (0, utils_1.isLinux)()) {
181
- await (0, utils_1.runCommand)('fuser -k 3000/tcp', { swallowError: true, timeout: 10 * 1000 });
180
+ const port = getPort();
181
+ (0, utils_2.assert)(/\d+/.test(port));
182
+ await (0, utils_1.runCommand)(`fuser -k ${port}/tcp`, { swallowError: true, timeout: 10 * 1000 });
182
183
  }
183
184
  const { terminate, processHasExited } = execRunScript({
184
185
  async onFailure(err) {
@@ -401,7 +402,7 @@ async function autoRetry(test, { timeout = TIMEOUT_AUTORETRY } = {}) {
401
402
  }
402
403
  exports.autoRetry = autoRetry;
403
404
  async function fetchHtml(pathname) {
404
- const response = await fetch(exports.urlBase + pathname);
405
+ const response = await fetch(getServerUrl() + pathname);
405
406
  const html = await response.text();
406
407
  return html;
407
408
  }
@@ -453,3 +454,15 @@ function getCwd() {
453
454
  const cwd = (0, path_1.dirname)(testFile);
454
455
  return cwd;
455
456
  }
457
+ function getServerUrl() {
458
+ const testInfo = (0, getCurrentTest_1.getCurrentTest)();
459
+ const serverUrl = testInfo.runInfo?.serverUrl;
460
+ return serverUrl;
461
+ }
462
+ exports.getServerUrl = getServerUrl;
463
+ function getPort() {
464
+ const serverUrl = getServerUrl();
465
+ const port = serverUrl.split(':').slice(-1)[0].split('/')[0];
466
+ (0, utils_2.assert)(/\d+/.test(port), { serverUrl });
467
+ return port;
468
+ }
@@ -1,6 +1,6 @@
1
1
  export { runCommand };
2
- declare function runCommand(cmd: string, { swallowError, timeout, cwd }?: {
3
- swallowError?: true;
2
+ declare function runCommand(cmd: string, { swallowError, timeout, cwd, }?: {
3
+ swallowError?: boolean;
4
4
  timeout?: number;
5
5
  cwd?: string;
6
6
  }): Promise<string>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCommand = void 0;
4
4
  const child_process_1 = require("child_process");
5
- function runCommand(cmd, { swallowError, timeout = 5000, cwd } = {}) {
5
+ function runCommand(cmd, { swallowError = false, timeout = 5000, cwd = process.cwd(), } = {}) {
6
6
  const { promise, resolvePromise } = genPromise();
7
7
  const t = setTimeout(() => {
8
8
  console.error(`Command call \`${cmd}\` timeout [${timeout / 1000} seconds][${cwd}].`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.1.22",
3
+ "version": "0.2.0",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {