@brillout/test-e2e 0.1.15 → 0.1.16

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
@@ -1,4 +1,4 @@
1
- export { expectBrowserError };
1
+ export { expectError };
2
2
  export declare const Logs: {
3
3
  add: typeof add;
4
4
  flush: typeof flush;
@@ -11,7 +11,7 @@ declare type LogEntry = {
11
11
  logSource: LogSource;
12
12
  logText: string;
13
13
  logTimestamp: string;
14
- isExpectedError: boolean;
14
+ isNotFailure: boolean;
15
15
  };
16
16
  declare function hasError(onlyFailOnBrowserError: boolean): boolean;
17
17
  declare function clear(): void;
@@ -20,4 +20,4 @@ declare function add({ logSource, logText }: {
20
20
  logSource: LogSource;
21
21
  logText: string;
22
22
  }): void;
23
- declare function expectBrowserError(browserLogFilter: (browserLog: LogEntry) => boolean): void;
23
+ declare function expectError(logFilter: (browserLog: LogEntry) => boolean): void;
package/dist/Logs.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.Logs = exports.expectBrowserError = void 0;
6
+ exports.Logs = exports.expectError = void 0;
7
7
  exports.Logs = {
8
8
  add,
9
9
  flush,
@@ -14,11 +14,12 @@ exports.Logs = {
14
14
  const utils_1 = require("./utils");
15
15
  const picocolors_1 = __importDefault(require("picocolors"));
16
16
  const getCurrentTest_1 = require("./getCurrentTest");
17
+ const getConfig_1 = require("./getConfig");
17
18
  let logEntries = [];
18
19
  let logEntriesNotPrinted = [];
19
20
  function hasError(onlyFailOnBrowserError) {
20
- const logErrors = logEntries.filter(({ logSource, isExpectedError }) => {
21
- if (isExpectedError) {
21
+ const logErrors = logEntries.filter(({ logSource, isNotFailure }) => {
22
+ if (isNotFailure) {
22
23
  return;
23
24
  }
24
25
  if (!onlyFailOnBrowserError && (logSource === 'Browser Warning' || logSource === 'stderr')) {
@@ -41,11 +42,21 @@ function flush() {
41
42
  }
42
43
  function add({ logSource, logText }) {
43
44
  const logTimestamp = getTimestamp();
45
+ const isNotFailure = (() => {
46
+ const config = (0, getConfig_1.getConfig)();
47
+ if (!config.tolerateError) {
48
+ return false;
49
+ }
50
+ return config.tolerateError({
51
+ logSource,
52
+ logText,
53
+ });
54
+ })();
44
55
  const logEntry = {
45
56
  logSource,
46
57
  logText,
47
58
  logTimestamp,
48
- isExpectedError: false,
59
+ isNotFailure,
49
60
  };
50
61
  logEntriesNotPrinted.push(logEntry);
51
62
  logEntries.push(logEntry);
@@ -53,18 +64,18 @@ function add({ logSource, logText }) {
53
64
  flush();
54
65
  }
55
66
  }
56
- function expectBrowserError(browserLogFilter) {
57
- const found = !!logEntries.find((logEntry) => {
58
- if (browserLogFilter(logEntry)) {
59
- logEntry.isExpectedError = true;
67
+ function expectError(logFilter) {
68
+ const logFounds = logEntries.filter((logEntry) => {
69
+ if (logFilter(logEntry)) {
70
+ logEntry.isNotFailure = true;
60
71
  return true;
61
72
  }
62
73
  return false;
63
74
  });
64
- //expect(found).toBe(true)
65
- (0, utils_1.assert)(found === true);
75
+ //expect(logFounds.length).not.toBe(0)
76
+ (0, utils_1.assert)(logFounds.length > 0);
66
77
  }
67
- exports.expectBrowserError = expectBrowserError;
78
+ exports.expectError = expectError;
68
79
  function getTimestamp() {
69
80
  const now = new Date();
70
81
  const time = now.toTimeString().split(' ')[0];
@@ -1,3 +1,4 @@
1
+ /// <reference types="chai-subset" />
1
2
  export type { ChaiPlugin };
2
3
  export type { Expect };
3
4
  import type { use as chaiUse } from 'chai';
@@ -0,0 +1,7 @@
1
+ export { getConfig };
2
+ export { loadConfig };
3
+ declare type Config = {
4
+ tolerateError?: Function;
5
+ };
6
+ declare function getConfig(): Config;
7
+ declare function loadConfig(): Promise<void>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadConfig = exports.getConfig = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const utils_1 = require("./utils");
10
+ const configFileName = 'test-e2e.config.mjs';
11
+ const errPrefix = `Config file \`${configFileName}\` `;
12
+ let config = null;
13
+ function getConfig() {
14
+ (0, utils_1.assert)(config);
15
+ return config;
16
+ }
17
+ exports.getConfig = getConfig;
18
+ async function loadConfig() {
19
+ const configFilePath = find();
20
+ (0, utils_1.assertUsage)(configFilePath, errPrefix + 'not found');
21
+ const configFileExports = (await import(configFilePath));
22
+ (0, utils_1.assertUsage)('default' in configFileExports, errPrefix + 'should have a default export');
23
+ assertConfig(configFileExports.default);
24
+ config = configFileExports.default;
25
+ }
26
+ exports.loadConfig = loadConfig;
27
+ function assertConfig(config) {
28
+ (0, utils_1.assertUsage)((0, utils_1.isObject)(config), errPrefix + 'default export should be an object');
29
+ if ('tolerateError' in config) {
30
+ (0, utils_1.assertUsage)((0, utils_1.isCallable)(config.tolerateError), errPrefix + '`tolerateError` should be a function');
31
+ }
32
+ }
33
+ function find() {
34
+ let curr = process.cwd();
35
+ do {
36
+ const dir = path_1.default.dirname(curr);
37
+ if (dir === curr) {
38
+ return null;
39
+ }
40
+ const configFilePath = path_1.default.join(dir, configFileName);
41
+ if (fs_1.default.existsSync(configFilePath)) {
42
+ return configFilePath;
43
+ }
44
+ curr = dir;
45
+ } while (true);
46
+ }
@@ -7,7 +7,9 @@ const runTests_1 = require("./runTests");
7
7
  const getBrowser_1 = require("./getBrowser");
8
8
  const buildTs_1 = require("./buildTs");
9
9
  const findTestFiles_1 = require("./findTestFiles");
10
+ const getConfig_1 = require("./getConfig");
10
11
  async function runTestSuites(filter) {
12
+ await (0, getConfig_1.loadConfig)();
11
13
  const testFiles = await (0, findTestFiles_1.findTestFiles)(filter);
12
14
  const browser = await (0, getBrowser_1.getBrowser)();
13
15
  for (const testFile of testFiles) {
package/dist/setup.d.ts CHANGED
@@ -4,7 +4,7 @@ export { partRegex } from '@brillout/part-regex';
4
4
  export { autoRetry };
5
5
  export { fetchHtml };
6
6
  export { fetch };
7
- export { expectBrowserError } from './Logs';
7
+ export { expectError } from './Logs';
8
8
  export { run };
9
9
  export { skip };
10
10
  export { isMinNodeVersion };
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.expectBrowserError = 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");
@@ -18,7 +18,7 @@ const page_1 = require("./page");
18
18
  var part_regex_1 = require("@brillout/part-regex");
19
19
  Object.defineProperty(exports, "partRegex", { enumerable: true, get: function () { return part_regex_1.partRegex; } });
20
20
  var Logs_2 = require("./Logs");
21
- Object.defineProperty(exports, "expectBrowserError", { enumerable: true, get: function () { return Logs_2.expectBrowserError; } });
21
+ Object.defineProperty(exports, "expectError", { enumerable: true, get: function () { return Logs_2.expectError; } });
22
22
  exports.urlBase = 'http://localhost:3000';
23
23
  const urlBaseChange = (url) => (exports.urlBase = url);
24
24
  exports.urlBaseChange = urlBaseChange;
@@ -83,7 +83,15 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
83
83
  page_1.page.off('pageerror', onPageError);
84
84
  // `runProcess` is `undefined` if `start()` failed.
85
85
  if (runProcess) {
86
- await runProcess.terminate('SIGINT');
86
+ try {
87
+ await runProcess.terminate('SIGINT');
88
+ }
89
+ catch (err) {
90
+ Logs_1.Logs.add({
91
+ logSource: 'run()',
92
+ logText: String(err),
93
+ });
94
+ }
87
95
  }
88
96
  };
89
97
  return;
@@ -231,7 +239,19 @@ function stopProcess({ proc, cwd, cmd, signal, }) {
231
239
  if (isWindows()) {
232
240
  // - https://github.com/nodejs/node/issues/3617#issuecomment-377731194
233
241
  // - https://stackoverflow.com/questions/23706055/why-can-i-not-kill-my-child-process-in-nodejs-on-windows/28163919#28163919
234
- (0, child_process_1.spawn)('taskkill', ['/pid', String(proc.pid), '/f', '/t'], { stdio: ['ignore', 'ignore', 'inherit'] });
242
+ (0, child_process_1.spawn)('taskkill', ['/pid', String(proc.pid), '/f', '/t'], {
243
+ stdio: [
244
+ 'ignore',
245
+ 'ignore',
246
+ // Should we ignore `stderr`? Because `taskkill` somtimes throws:
247
+ // ```
248
+ // ERROR: The process with PID 6052 (child process of PID 3184) could not be terminated.
249
+ // Reason: There is no running instance of the task.
250
+ // ```
251
+ // There doesn't seem to be an option to suppress that error: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill#parameters
252
+ 'inherit', // stderr
253
+ ],
254
+ });
235
255
  }
236
256
  else {
237
257
  (0, utils_2.assert)(proc.pid);
@@ -7,3 +7,5 @@ export * from './findFiles';
7
7
  export * from './logProgress';
8
8
  export * from './cliConfig';
9
9
  export * from './fsWindowsBugWorkaround';
10
+ export * from './isObject';
11
+ export * from './isCallable';
@@ -23,3 +23,5 @@ __exportStar(require("./findFiles"), exports);
23
23
  __exportStar(require("./logProgress"), exports);
24
24
  __exportStar(require("./cliConfig"), exports);
25
25
  __exportStar(require("./fsWindowsBugWorkaround"), exports);
26
+ __exportStar(require("./isObject"), exports);
27
+ __exportStar(require("./isCallable"), exports);
@@ -0,0 +1 @@
1
+ export declare function isCallable<T extends Function>(thing: T | unknown): thing is T;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCallable = void 0;
4
+ function isCallable(thing) {
5
+ return thing instanceof Function || typeof thing === 'function';
6
+ }
7
+ exports.isCallable = isCallable;
@@ -0,0 +1 @@
1
+ export declare function isObject(value: unknown): value is Record<string | symbol, unknown>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isObject = void 0;
4
+ function isObject(value) {
5
+ return typeof value === 'object' && value !== null;
6
+ }
7
+ exports.isObject = isObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {