@brillout/test-e2e 0.6.11 → 0.6.13

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
@@ -4,7 +4,7 @@ export declare const Logs: {
4
4
  flushLogs: typeof flushLogs;
5
5
  logErrorsAndWarnings: typeof logErrorsAndWarnings;
6
6
  clearLogs: typeof clearLogs;
7
- hasFailLogs: typeof hasFailLogs;
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 hasFailLogs(failOnWarning: boolean): boolean;
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
- hasFailLogs,
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 hasFailLogs(failOnWarning) {
19
- const failLogs = getErrorLogs(failOnWarning);
18
+ function hasFailureLog({ includeBrowserWarnings, includeStderr, }) {
19
+ const failLogs = getErrorLogs({ includeBrowserWarnings, includeStderr });
20
20
  return failLogs.length > 0;
21
21
  }
22
- function getErrorLogs(includeWarnings) {
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 (includeWarnings && (logSource === 'Browser Warning' || logSource === 'stderr')) {
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');
@@ -59,12 +62,13 @@ function flushLogs() {
59
62
  }
60
63
  function add({ logSource, logText, logInfo = '', loggedAfterExit = false, }) {
61
64
  const logTimestamp = getTimestamp();
65
+ const isNotFailure = isTolerateError({ logSource, logText });
62
66
  const logEntry = {
63
67
  logSource,
64
68
  logText,
65
69
  logInfo,
66
70
  logTimestamp,
67
- isNotFailure: isTolerateError({ logSource, logText }),
71
+ isNotFailure,
68
72
  loggedAfterExit,
69
73
  };
70
74
  logEntries.push(logEntry);
@@ -78,15 +82,20 @@ function add({ logSource, logText, logInfo = '', loggedAfterExit = false, }) {
78
82
  if (shouldLog)
79
83
  printLog(logEntry);
80
84
  }
81
- if (logSource === 'Browser Error' || logSource === 'stderr') {
82
- terminateUponErrorLog();
85
+ if ((logSource === 'Browser Error' || logSource === 'stderr') && !isNotFailure) {
86
+ terminateUponErrorLog(logSource);
83
87
  }
84
88
  }
85
- async function terminateUponErrorLog() {
86
- if (!cliOptions.bail)
89
+ async function terminateUponErrorLog(logSource) {
90
+ const shouldBail = cliOptions.bail || (logSource === 'Browser Error' && !isCI());
91
+ if (!shouldBail)
87
92
  return;
88
93
  const testInfo = getCurrentTest();
94
+ // Skip bailing upon stderr logs while spinning up the server
95
+ if (logSource === 'stderr' && !testInfo.isTestFunctionRunning)
96
+ return;
89
97
  testInfo.aborted = true;
98
+ assert(Logs.hasFailureLog({ includeBrowserWarnings: false, includeStderr: true }));
90
99
  // Trick to abort the test: page.close() triggers the following error.
91
100
  // ```console
92
101
  // proxy.waitForFunction: Target closed
@@ -97,6 +106,10 @@ async function terminateUponErrorLog() {
97
106
  // }
98
107
  // ```
99
108
  await testInfo.page.close();
109
+ /* The trick above doesn't always work, and the following doesn't seem to make a difference.
110
+ const browser = await getBrowser()
111
+ await browser.close()
112
+ */
100
113
  }
101
114
  /**
102
115
  * Expect a log to be printed.
@@ -10,6 +10,7 @@ import type { Page } from 'playwright-chromium';
10
10
  type TestInfo = {
11
11
  testFile: string;
12
12
  testName: string;
13
+ isTestFunctionRunning?: true;
13
14
  tests?: {
14
15
  testDesc: string;
15
16
  testFn: Function;
package/dist/run.js CHANGED
@@ -93,10 +93,8 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
93
93
  function onPageError(err) {
94
94
  Logs.add({
95
95
  logSource: 'Browser Error',
96
- logText: JSON.stringify({
97
- text: err.message,
98
- location: err.stack,
99
- }, null, 2),
96
+ logText: err.stack || err.message,
97
+ logInfo: JSON.stringify({ errorMessage: err.message }, null, 2),
100
98
  });
101
99
  }
102
100
  }
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.hasFailLogs(failOnWarning) &&
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 hasErrorLog = Logs.hasFailLogs(failOnWarning);
189
- const isFailure = err || hasErrorLog;
188
+ const isFailureFromLogs = Logs.hasFailureLog({
189
+ includeBrowserWarnings: failOnWarning,
190
+ includeStderr: failOnWarning,
191
+ });
192
+ const isFailure = err || isFailureFromLogs;
190
193
  if (isFailure) {
191
- if (err && !testInfo.aborted) {
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(false);
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) {
@@ -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') || !isCI();
7
+ const bail = check('--bail');
9
8
  // Defined & used in ./findFiles.ts
10
9
  const exclude = check('--exclude');
11
10
  validate();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",