@brillout/test-e2e 0.2.1 → 0.2.2

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/Logs.d.ts CHANGED
@@ -13,7 +13,7 @@ declare type LogEntry = {
13
13
  logTimestamp: string;
14
14
  isNotFailure: boolean;
15
15
  };
16
- declare function hasErrorLogs(onlyFailOnBrowserError?: boolean): boolean;
16
+ declare function hasErrorLogs(doNotFailOnWarning?: boolean): boolean;
17
17
  declare function clearLogs(): void;
18
18
  declare function flushLogs(): void;
19
19
  declare function add({ logSource, logText }: {
package/dist/Logs.js CHANGED
@@ -16,7 +16,7 @@ const picocolors_1 = __importDefault(require("picocolors"));
16
16
  const getCurrentTest_1 = require("./getCurrentTest");
17
17
  const getConfig_1 = require("./getConfig");
18
18
  let logEntries = [];
19
- function hasErrorLogs(onlyFailOnBrowserError = false) {
19
+ function hasErrorLogs(doNotFailOnWarning = false) {
20
20
  const logErrors = logEntries.filter(({ logSource, isNotFailure }) => {
21
21
  if (isNotFailure) {
22
22
  return;
@@ -24,7 +24,7 @@ function hasErrorLogs(onlyFailOnBrowserError = false) {
24
24
  if (logSource === 'run() failure') {
25
25
  return true;
26
26
  }
27
- if (!onlyFailOnBrowserError && (logSource === 'Browser Warning' || logSource === 'stderr')) {
27
+ if (!doNotFailOnWarning && (logSource === 'Browser Warning' || logSource === 'stderr')) {
28
28
  return true;
29
29
  }
30
30
  if (logSource === 'Browser Error') {
@@ -1,4 +1,3 @@
1
- /// <reference types="chai-subset" />
2
1
  export type { ChaiPlugin };
3
2
  export type { Expect };
4
3
  import type { use as chaiUse } from 'chai';
package/dist/cli.js CHANGED
@@ -7,10 +7,8 @@ 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");
11
10
  initSourceMap();
12
11
  initPromiseRejectionHandler();
13
- initUserExitHandler();
14
12
  cli();
15
13
  function cli() {
16
14
  const filter = (0, utils_1.findFilesParseCliArgs)();
@@ -22,11 +20,6 @@ function initPromiseRejectionHandler() {
22
20
  process.exit(1);
23
21
  });
24
22
  }
25
- function initUserExitHandler() {
26
- process.on('SIGINT', function () {
27
- Logs_1.Logs.flushLogs();
28
- });
29
- }
30
23
  function initSourceMap() {
31
24
  source_map_support_1.default.install({
32
25
  retrieveSourceMap: function (source) {
@@ -14,11 +14,10 @@ declare type TestInfo = {
14
14
  cwd: string;
15
15
  testFunctionTimeout: number;
16
16
  additionalTimeout: number;
17
- serverIsReadyMessage?: string | ((log: string) => boolean);
17
+ serverIsReadyMessage?: string;
18
18
  serverIsReadyDelay: number;
19
19
  inspect: boolean;
20
- onlyFailOnBrowserError: boolean;
21
- serverUrl: string;
20
+ doNotFailOnWarning: boolean;
22
21
  };
23
22
  hasStartedRunning?: boolean;
24
23
  skipped?: string;
package/dist/runTests.js CHANGED
@@ -8,7 +8,7 @@ const getCurrentTest_1 = require("./getCurrentTest");
8
8
  const Logs_1 = require("./Logs");
9
9
  const utils_1 = require("./utils");
10
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('');
11
+ const logsContainError_errMsg = (isTermination) => [picocolors_1.default.bold('Error/warning'), !isTermination ? '' : ' during termination', ', see logs below.'].join(' ');
12
12
  async function runTests(browser) {
13
13
  const testInfo = (0, getCurrentTest_1.getCurrentTest)();
14
14
  if (utils_1.isTTY) {
@@ -56,7 +56,7 @@ async function runTests(browser) {
56
56
  }
57
57
  done(!!err);
58
58
  testInfo.afterEach(!!err);
59
- const hasErrorLog = Logs_1.Logs.hasErrorLogs(testInfo.runInfo.onlyFailOnBrowserError);
59
+ const hasErrorLog = Logs_1.Logs.hasErrorLogs(testInfo.runInfo.doNotFailOnWarning);
60
60
  const isFailure = err || hasErrorLog;
61
61
  if (isFailure) {
62
62
  logTestsResult(false);
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 { getServerUrl };
16
+ export declare let urlBase: string;
17
+ export declare const urlBaseChange: (url: string) => string;
17
18
  export { editFile, editFileRevert } from './editFile';
18
19
  declare function skip(reason: string): void;
19
- declare function run(cmd: string, { additionalTimeout, serverIsReadyMessage, serverIsReadyDelay, inspect, cwd, onlyFailOnBrowserError, serverUrl, }?: {
20
+ declare function run(cmd: string, { additionalTimeout, serverIsReadyMessage, serverIsReadyDelay, inspect, cwd, doNotFailOnWarning, }?: {
20
21
  additionalTimeout?: number;
21
- serverIsReadyMessage?: string | ((log: string) => boolean);
22
+ serverIsReadyMessage?: string;
22
23
  serverIsReadyDelay?: number;
23
24
  inspect?: boolean;
24
25
  cwd?: string;
25
- onlyFailOnBrowserError?: boolean;
26
- serverUrl?: string;
26
+ doNotFailOnWarning?: boolean;
27
27
  }): void;
28
28
  declare function autoRetry(test: () => void | Promise<void>, { timeout }?: {
29
29
  timeout?: number;
@@ -31,4 +31,3 @@ 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.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;
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;
7
7
  const child_process_1 = require("child_process");
8
8
  const path_1 = require("path");
9
9
  const utils_1 = require("./utils");
@@ -23,10 +23,12 @@ 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;
26
29
  var editFile_2 = require("./editFile");
27
30
  Object.defineProperty(exports, "editFile", { enumerable: true, get: function () { return editFile_2.editFile; } });
28
31
  Object.defineProperty(exports, "editFileRevert", { enumerable: true, get: function () { return editFile_2.editFileRevert; } });
29
- const serverUrlDefault = 'http://localhost:3000';
30
32
  const TIMEOUT_NPM_SCRIPT = 2 * 60 * 1000;
31
33
  const TIMEOUT_TEST_FUNCTION = 60 * 1000 * (!(0, utils_1.isGithubAction)() ? 1 : (0, utils_1.isWindows)() ? 5 : 3);
32
34
  const TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!(0, utils_1.isGithubAction)() ? 1 : (0, utils_1.isLinux)() ? 1 : 4);
@@ -39,7 +41,7 @@ function skip(reason) {
39
41
  exports.skip = skip;
40
42
  function run(cmd, {
41
43
  //baseUrl = '',
42
- additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = utils_1.cliConfig.inspect, cwd, onlyFailOnBrowserError = false, serverUrl = serverUrlDefault, } = {}) {
44
+ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = utils_1.cliConfig.inspect, cwd, doNotFailOnWarning = false, } = {}) {
43
45
  additionalTimeout += serverIsReadyDelay;
44
46
  const testInfo = (0, getCurrentTest_1.getCurrentTest)();
45
47
  testInfo.runInfo = {
@@ -50,8 +52,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
50
52
  serverIsReadyMessage,
51
53
  serverIsReadyDelay,
52
54
  inspect,
53
- onlyFailOnBrowserError,
54
- serverUrl,
55
+ doNotFailOnWarning,
55
56
  };
56
57
  if (inspect) {
57
58
  Logs_1.Logs.flushEagerly = true;
@@ -67,7 +68,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
67
68
  /*
68
69
  await bailOnTimeout(
69
70
  async () => {
70
- await page.goto(getServerUrl() + baseUrl)
71
+ await page.goto(urlBase + baseUrl)
71
72
  },
72
73
  { timeout: TIMEOUT_PAGE_LOAD + additionalTimeout },
73
74
  )
@@ -175,11 +176,9 @@ async function start() {
175
176
  await terminate();
176
177
  rejectServerStart(new Error(errMsg));
177
178
  }, timeoutTotal);
178
- // Kill any process that listens to the server port
179
+ // Kill any process that listens to port `3000`
179
180
  if (!process.env.CI && (0, utils_1.isLinux)()) {
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 });
181
+ await (0, utils_1.runCommand)('fuser -k 3000/tcp', { swallowError: true, timeout: 10 * 1000 });
183
182
  }
184
183
  const { terminate, processHasExited } = execRunScript({
185
184
  async onFailure(err) {
@@ -195,8 +194,7 @@ async function start() {
195
194
  const text = (0, strip_ansi_1.default)(data);
196
195
  const isServerReady =
197
196
  // Custom
198
- (typeof serverIsReadyMessage === 'string' && text.includes(serverIsReadyMessage)) ||
199
- ((0, utils_1.isCallable)(serverIsReadyMessage) && serverIsReadyMessage(text)) ||
197
+ (serverIsReadyMessage && text.includes(serverIsReadyMessage)) ||
200
198
  // Express.js server
201
199
  text.includes('Server running at') ||
202
200
  // npm package `serve`
@@ -403,7 +401,7 @@ async function autoRetry(test, { timeout = TIMEOUT_AUTORETRY } = {}) {
403
401
  }
404
402
  exports.autoRetry = autoRetry;
405
403
  async function fetchHtml(pathname) {
406
- const response = await fetch(getServerUrl() + pathname);
404
+ const response = await fetch(exports.urlBase + pathname);
407
405
  const html = await response.text();
408
406
  return html;
409
407
  }
@@ -455,15 +453,3 @@ function getCwd() {
455
453
  const cwd = (0, path_1.dirname)(testFile);
456
454
  return cwd;
457
455
  }
458
- function getServerUrl() {
459
- const testInfo = (0, getCurrentTest_1.getCurrentTest)();
460
- const serverUrl = testInfo.runInfo?.serverUrl;
461
- return serverUrl;
462
- }
463
- exports.getServerUrl = getServerUrl;
464
- function getPort() {
465
- const serverUrl = getServerUrl();
466
- const port = serverUrl.split(':').slice(-1)[0].split('/')[0];
467
- (0, utils_2.assert)(/\d+/.test(port), { serverUrl });
468
- return port;
469
- }
@@ -1 +1 @@
1
- export declare function isCallable(thing: unknown): thing is Function;
1
+ export declare function isCallable<T extends Function>(thing: T | unknown): thing is T;
@@ -1,6 +1,6 @@
1
1
  export { runCommand };
2
- declare function runCommand(cmd: string, { swallowError, timeout, cwd, }?: {
3
- swallowError?: boolean;
2
+ declare function runCommand(cmd: string, { swallowError, timeout, cwd }?: {
3
+ swallowError?: true;
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 = false, timeout = 5000, cwd = process.cwd(), } = {}) {
5
+ function runCommand(cmd, { swallowError, timeout = 5000, 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.2.1",
3
+ "version": "0.2.2",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {