@brillout/test-e2e 0.1.21 → 0.1.22
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 +6 -6
- package/dist/Logs.js +9 -12
- package/dist/runTests.js +14 -7
- package/dist/setup.d.ts +1 -5
- package/dist/setup.js +11 -27
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/platform.d.ts +8 -0
- package/dist/utils/platform.js +24 -0
- package/package.json +1 -1
package/dist/Logs.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { expectError };
|
|
2
2
|
export declare const Logs: {
|
|
3
3
|
add: typeof add;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
flushLogs: typeof flushLogs;
|
|
5
|
+
clearLogs: typeof clearLogs;
|
|
6
|
+
hasErrorLogs: typeof hasErrorLogs;
|
|
7
7
|
flushEagerly: boolean;
|
|
8
8
|
};
|
|
9
9
|
declare type LogSource = 'stdout' | 'stderr' | 'Browser Error' | 'Browser Warning' | 'Browser Log' | 'Playwright' | 'run()' | 'run() failure' | 'test()' | 'Connection Error';
|
|
@@ -13,9 +13,9 @@ declare type LogEntry = {
|
|
|
13
13
|
logTimestamp: string;
|
|
14
14
|
isNotFailure: boolean;
|
|
15
15
|
};
|
|
16
|
-
declare function
|
|
17
|
-
declare function
|
|
18
|
-
declare function
|
|
16
|
+
declare function hasErrorLogs(onlyFailOnBrowserError?: boolean): boolean;
|
|
17
|
+
declare function clearLogs(): void;
|
|
18
|
+
declare function flushLogs(): void;
|
|
19
19
|
declare function add({ logSource, logText }: {
|
|
20
20
|
logSource: LogSource;
|
|
21
21
|
logText: string;
|
package/dist/Logs.js
CHANGED
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Logs = exports.expectError = void 0;
|
|
7
7
|
exports.Logs = {
|
|
8
8
|
add,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
flushLogs,
|
|
10
|
+
clearLogs,
|
|
11
|
+
hasErrorLogs,
|
|
12
12
|
flushEagerly: false,
|
|
13
13
|
};
|
|
14
14
|
const utils_1 = require("./utils");
|
|
@@ -16,8 +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
|
-
|
|
20
|
-
function hasError(onlyFailOnBrowserError = false) {
|
|
19
|
+
function hasErrorLogs(onlyFailOnBrowserError = false) {
|
|
21
20
|
const logErrors = logEntries.filter(({ logSource, isNotFailure }) => {
|
|
22
21
|
if (isNotFailure) {
|
|
23
22
|
return;
|
|
@@ -35,13 +34,12 @@ function hasError(onlyFailOnBrowserError = false) {
|
|
|
35
34
|
});
|
|
36
35
|
return logErrors.length > 0;
|
|
37
36
|
}
|
|
38
|
-
function
|
|
37
|
+
function clearLogs() {
|
|
39
38
|
logEntries = [];
|
|
40
|
-
logEntriesNotPrinted = [];
|
|
41
39
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
function flushLogs() {
|
|
41
|
+
logEntries.forEach((logEntry) => printLog(logEntry));
|
|
42
|
+
logEntries = [];
|
|
45
43
|
}
|
|
46
44
|
function add({ logSource, logText }) {
|
|
47
45
|
const logTimestamp = getTimestamp();
|
|
@@ -61,10 +59,9 @@ function add({ logSource, logText }) {
|
|
|
61
59
|
logTimestamp,
|
|
62
60
|
isNotFailure,
|
|
63
61
|
};
|
|
64
|
-
logEntriesNotPrinted.push(logEntry);
|
|
65
62
|
logEntries.push(logEntry);
|
|
66
63
|
if (exports.Logs.flushEagerly) {
|
|
67
|
-
|
|
64
|
+
flushLogs();
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
function expectError(logFilter) {
|
package/dist/runTests.js
CHANGED
|
@@ -35,7 +35,7 @@ async function runTests(browser) {
|
|
|
35
35
|
catch (err) {
|
|
36
36
|
logTestsResult(false);
|
|
37
37
|
console.log(err);
|
|
38
|
-
Logs_1.Logs.
|
|
38
|
+
Logs_1.Logs.flushLogs();
|
|
39
39
|
process.exit(1);
|
|
40
40
|
}
|
|
41
41
|
for (const { testDesc, testFn } of testInfo.tests) {
|
|
@@ -53,7 +53,7 @@ async function runTests(browser) {
|
|
|
53
53
|
}
|
|
54
54
|
done(!!err);
|
|
55
55
|
testInfo.afterEach(!!err);
|
|
56
|
-
const hasErrorLog = Logs_1.Logs.
|
|
56
|
+
const hasErrorLog = Logs_1.Logs.hasErrorLogs(testInfo.runInfo.onlyFailOnBrowserError);
|
|
57
57
|
const isFailure = err || hasErrorLog;
|
|
58
58
|
if (isFailure) {
|
|
59
59
|
logTestsResult(false);
|
|
@@ -63,19 +63,26 @@ async function runTests(browser) {
|
|
|
63
63
|
if (hasErrorLog) {
|
|
64
64
|
console.log(new Error(logsContainError_errMsg));
|
|
65
65
|
}
|
|
66
|
-
Logs_1.Logs.
|
|
66
|
+
Logs_1.Logs.flushLogs();
|
|
67
67
|
process.exit(1);
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
|
-
Logs_1.Logs.
|
|
70
|
+
Logs_1.Logs.clearLogs();
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
await testInfo.terminateServer();
|
|
74
74
|
await page.close();
|
|
75
75
|
// Handle case that an error occured during `terminateServer()`
|
|
76
|
-
if (Logs_1.Logs.
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
if (Logs_1.Logs.hasErrorLogs()) {
|
|
77
|
+
if ((0, utils_1.isWindows)()) {
|
|
78
|
+
// On Windows, the sever sometimes terminates with an exit code of `1`. I don't know why.
|
|
79
|
+
Logs_1.Logs.clearLogs();
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.log(new Error(logsContainError_errMsg));
|
|
83
|
+
Logs_1.Logs.flushLogs();
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
79
86
|
}
|
|
80
87
|
logTestsResult(true);
|
|
81
88
|
}
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sleep } from './utils';
|
|
1
|
+
import { sleep, isWindows, isLinux, isGithubAction, isMac } from './utils';
|
|
2
2
|
import fetch_ from 'node-fetch';
|
|
3
3
|
export { partRegex } from '@brillout/part-regex';
|
|
4
4
|
export { autoRetry };
|
|
@@ -31,7 +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 isWindows(): boolean;
|
|
35
|
-
declare function isLinux(): boolean;
|
|
36
|
-
declare function isMac(): boolean;
|
|
37
|
-
declare function isGithubAction(): boolean;
|
package/dist/setup.js
CHANGED
|
@@ -8,6 +8,10 @@ const child_process_1 = require("child_process");
|
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return utils_1.sleep; } });
|
|
11
|
+
Object.defineProperty(exports, "isWindows", { enumerable: true, get: function () { return utils_1.isWindows; } });
|
|
12
|
+
Object.defineProperty(exports, "isLinux", { enumerable: true, get: function () { return utils_1.isLinux; } });
|
|
13
|
+
Object.defineProperty(exports, "isGithubAction", { enumerable: true, get: function () { return utils_1.isGithubAction; } });
|
|
14
|
+
Object.defineProperty(exports, "isMac", { enumerable: true, get: function () { return utils_1.isMac; } });
|
|
11
15
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
12
16
|
const utils_2 = require("./utils");
|
|
13
17
|
const Logs_1 = require("./Logs");
|
|
@@ -26,8 +30,8 @@ var editFile_2 = require("./editFile");
|
|
|
26
30
|
Object.defineProperty(exports, "editFile", { enumerable: true, get: function () { return editFile_2.editFile; } });
|
|
27
31
|
Object.defineProperty(exports, "editFileRevert", { enumerable: true, get: function () { return editFile_2.editFileRevert; } });
|
|
28
32
|
const TIMEOUT_NPM_SCRIPT = 2 * 60 * 1000;
|
|
29
|
-
const TIMEOUT_TEST_FUNCTION = 60 * 1000 * (!isGithubAction() ? 1 : isWindows() ? 5 : 3);
|
|
30
|
-
const TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!isGithubAction() ? 1 : isLinux() ? 1 : 4);
|
|
33
|
+
const TIMEOUT_TEST_FUNCTION = 60 * 1000 * (!(0, utils_1.isGithubAction)() ? 1 : (0, utils_1.isWindows)() ? 5 : 3);
|
|
34
|
+
const TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!(0, utils_1.isGithubAction)() ? 1 : (0, utils_1.isLinux)() ? 1 : 4);
|
|
31
35
|
const TIMEOUT_AUTORETRY = TIMEOUT_TEST_FUNCTION / 2;
|
|
32
36
|
const TIMEOUT_PLAYWRIGHT = TIMEOUT_TEST_FUNCTION / 2;
|
|
33
37
|
function skip(reason) {
|
|
@@ -173,7 +177,7 @@ async function start() {
|
|
|
173
177
|
rejectServerStart(new Error(errMsg));
|
|
174
178
|
}, timeoutTotal);
|
|
175
179
|
// Kill any process that listens to port `3000`
|
|
176
|
-
if (!process.env.CI && isLinux()) {
|
|
180
|
+
if (!process.env.CI && (0, utils_1.isLinux)()) {
|
|
177
181
|
await (0, utils_1.runCommand)('fuser -k 3000/tcp', { swallowError: true, timeout: 10 * 1000 });
|
|
178
182
|
}
|
|
179
183
|
const { terminate, processHasExited } = execRunScript({
|
|
@@ -216,7 +220,7 @@ function stopProcess({ proc, cwd, cmd, signal, }) {
|
|
|
216
220
|
reject = _reject;
|
|
217
221
|
});
|
|
218
222
|
const onProcessClose = (code) => {
|
|
219
|
-
if (code === 0 || code === null || (code === 1 && isWindows())) {
|
|
223
|
+
if (code === 0 || code === null || (code === 1 && (0, utils_1.isWindows)())) {
|
|
220
224
|
resolve();
|
|
221
225
|
}
|
|
222
226
|
else {
|
|
@@ -225,7 +229,7 @@ function stopProcess({ proc, cwd, cmd, signal, }) {
|
|
|
225
229
|
};
|
|
226
230
|
proc.on('close', onProcessClose);
|
|
227
231
|
proc.on('exit', onProcessClose);
|
|
228
|
-
if (isWindows()) {
|
|
232
|
+
if ((0, utils_1.isWindows)()) {
|
|
229
233
|
// - https://github.com/nodejs/node/issues/3617#issuecomment-377731194
|
|
230
234
|
// - https://stackoverflow.com/questions/23706055/why-can-i-not-kill-my-child-process-in-nodejs-on-windows/28163919#28163919
|
|
231
235
|
(0, child_process_1.spawn)('taskkill', ['/pid', String(proc.pid), '/f', '/t'], {
|
|
@@ -268,7 +272,7 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
|
|
|
268
272
|
const { cwd, cmd } = getRunInfo();
|
|
269
273
|
let [command, ...args] = cmd.split(' ');
|
|
270
274
|
let detached = true;
|
|
271
|
-
if (isWindows()) {
|
|
275
|
+
if ((0, utils_1.isWindows)()) {
|
|
272
276
|
detached = false;
|
|
273
277
|
if (command === 'npm' || command === 'pnpm') {
|
|
274
278
|
command = command + '.cmd';
|
|
@@ -319,7 +323,7 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
|
|
|
319
323
|
procExited = true;
|
|
320
324
|
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
321
325
|
const exitIsPossible = onExit();
|
|
322
|
-
const isSuccessCode = [0, null].includes(code) || (isWindows() && code === 1);
|
|
326
|
+
const isSuccessCode = [0, null].includes(code) || ((0, utils_1.isWindows)() && code === 1);
|
|
323
327
|
const isExpected = isSuccessCode && exitIsPossible;
|
|
324
328
|
if (!isExpected) {
|
|
325
329
|
const errMsg = `Unexpected premature process termination, exit code: ${code}`;
|
|
@@ -444,26 +448,6 @@ function isMinNodeVersion(minNodeVersion) {
|
|
|
444
448
|
return major >= minNodeVersion;
|
|
445
449
|
}
|
|
446
450
|
exports.isMinNodeVersion = isMinNodeVersion;
|
|
447
|
-
function isWindows() {
|
|
448
|
-
return process.platform === 'win32';
|
|
449
|
-
}
|
|
450
|
-
exports.isWindows = isWindows;
|
|
451
|
-
function isLinux() {
|
|
452
|
-
return process.platform === 'linux';
|
|
453
|
-
}
|
|
454
|
-
exports.isLinux = isLinux;
|
|
455
|
-
function isMac() {
|
|
456
|
-
if (process.platform === 'darwin') {
|
|
457
|
-
return true;
|
|
458
|
-
}
|
|
459
|
-
(0, utils_2.assert)(isLinux() || isWindows());
|
|
460
|
-
return false;
|
|
461
|
-
}
|
|
462
|
-
exports.isMac = isMac;
|
|
463
|
-
function isGithubAction() {
|
|
464
|
-
return !!process.env.CI;
|
|
465
|
-
}
|
|
466
|
-
exports.isGithubAction = isGithubAction;
|
|
467
451
|
function getCwd() {
|
|
468
452
|
const { testFile } = (0, getCurrentTest_1.getCurrentTest)();
|
|
469
453
|
const cwd = (0, path_1.dirname)(testFile);
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMac = exports.isWindows = exports.isLinux = exports.isGithubAction = void 0;
|
|
4
|
+
const assert_1 = require("./assert");
|
|
5
|
+
function isWindows() {
|
|
6
|
+
return process.platform === 'win32';
|
|
7
|
+
}
|
|
8
|
+
exports.isWindows = isWindows;
|
|
9
|
+
function isLinux() {
|
|
10
|
+
return process.platform === 'linux';
|
|
11
|
+
}
|
|
12
|
+
exports.isLinux = isLinux;
|
|
13
|
+
function isMac() {
|
|
14
|
+
if (process.platform === 'darwin') {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
(0, assert_1.assert)(isLinux() || isWindows());
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
exports.isMac = isMac;
|
|
21
|
+
function isGithubAction() {
|
|
22
|
+
return !!process.env.CI;
|
|
23
|
+
}
|
|
24
|
+
exports.isGithubAction = isGithubAction;
|