@brillout/test-e2e 0.6.11 → 0.6.12
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 +5 -2
- package/dist/Logs.js +22 -10
- package/dist/getCurrentTest.d.ts +1 -0
- package/dist/runAll.js +28 -13
- package/dist/utils/cliOptions.js +1 -2
- package/package.json +1 -1
package/dist/Logs.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const Logs: {
|
|
|
4
4
|
flushLogs: typeof flushLogs;
|
|
5
5
|
logErrorsAndWarnings: typeof logErrorsAndWarnings;
|
|
6
6
|
clearLogs: typeof clearLogs;
|
|
7
|
-
|
|
7
|
+
hasFailureLog: typeof hasFailureLog;
|
|
8
8
|
logEagerly: false | "all" | "logs";
|
|
9
9
|
};
|
|
10
10
|
export type { LogSource };
|
|
@@ -17,7 +17,10 @@ type LogEntry = {
|
|
|
17
17
|
isNotFailure: boolean;
|
|
18
18
|
loggedAfterExit: boolean;
|
|
19
19
|
};
|
|
20
|
-
declare function
|
|
20
|
+
declare function hasFailureLog({ includeBrowserWarnings, includeStderr, }: {
|
|
21
|
+
includeBrowserWarnings: boolean;
|
|
22
|
+
includeStderr: boolean;
|
|
23
|
+
}): boolean;
|
|
21
24
|
declare function clearLogs(): void;
|
|
22
25
|
declare function logErrorsAndWarnings(): void;
|
|
23
26
|
declare function flushLogs(): void;
|
package/dist/Logs.js
CHANGED
|
@@ -4,10 +4,10 @@ export const Logs = {
|
|
|
4
4
|
flushLogs,
|
|
5
5
|
logErrorsAndWarnings,
|
|
6
6
|
clearLogs,
|
|
7
|
-
|
|
7
|
+
hasFailureLog,
|
|
8
8
|
logEagerly: false,
|
|
9
9
|
};
|
|
10
|
-
import { assert, cliOptions, ensureNewTerminalLine, isWindows } from './utils.js';
|
|
10
|
+
import { assert, cliOptions, ensureNewTerminalLine, isCI, isWindows } from './utils.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
12
12
|
import { getCurrentTest, getCurrentTestOptional } from './getCurrentTest.js';
|
|
13
13
|
import { logSection } from './logSection.js';
|
|
@@ -15,11 +15,11 @@ import { isTolerateError } from './Logs/isTolerateError.js';
|
|
|
15
15
|
import stripAnsi from 'strip-ansi';
|
|
16
16
|
let logEntries = [];
|
|
17
17
|
const logEntriesAll = [];
|
|
18
|
-
function
|
|
19
|
-
const failLogs = getErrorLogs(
|
|
18
|
+
function hasFailureLog({ includeBrowserWarnings, includeStderr, }) {
|
|
19
|
+
const failLogs = getErrorLogs({ includeBrowserWarnings, includeStderr });
|
|
20
20
|
return failLogs.length > 0;
|
|
21
21
|
}
|
|
22
|
-
function getErrorLogs(
|
|
22
|
+
function getErrorLogs({ includeBrowserWarnings, includeStderr, }) {
|
|
23
23
|
const errorLogs = logEntries.filter((logEntry) => {
|
|
24
24
|
if (logEntry.isNotFailure) {
|
|
25
25
|
return false;
|
|
@@ -32,7 +32,10 @@ function getErrorLogs(includeWarnings) {
|
|
|
32
32
|
if (logSource === 'run() failure') {
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
35
|
+
if (logSource === 'Browser Warning' && includeBrowserWarnings) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (logSource === 'stderr' && includeStderr) {
|
|
36
39
|
return true;
|
|
37
40
|
}
|
|
38
41
|
if (logSource === 'Browser Error') {
|
|
@@ -46,7 +49,7 @@ function clearLogs() {
|
|
|
46
49
|
logEntries = [];
|
|
47
50
|
}
|
|
48
51
|
function logErrorsAndWarnings() {
|
|
49
|
-
const errorAndWarningLogs = getErrorLogs(true);
|
|
52
|
+
const errorAndWarningLogs = getErrorLogs({ includeBrowserWarnings: true, includeStderr: true });
|
|
50
53
|
if (errorAndWarningLogs.length === 0)
|
|
51
54
|
return;
|
|
52
55
|
logSection('ERROR & WARNING LOGS');
|
|
@@ -79,14 +82,19 @@ function add({ logSource, logText, logInfo = '', loggedAfterExit = false, }) {
|
|
|
79
82
|
printLog(logEntry);
|
|
80
83
|
}
|
|
81
84
|
if (logSource === 'Browser Error' || logSource === 'stderr') {
|
|
82
|
-
terminateUponErrorLog();
|
|
85
|
+
terminateUponErrorLog(logSource);
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
|
-
async function terminateUponErrorLog() {
|
|
86
|
-
|
|
88
|
+
async function terminateUponErrorLog(logSource) {
|
|
89
|
+
const shouldBail = cliOptions.bail || (logSource === 'Browser Error' && !isCI());
|
|
90
|
+
if (!shouldBail)
|
|
87
91
|
return;
|
|
88
92
|
const testInfo = getCurrentTest();
|
|
93
|
+
// Skip bailing upon stderr logs while spinning up the server
|
|
94
|
+
if (logSource === 'stderr' && !testInfo.isTestFunctionRunning)
|
|
95
|
+
return;
|
|
89
96
|
testInfo.aborted = true;
|
|
97
|
+
assert(Logs.hasFailureLog({ includeBrowserWarnings: false, includeStderr: true }));
|
|
90
98
|
// Trick to abort the test: page.close() triggers the following error.
|
|
91
99
|
// ```console
|
|
92
100
|
// proxy.waitForFunction: Target closed
|
|
@@ -97,6 +105,10 @@ async function terminateUponErrorLog() {
|
|
|
97
105
|
// }
|
|
98
106
|
// ```
|
|
99
107
|
await testInfo.page.close();
|
|
108
|
+
/* The trick above doesn't always work, and the following doesn't seem to make a difference.
|
|
109
|
+
const browser = await getBrowser()
|
|
110
|
+
await browser.close()
|
|
111
|
+
*/
|
|
100
112
|
}
|
|
101
113
|
/**
|
|
102
114
|
* Expect a log to be printed.
|
package/dist/getCurrentTest.d.ts
CHANGED
package/dist/runAll.js
CHANGED
|
@@ -11,15 +11,14 @@ import { loadConfig } from './getConfig.js';
|
|
|
11
11
|
import { logError } from './logError.js';
|
|
12
12
|
import { hasFail, logBoot, logFail, logPass, logWarn, TEST_FAIL } from './logTestStatus.js';
|
|
13
13
|
import pc from '@brillout/picocolors';
|
|
14
|
-
let browser;
|
|
15
14
|
async function runAll(filter) {
|
|
16
15
|
await loadConfig();
|
|
17
16
|
const testFiles = await findTestFiles(filter);
|
|
18
|
-
browser = await getBrowser();
|
|
17
|
+
const browser = await getBrowser();
|
|
19
18
|
const failedTestFiles = await runTestFiles(testFiles, browser);
|
|
20
|
-
await closeAll(failedTestFiles);
|
|
19
|
+
await closeAll(failedTestFiles, browser);
|
|
21
20
|
}
|
|
22
|
-
async function closeAll(failedTestFiles) {
|
|
21
|
+
async function closeAll(failedTestFiles, browser) {
|
|
23
22
|
await browser.close();
|
|
24
23
|
const hasFailedTestFile = failedTestFiles.length > 0;
|
|
25
24
|
const hasFailLog = hasFail();
|
|
@@ -42,7 +41,7 @@ async function runTestFiles(testFiles, browser) {
|
|
|
42
41
|
if (!isFlaky) {
|
|
43
42
|
doNotRetry = true;
|
|
44
43
|
}
|
|
45
|
-
if (cliOptions.bail) {
|
|
44
|
+
if (cliOptions.bail || !isCI()) {
|
|
46
45
|
return failedTestFiles;
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -146,7 +145,7 @@ async function closeTest(testInfo, success, isFinalAttempt) {
|
|
|
146
145
|
// Check whether stderr emitted during testInfo.terminateServer()
|
|
147
146
|
if (success) {
|
|
148
147
|
const failOnWarning = true;
|
|
149
|
-
if (Logs.
|
|
148
|
+
if (Logs.hasFailureLog({ includeBrowserWarnings: failOnWarning, includeStderr: failOnWarning }) &&
|
|
150
149
|
// See comments about taskkill in src/utils/runCommandLongRunning.ts
|
|
151
150
|
!isWindows()) {
|
|
152
151
|
logFailure(null, `${getErrorType(failOnWarning)} occurred during server termination`, isFinalAttempt);
|
|
@@ -169,6 +168,7 @@ async function runTests(testInfo, isFinalAttempt) {
|
|
|
169
168
|
// When user hasn't any test() call
|
|
170
169
|
[];
|
|
171
170
|
for (const { testDesc, testFn } of tests) {
|
|
171
|
+
testInfo.isTestFunctionRunning = true;
|
|
172
172
|
Logs.add({
|
|
173
173
|
logSource: 'test()',
|
|
174
174
|
logText: testDesc,
|
|
@@ -185,23 +185,38 @@ async function runTests(testInfo, isFinalAttempt) {
|
|
|
185
185
|
testInfo.afterEach(!!err);
|
|
186
186
|
{
|
|
187
187
|
const failOnWarning = !testInfo.runInfo.doNotFailOnWarning;
|
|
188
|
-
const
|
|
189
|
-
|
|
188
|
+
const isFailureFromLogs = Logs.hasFailureLog({
|
|
189
|
+
includeBrowserWarnings: failOnWarning,
|
|
190
|
+
includeStderr: failOnWarning,
|
|
191
|
+
});
|
|
192
|
+
const isFailure = err || isFailureFromLogs;
|
|
190
193
|
if (isFailure) {
|
|
191
|
-
if (err &&
|
|
194
|
+
if (err &&
|
|
195
|
+
// When aborting (using the page.close() trick) the following `err` is triggered which irrelevant for the user.
|
|
196
|
+
// ```
|
|
197
|
+
// proxy.goto: Target page, context or browser has been closed
|
|
198
|
+
// at .testRun.ts:21:16
|
|
199
|
+
// at runTest (file:///home/rom/code/test-e2e/src/runAll.ts:265:24)
|
|
200
|
+
// at runTests (file:///home/rom/code/test-e2e/src/runAll.ts:211:13)
|
|
201
|
+
// at runServerAndTests (file:///home/rom/code/test-e2e/src/runAll.ts:164:17)
|
|
202
|
+
// at buildAndTest (file:///home/rom/code/test-e2e/src/runAll.ts:142:19)
|
|
203
|
+
// at runTestFiles (file:///home/rom/code/test-e2e/src/runAll.ts:56:34)
|
|
204
|
+
// at runAll (file:///home/rom/code/test-e2e/src/runAll.ts:26:27) {
|
|
205
|
+
// name: 'Error'
|
|
206
|
+
//}
|
|
207
|
+
!testInfo.aborted) {
|
|
192
208
|
logFailure(err, `the test "${testDesc}" threw an error`, isFinalAttempt);
|
|
193
209
|
}
|
|
194
|
-
else if (hasErrorLog) {
|
|
195
|
-
logFailure(null, `${getErrorType(failOnWarning)} occurred while running the test "${testDesc}"`, isFinalAttempt);
|
|
196
|
-
}
|
|
197
210
|
else {
|
|
198
|
-
assert(
|
|
211
|
+
assert(Logs.hasFailureLog({ includeBrowserWarnings: failOnWarning, includeStderr: true }));
|
|
212
|
+
logFailure(null, `${getErrorType(failOnWarning)} occurred while running the test "${testDesc}"`, isFinalAttempt);
|
|
199
213
|
}
|
|
200
214
|
return false;
|
|
201
215
|
}
|
|
202
216
|
}
|
|
203
217
|
Logs.clearLogs();
|
|
204
218
|
}
|
|
219
|
+
delete testInfo.isTestFunctionRunning;
|
|
205
220
|
return true;
|
|
206
221
|
}
|
|
207
222
|
function logFailure(err, reason, isFinalAttempt) {
|
package/dist/utils/cliOptions.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export { cliOptions };
|
|
2
2
|
import { check, prepare, validate } from './parseCli.js';
|
|
3
|
-
import { isCI } from './platform.js';
|
|
4
3
|
prepare();
|
|
5
4
|
const verbose = check('--verbose');
|
|
6
5
|
const inspect = check('--inspect');
|
|
7
6
|
const debugEsbuild = check('--debug-esbuild');
|
|
8
|
-
const bail = check('--bail')
|
|
7
|
+
const bail = check('--bail');
|
|
9
8
|
// Defined & used in ./findFiles.ts
|
|
10
9
|
const exclude = check('--exclude');
|
|
11
10
|
validate();
|