@brillout/test-e2e 0.5.7 → 0.5.9

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
@@ -25,4 +25,4 @@ declare function add({ logSource, logText, loggedAfterExit, }: {
25
25
  logText: string;
26
26
  loggedAfterExit?: boolean;
27
27
  }): void;
28
- declare function expectError(logFilter: (browserLog: LogEntry) => boolean): void;
28
+ declare function expectError(userFilter: (logEntry: LogEntry) => boolean): void;
package/dist/Logs.js CHANGED
@@ -17,6 +17,7 @@ const picocolors_1 = __importDefault(require("picocolors"));
17
17
  const getCurrentTest_1 = require("./getCurrentTest");
18
18
  const logSection_1 = require("./logSection");
19
19
  const isTolerateError_1 = require("./Logs/isTolerateError");
20
+ const expect_1 = require("./chai/expect");
20
21
  let logEntries = [];
21
22
  function hasFailLogs(failOnWarning) {
22
23
  const failLogs = getErrorLogs(failOnWarning);
@@ -74,16 +75,15 @@ function add({ logSource, logText, loggedAfterExit = false, }) {
74
75
  printLog(logEntry);
75
76
  }
76
77
  }
77
- function expectError(logFilter) {
78
+ function expectError(userFilter) {
78
79
  const logFounds = logEntries.filter((logEntry) => {
79
- if (logFilter(logEntry)) {
80
+ if (userFilter(logEntry)) {
80
81
  logEntry.isNotFailure = true;
81
82
  return true;
82
83
  }
83
84
  return false;
84
85
  });
85
- //expect(logFounds.length).not.toBe(0)
86
- (0, utils_1.assert)(logFounds.length > 0);
86
+ (0, expect_1.expect)(logFounds.length).not.toBe(0);
87
87
  }
88
88
  exports.expectError = expectError;
89
89
  function getTimestamp() {
@@ -0,0 +1,5 @@
1
+ export declare const TIMEOUT_NPM_SCRIPT: number;
2
+ export declare const TIMEOUT_TEST_FUNCTION: number;
3
+ export declare const TIMEOUT_PROCESS_TERMINATION: number;
4
+ export declare const TIMEOUT_AUTORETRY: number;
5
+ export declare const TIMEOUT_PLAYWRIGHT: number;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TIMEOUT_PLAYWRIGHT = exports.TIMEOUT_AUTORETRY = exports.TIMEOUT_PROCESS_TERMINATION = exports.TIMEOUT_TEST_FUNCTION = exports.TIMEOUT_NPM_SCRIPT = void 0;
4
+ const platform_1 = require("./utils/platform");
5
+ exports.TIMEOUT_NPM_SCRIPT = 2 * 60 * 1000 * (!(0, platform_1.isCI)() ? 1 : (0, platform_1.isWindows)() ? 2 : 1);
6
+ exports.TIMEOUT_TEST_FUNCTION = 60 * 1000 * (!(0, platform_1.isCI)() ? 1 : (0, platform_1.isWindows)() ? 5 : 3);
7
+ exports.TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!(0, platform_1.isCI)() ? 1 : (0, platform_1.isWindows)() ? 3 : !(0, platform_1.isLinux)() ? 3 : 1);
8
+ exports.TIMEOUT_AUTORETRY = exports.TIMEOUT_TEST_FUNCTION / 2;
9
+ exports.TIMEOUT_PLAYWRIGHT = exports.TIMEOUT_TEST_FUNCTION / 2;
@@ -0,0 +1,4 @@
1
+ export { autoRetry };
2
+ declare function autoRetry(test: () => void | Promise<void>, { timeout }?: {
3
+ timeout?: number;
4
+ }): Promise<void>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.autoRetry = void 0;
4
+ const TIMEOUTS_1 = require("./TIMEOUTS");
5
+ const utils_1 = require("./utils");
6
+ async function autoRetry(test, { timeout = TIMEOUTS_1.TIMEOUT_AUTORETRY } = {}) {
7
+ const period = 100;
8
+ const numberOfTries = timeout / period;
9
+ let i = 0;
10
+ while (true) {
11
+ try {
12
+ await test();
13
+ return;
14
+ }
15
+ catch (err) {
16
+ i = i + 1;
17
+ if (i > numberOfTries) {
18
+ throw err;
19
+ }
20
+ }
21
+ await (0, utils_1.sleep)(period);
22
+ }
23
+ }
24
+ exports.autoRetry = autoRetry;
package/dist/buildTs.js CHANGED
@@ -17,7 +17,7 @@ async function buildTs(entry, outfile) {
17
17
  outfile,
18
18
  logLevel: 'warning',
19
19
  format: 'esm',
20
- target: 'es2020',
20
+ target: 'es2022',
21
21
  bundle: true,
22
22
  packages: 'external',
23
23
  minify: false,
package/dist/cli.js CHANGED
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ /* Track down log origins
3
+ import './utils/trackLogs'
4
+ //*/
2
5
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
6
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
7
  };
@@ -27,6 +30,7 @@ function initUserExitHandler() {
27
30
  Logs_1.Logs.flushLogs();
28
31
  });
29
32
  }
33
+ // Much simpler alternative: https://github.com/brillout/vite-plugin-ssr/blob/77b1b0e8b6c1ed4efe3e3039f7c0b23a00651663/vite-plugin-ssr/node/plugin/plugins/importUserCode/v1-design/transpileAndLoadFile.ts#L200-L208
30
34
  function initSourceMap() {
31
35
  source_map_support_1.default.install({
32
36
  retrieveSourceMap: function (source) {
@@ -1,6 +1,9 @@
1
1
  export { getCurrentTest };
2
2
  export { getCurrentTestOptional };
3
3
  export { setCurrentTest };
4
+ export { getRunInfo };
5
+ export { setRunInfo };
6
+ export { getCwd };
4
7
  export type { TestInfo };
5
8
  import type { Page } from 'playwright-chromium';
6
9
  declare type TestInfo = {
@@ -10,17 +13,18 @@ declare type TestInfo = {
10
13
  testDesc: string;
11
14
  testFn: Function;
12
15
  }[];
16
+ testOptions?: {
17
+ doNotFailOnWarning: boolean;
18
+ testFunctionTimeout: number;
19
+ isFlaky: boolean;
20
+ };
13
21
  runInfo?: {
14
22
  cmd: string;
15
- cwd: string;
16
- testFunctionTimeout: number;
17
- additionalTimeout: number;
18
- serverIsReadyMessage?: string | ((log: string) => boolean);
19
- serverIsReadyDelay: number;
20
- inspect: boolean;
21
- doNotFailOnWarning: boolean;
22
23
  serverUrl: string;
24
+ doNotFailOnWarning: boolean;
25
+ testFunctionTimeout: number;
23
26
  isFlaky: boolean;
27
+ isRunCommandThatTerminates: boolean;
24
28
  };
25
29
  hasStartedRunning?: boolean;
26
30
  skipped?: {
@@ -34,3 +38,20 @@ declare type TestInfo = {
34
38
  declare function getCurrentTest(): TestInfo;
35
39
  declare function getCurrentTestOptional(): null | TestInfo;
36
40
  declare function setCurrentTest(testFile: null | string): void;
41
+ declare function getRunInfo(): {
42
+ cmd: string;
43
+ serverUrl: string;
44
+ doNotFailOnWarning: boolean;
45
+ testFunctionTimeout: number;
46
+ isFlaky: boolean;
47
+ isRunCommandThatTerminates: boolean;
48
+ };
49
+ declare function setRunInfo({ cmd, serverUrl, additionalTimeout, doNotFailOnWarning, isFlaky, isRunCommandThatTerminates, }: {
50
+ cmd: string;
51
+ serverUrl?: string;
52
+ additionalTimeout?: number;
53
+ doNotFailOnWarning?: boolean;
54
+ isFlaky?: boolean;
55
+ isRunCommandThatTerminates?: boolean;
56
+ }): void;
57
+ declare function getCwd(): string;
@@ -3,9 +3,10 @@ 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.setCurrentTest = exports.getCurrentTestOptional = exports.getCurrentTest = void 0;
6
+ exports.getCwd = exports.setRunInfo = exports.getRunInfo = exports.setCurrentTest = exports.getCurrentTestOptional = exports.getCurrentTest = void 0;
7
7
  const utils_1 = require("./utils");
8
8
  const path_1 = __importDefault(require("path"));
9
+ const TIMEOUTS_1 = require("./TIMEOUTS");
9
10
  let testInfo = null;
10
11
  function getCurrentTest() {
11
12
  (0, utils_1.assert)(testInfo);
@@ -42,3 +43,29 @@ function removeRootDir(filePath) {
42
43
  (0, utils_1.assert)(filePath.startsWith(rootDir));
43
44
  return filePath.slice(rootDir.length);
44
45
  }
46
+ function getRunInfo() {
47
+ const testInfo = getCurrentTest();
48
+ (0, utils_1.assert)(testInfo.runInfo);
49
+ return testInfo.runInfo;
50
+ }
51
+ exports.getRunInfo = getRunInfo;
52
+ const serverUrlDefault = 'http://localhost:3000';
53
+ function setRunInfo({ cmd, serverUrl = serverUrlDefault, additionalTimeout = 0, doNotFailOnWarning = false, isFlaky = false, isRunCommandThatTerminates = false, }) {
54
+ const testInfo = getCurrentTest();
55
+ const testFunctionTimeout = TIMEOUTS_1.TIMEOUT_TEST_FUNCTION + additionalTimeout;
56
+ testInfo.runInfo = {
57
+ cmd,
58
+ serverUrl,
59
+ testFunctionTimeout,
60
+ doNotFailOnWarning,
61
+ isFlaky,
62
+ isRunCommandThatTerminates,
63
+ };
64
+ }
65
+ exports.setRunInfo = setRunInfo;
66
+ function getCwd() {
67
+ const { testFile } = getCurrentTest();
68
+ const cwd = path_1.default.dirname(testFile);
69
+ return cwd;
70
+ }
71
+ exports.getCwd = getCwd;
@@ -1,8 +1,10 @@
1
1
  export { logPass };
2
2
  export { logWarn };
3
3
  export { logFail };
4
+ export { logBoot };
4
5
  export { hasFail };
5
6
  declare function logPass(): void;
6
7
  declare function logWarn(warning: string): void;
7
8
  declare function logFail(reason: string, isFinalAttempt: boolean): void;
9
+ declare function logBoot(): void;
8
10
  declare function hasFail(): boolean;
@@ -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.hasFail = exports.logFail = exports.logWarn = exports.logPass = void 0;
6
+ exports.hasFail = exports.logBoot = exports.logFail = exports.logWarn = exports.logPass = void 0;
7
7
  const getCurrentTest_1 = require("./getCurrentTest");
8
8
  const utils_1 = require("./utils");
9
9
  const picocolors_1 = __importDefault(require("picocolors"));
@@ -47,8 +47,18 @@ function getStatusTags() {
47
47
  const PASS = picocolors_1.default.bold(picocolors_1.default.white(picocolors_1.default.bgGreen(' PASS ')));
48
48
  const FAIL = picocolors_1.default.bold(picocolors_1.default.white(picocolors_1.default.bgRed(' FAIL ')));
49
49
  const WARN = picocolors_1.default.bold(picocolors_1.default.white(picocolors_1.default.bgYellow(' WARN ')));
50
- return { PASS, FAIL, WARN };
50
+ const BOOT = picocolors_1.default.bold(picocolors_1.default.white(picocolors_1.default.bgBlack(' BOOT ')));
51
+ return { PASS, FAIL, WARN, BOOT };
51
52
  }
53
+ function logBoot() {
54
+ if (!utils_1.isTTY)
55
+ return;
56
+ const { testFile } = (0, getCurrentTest_1.getCurrentTest)();
57
+ const { BOOT } = getStatusTags();
58
+ console.log();
59
+ console.log(`${BOOT} ${testFile}`);
60
+ }
61
+ exports.logBoot = logBoot;
52
62
  let hasFailLog = false;
53
63
  function hasFail() {
54
64
  return hasFailLog;
package/dist/runAll.js CHANGED
@@ -59,25 +59,48 @@ async function buildAndTest(testFile, browser, isSecondAttempt) {
59
59
  (0, utils_1.assert)(testFileJs.endsWith('.mjs'));
60
60
  const cleanBuild = await (0, buildTs_1.buildTs)(testFile, testFileJs);
61
61
  (0, getCurrentTest_2.setCurrentTest)(testFile);
62
+ (0, logTestStatus_1.logBoot)();
63
+ let execErr;
62
64
  try {
63
65
  await import((0, utils_2.fsWindowsBugWorkaround)(testFileJs) + `?cacheBuster=${Date.now()}`);
64
66
  }
67
+ catch (err) {
68
+ (0, utils_1.assert)(err);
69
+ execErr = err;
70
+ }
65
71
  finally {
66
72
  cleanBuild();
67
73
  }
74
+ if (execErr) {
75
+ (0, logTestStatus_1.logFail)(`an error was thrown while executing the file ${testFile}`, true);
76
+ (0, logError_1.logError)(execErr);
77
+ return false;
78
+ }
79
+ // When user calls run runCommandThatTerminates()
80
+ {
81
+ const testInfo = (0, getCurrentTest_1.getCurrentTest)();
82
+ // Set when user calls run() or runCommandThatTerminates()
83
+ (0, utils_1.assert)(testInfo.runInfo);
84
+ if (testInfo.runInfo.isRunCommandThatTerminates) {
85
+ (0, utils_1.assertUsage)(!testInfo.tests, "Can't call test() when calling runCommandThatTerminates()");
86
+ (0, utils_1.assertUsage)(!testInfo.startServer, "Can't call run() when calling runCommandThatTerminates()");
87
+ (0, logTestStatus_1.logPass)();
88
+ return true;
89
+ }
90
+ }
68
91
  const success = await runServerAndTests(browser, isSecondAttempt);
69
92
  (0, getCurrentTest_2.setCurrentTest)(null);
70
93
  return success;
71
94
  }
72
95
  async function runServerAndTests(browser, isSecondAttempt) {
73
96
  const testInfo = (0, getCurrentTest_1.getCurrentTest)();
74
- // Set when user calls `skip()`
97
+ // Set when user calls skip()
75
98
  if (testInfo.skipped) {
76
99
  assertSkipUsage(testInfo);
77
100
  (0, logTestStatus_1.logWarn)(testInfo.skipped.reason);
78
101
  return true;
79
102
  }
80
- // Set when user calls `run()`
103
+ // Set when user calls run()
81
104
  (0, utils_1.assert)(testInfo.runInfo);
82
105
  (0, utils_1.assert)(testInfo.startServer);
83
106
  (0, utils_1.assert)(testInfo.terminateServer);
@@ -120,21 +143,20 @@ async function runServerAndTests(browser, isSecondAttempt) {
120
143
  return success;
121
144
  }
122
145
  async function runTests(testInfo, isFinalAttempt) {
123
- if (utils_1.isTTY) {
124
- console.log();
125
- console.log(testInfo.testFile);
126
- }
127
146
  // Set when user calls `run()`
128
147
  (0, utils_1.assert)(testInfo.runInfo);
129
148
  (0, utils_1.assert)(testInfo.afterEach);
130
- // Set when user calls `test()`
131
- (0, utils_1.assert)(testInfo.tests);
132
- for (const { testDesc, testFn } of testInfo.tests) {
149
+ const tests =
150
+ // Set when user calls test()
151
+ testInfo.tests ??
152
+ // When user hasn't any test() call
153
+ [];
154
+ for (const { testDesc, testFn } of tests) {
133
155
  Logs_1.Logs.add({
134
156
  logSource: 'test()',
135
157
  logText: testDesc,
136
158
  });
137
- const done = (0, utils_1.logProgress)(`| [test] ${testDesc}`);
159
+ const done = (0, utils_1.logProgress)(`[test] ${testDesc}`);
138
160
  let err;
139
161
  try {
140
162
  await runTest(testFn, testInfo.runInfo.testFunctionTimeout);
@@ -0,0 +1,4 @@
1
+ export { runCommandThatTerminates };
2
+ declare function runCommandThatTerminates(cmd: string, { timeout }?: {
3
+ timeout?: number;
4
+ }): Promise<void>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCommandThatTerminates = void 0;
4
+ const getCurrentTest_1 = require("./getCurrentTest");
5
+ const utils_1 = require("./utils");
6
+ async function runCommandThatTerminates(cmd, { timeout = 2 * 60 * 1000 } = {}) {
7
+ (0, getCurrentTest_1.setRunInfo)({ cmd, isRunCommandThatTerminates: true });
8
+ const cwd = (0, getCurrentTest_1.getCwd)();
9
+ await (0, utils_1.runCommand)(cmd, { timeout, cwd });
10
+ }
11
+ exports.runCommandThatTerminates = runCommandThatTerminates;
package/dist/setup.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { sleep, isWindows, isLinux, isCI, isMac } from './utils';
2
- import fetch_ from 'node-fetch';
3
1
  export { partRegex } from '@brillout/part-regex';
4
- export { autoRetry };
2
+ export { autoRetry } from './autoRetry';
5
3
  export { fetchHtml };
6
4
  export { fetch };
7
5
  export { expectError } from './Logs';
@@ -14,20 +12,21 @@ export { isWindows };
14
12
  export { isMac };
15
13
  export { sleep };
16
14
  export { getServerUrl };
15
+ export { runCommandThatTerminates } from './runCommandThatTerminates';
16
+ import { sleep, isWindows, isLinux, isCI, isMac } from './utils';
17
+ import fetch_ from 'node-fetch';
17
18
  declare function skip(reason: string): void;
18
19
  declare function run(cmd: string, { additionalTimeout, serverIsReadyMessage, serverIsReadyDelay, inspect, cwd, doNotFailOnWarning, serverUrl, isFlaky, }?: {
19
20
  additionalTimeout?: number;
20
21
  serverIsReadyMessage?: string | ((log: string) => boolean);
21
22
  serverIsReadyDelay?: number;
22
23
  inspect?: boolean;
24
+ /** deprecated */
23
25
  cwd?: string;
24
26
  doNotFailOnWarning?: boolean;
25
27
  serverUrl?: string;
26
28
  isFlaky?: boolean;
27
29
  }): void;
28
- declare function autoRetry(test: () => void | Promise<void>, { timeout }?: {
29
- timeout?: number;
30
- }): Promise<void>;
31
30
  declare function fetchHtml(pathname: string): Promise<string>;
32
31
  declare function fetch(...args: Parameters<typeof fetch_>): Promise<import("node-fetch").Response>;
33
32
  declare function isMinNodeVersion(minNodeVersion: 14): boolean;