@brillout/test-e2e 0.6.8 → 0.6.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.
@@ -35,6 +35,7 @@ type TestInfo = {
35
35
  terminateServer?: () => Promise<void>;
36
36
  afterEach?: (hasFailed: boolean) => void;
37
37
  page?: Page;
38
+ aborted?: true;
38
39
  };
39
40
  declare function getCurrentTest(): TestInfo;
40
41
  declare function getCurrentTestOptional(): null | TestInfo;
package/dist/run.js CHANGED
@@ -69,11 +69,12 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
69
69
  };
70
70
  return;
71
71
  // Also called when the page throws an error or a warning
72
- function onConsole(msg) {
72
+ async function onConsole(msg) {
73
73
  const type = msg.type();
74
+ const isError = type === 'error';
74
75
  Logs.add({
75
76
  logSource: (() => {
76
- if (type === 'error') {
77
+ if (isError) {
77
78
  return 'Browser Error';
78
79
  }
79
80
  if (type === 'warning') {
@@ -81,16 +82,25 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
81
82
  }
82
83
  return 'Browser Log';
83
84
  })(),
84
- logText: JSON.stringify({
85
+ logText: msg.text(),
86
+ /* Seems like the information below isn't that useful.
87
+ JSON.stringify(
88
+ {
85
89
  type,
86
90
  text: msg.text(),
87
91
  location: msg.location(),
88
92
  args: msg.args(),
89
- }, null, 2),
93
+ },
94
+ null,
95
+ 2,
96
+ ),
97
+ */
90
98
  });
99
+ if (isError)
100
+ await terminateUponBrowserError();
91
101
  }
92
102
  // For uncaught exceptions
93
- function onPageError(err) {
103
+ async function onPageError(err) {
94
104
  Logs.add({
95
105
  logSource: 'Browser Error',
96
106
  logText: JSON.stringify({
@@ -98,6 +108,22 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
98
108
  location: err.stack,
99
109
  }, null, 2),
100
110
  });
111
+ await terminateUponBrowserError();
112
+ }
113
+ async function terminateUponBrowserError() {
114
+ if (!cliOptions.bail)
115
+ return;
116
+ testInfo.aborted = true;
117
+ // Trick to abort the test: page.close() triggers the following error.
118
+ // ```console
119
+ // proxy.waitForFunction: Target closed
120
+ // at clientSideNavigation (.testRun.ts:16:16)
121
+ // at .testRun.ts:11:5
122
+ // at file:///home/rom/code/test-e2e/src/runAll.ts:278:7 {
123
+ // name: 'Error'
124
+ // }
125
+ // ```
126
+ await testInfo.page.close();
101
127
  }
102
128
  }
103
129
  async function startProcess({ serverIsReadyMessage, serverIsReadyDelay, additionalTimeout, cmd, }) {
package/dist/runAll.js CHANGED
@@ -11,11 +11,15 @@ 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;
14
15
  async function runAll(filter) {
15
16
  await loadConfig();
16
17
  const testFiles = await findTestFiles(filter);
17
- const browser = await getBrowser();
18
+ browser = await getBrowser();
18
19
  const failedTestFiles = await runTestFiles(testFiles, browser);
20
+ await closeAll(failedTestFiles);
21
+ }
22
+ async function closeAll(failedTestFiles) {
19
23
  await browser.close();
20
24
  const hasFailedTestFile = failedTestFiles.length > 0;
21
25
  const hasFailLog = hasFail();
@@ -134,8 +138,11 @@ async function runServerAndTests(browser, isThirdAttempt, isFlaky) {
134
138
  return false;
135
139
  }
136
140
  let success = await runTests(testInfo, isFinalAttempt);
141
+ return await closeTest(testInfo, success, isFinalAttempt);
142
+ }
143
+ async function closeTest(testInfo, success, isFinalAttempt) {
137
144
  await testInfo.terminateServer();
138
- await page.close();
145
+ await testInfo.page.close();
139
146
  // Check whether stderr emitted during testInfo.terminateServer()
140
147
  if (success) {
141
148
  const failOnWarning = true;
@@ -181,7 +188,7 @@ async function runTests(testInfo, isFinalAttempt) {
181
188
  const hasErrorLog = Logs.hasFailLogs(failOnWarning);
182
189
  const isFailure = err || hasErrorLog;
183
190
  if (isFailure) {
184
- if (err) {
191
+ if (err && !testInfo.aborted) {
185
192
  logFailure(err, `the test "${testDesc}" threw an error`, isFinalAttempt);
186
193
  }
187
194
  else if (hasErrorLog) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",