@brillout/test-e2e 0.4.0 → 0.4.2

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.js CHANGED
@@ -46,7 +46,7 @@ function clearLogs() {
46
46
  function logErrors(failOnWarning) {
47
47
  if (!exports.Logs.hasErrorLogs(failOnWarning))
48
48
  return;
49
- (0, logSection_1.logSection)(`ERROR${!failOnWarning ? '' : '/WARNING'} LOG(S)`);
49
+ (0, logSection_1.logSection)(`ERROR${!failOnWarning ? '' : '/WARNING'} LOGS`);
50
50
  const errorLogs = getErrorLogs(failOnWarning);
51
51
  errorLogs.forEach((logEntry) => printLog(logEntry));
52
52
  }
@@ -6,6 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.logSection = void 0;
7
7
  const picocolors_1 = __importDefault(require("picocolors"));
8
8
  function logSection(sectionTitle) {
9
- console.log(picocolors_1.default.bold(`vvvvvv ${sectionTitle} vvvvvv`));
9
+ const title = `------ ${sectionTitle} ------`;
10
+ const width = title.length;
11
+ console.log(picocolors_1.default.bold('='.repeat(width)));
12
+ console.log(picocolors_1.default.bold(title));
13
+ console.log(picocolors_1.default.bold('v'.repeat(width)));
10
14
  }
11
15
  exports.logSection = logSection;
package/dist/runTests.js CHANGED
@@ -73,8 +73,7 @@ async function runTestFile(browser) {
73
73
  await testInfo.startServer();
74
74
  }
75
75
  catch (err) {
76
- logResult(false);
77
- logFailureReason('during server start', false);
76
+ logFailureReason('an error occurred while starting the server');
78
77
  logError(err);
79
78
  Logs_1.Logs.flushLogs();
80
79
  await abort();
@@ -100,14 +99,12 @@ async function runTestFile(browser) {
100
99
  const hasErrorLog = Logs_1.Logs.hasErrorLogs(failOnWarning);
101
100
  const isFailure = err || hasErrorLog;
102
101
  if (isFailure) {
103
- logResult(false);
104
- const failureContext = 'while running the tests';
105
102
  if (err) {
106
- logFailureReason(failureContext, false);
103
+ logFailureReason(`the test "${testDesc}" threw an error`);
107
104
  logError(err);
108
105
  }
109
106
  else if (hasErrorLog) {
110
- logFailureReason(failureContext, true, failOnWarning);
107
+ logFailureReason(`${getErrorType(failOnWarning)} occurred while running the test "${testDesc}"`);
111
108
  }
112
109
  else {
113
110
  (0, utils_1.assert)(false);
@@ -121,23 +118,23 @@ async function runTestFile(browser) {
121
118
  Logs_1.Logs.clearLogs();
122
119
  }
123
120
  await clean();
124
- // Handle case that an error occured during `testInfo.terminateServer()`
125
- if (Logs_1.Logs.hasErrorLogs(true)) {
126
- /* TODO: implement more precise workaround
127
- if (isWindows()) {
128
- // On Windows, the sever sometimes terminates with an exit code of `1`. I don't know why.
129
- Logs.clearLogs()
130
- } else {
131
- */
132
- const failOnWarning = false;
133
- logFailureReason('during server termination', true, failOnWarning);
134
- Logs_1.Logs.logErrors(failOnWarning);
135
- Logs_1.Logs.flushLogs();
136
- await abort();
137
- return;
121
+ // Check whether stderr emitted during testInfo.terminateServer()
122
+ {
123
+ const failOnWarning = true;
124
+ if (Logs_1.Logs.hasErrorLogs(failOnWarning)) {
125
+ logFailureReason(`${getErrorType(failOnWarning)} occurred during server termination`);
126
+ Logs_1.Logs.logErrors(failOnWarning);
127
+ Logs_1.Logs.flushLogs();
128
+ await abort();
129
+ return;
130
+ }
138
131
  }
132
+ Logs_1.Logs.clearLogs();
139
133
  logResult(true);
140
134
  }
135
+ function getErrorType(failOnWarning) {
136
+ return !failOnWarning ? 'error(s)' : 'error(s)/warning(s)';
137
+ }
141
138
  function runTest(testFn, testFunctionTimeout) {
142
139
  let resolve;
143
140
  let reject;
@@ -178,13 +175,11 @@ function logResult(success) {
178
175
  console.log(`${FAIL} ${testInfo.testFile}`);
179
176
  }
180
177
  }
181
- function logFailureReason(context, isErrorLog, failOnWarning) {
178
+ function logFailureReason(reason) {
179
+ logResult(false);
182
180
  const { FAIL } = getStatusTags();
183
181
  const color = (s) => picocolors_1.default.red(picocolors_1.default.bold(s));
184
- (0, utils_1.assert)((isErrorLog === false && failOnWarning === undefined) ||
185
- (isErrorLog === true && (failOnWarning === true || failOnWarning === false)));
186
- const errType = isErrorLog ? 'error' : !failOnWarning ? 'error(s)' : 'error(s)/warning(s)';
187
- const msg = `Test ${FAIL} because encountered ${errType} ${context}, see below.`;
182
+ const msg = `Test ${FAIL} because ${reason}, see below.`;
188
183
  console.log(color(msg));
189
184
  }
190
185
  function logError(err) {
@@ -192,8 +187,8 @@ function logError(err) {
192
187
  console.log(err);
193
188
  }
194
189
  function getStatusTags() {
195
- const PASS = picocolors_1.default.bold(picocolors_1.default.bgGreen('PASS'));
196
- const FAIL = picocolors_1.default.bold(picocolors_1.default.bgRed('FAIL'));
197
- const WARN = picocolors_1.default.bold(picocolors_1.default.bgYellow('WARN'));
190
+ const PASS = picocolors_1.default.bold(picocolors_1.default.bgGreen(picocolors_1.default.white(' PASS ')));
191
+ const FAIL = picocolors_1.default.bold(picocolors_1.default.bgRed(picocolors_1.default.white(' FAIL ')));
192
+ const WARN = picocolors_1.default.bold(picocolors_1.default.bgYellow(picocolors_1.default.white(' WARN ')));
198
193
  return { PASS, FAIL, WARN };
199
194
  }
package/dist/setup.js CHANGED
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "expectError", { enumerable: true, get: function
26
26
  const serverUrlDefault = 'http://localhost:3000';
27
27
  const TIMEOUT_NPM_SCRIPT = 2 * 60 * 1000 * (!(0, utils_1.isCI)() ? 1 : (0, utils_1.isWindows)() ? 2 : 1);
28
28
  const TIMEOUT_TEST_FUNCTION = 60 * 1000 * (!(0, utils_1.isCI)() ? 1 : (0, utils_1.isWindows)() ? 5 : 3);
29
- const TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!(0, utils_1.isCI)() ? 1 : (0, utils_1.isLinux)() ? 1 : 4);
29
+ const TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!(0, utils_1.isCI)() ? 1 : (0, utils_1.isWindows)() ? 3 : !(0, utils_1.isLinux)() ? 3 : 1);
30
30
  const TIMEOUT_AUTORETRY = TIMEOUT_TEST_FUNCTION / 2;
31
31
  const TIMEOUT_PLAYWRIGHT = TIMEOUT_TEST_FUNCTION / 2;
32
32
  function skip(reason) {
@@ -87,7 +87,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
87
87
  page_1.page.off('pageerror', onPageError);
88
88
  // `runProcess` is `undefined` if `start()` failed.
89
89
  if (runProcess) {
90
- await runProcess.terminate('SIGINT');
90
+ await runProcess.terminate();
91
91
  }
92
92
  };
93
93
  return;
@@ -169,7 +169,7 @@ async function start() {
169
169
  logSource: 'run() failure',
170
170
  logText: errMsg,
171
171
  });
172
- await terminate();
172
+ await terminate(true);
173
173
  rejectServerStart(new Error(errMsg));
174
174
  }, timeoutTotal);
175
175
  // Kill any process that listens to the server port
@@ -210,7 +210,7 @@ async function start() {
210
210
  });
211
211
  return promise;
212
212
  }
213
- function stopProcess({ proc, cwd, cmd, signal, }) {
213
+ function stopProcess({ proc, cwd, cmd, force, }) {
214
214
  const prefix = `[Run Stop][${cwd}][${cmd}]`;
215
215
  let resolve;
216
216
  let reject;
@@ -235,19 +235,33 @@ function stopProcess({ proc, cwd, cmd, signal, }) {
235
235
  stdio: [
236
236
  'ignore',
237
237
  'ignore',
238
- // Should we ignore `stderr`? Because `taskkill` somtimes throws:
239
- // ```
240
- // ERROR: The process with PID 6052 (child process of PID 3184) could not be terminated.
241
- // Reason: There is no running instance of the task.
242
- // ```
238
+ // We ignore stderr because taskkill somtimes throws:
239
+ // ```
240
+ // ERROR: The process with PID 6052 (child process of PID 3184) could not be terminated.
241
+ // Reason: There is no running instance of the task.
242
+ // ```
243
+ // ```
244
+ // ERROR: The process "6564" not found.
245
+ // ```
243
246
  // There doesn't seem to be an option to suppress that error: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill#parameters
244
- 'inherit', // stderr
247
+ // The error propagates to Node.js's stderr.
248
+ // ```
249
+ // [15:36:10.626][\examples\react][npm run preview][stderr] npm
250
+ // [15:36:10.626][\examples\react][npm run preview][stderr]
251
+ // [15:36:10.626][\examples\react][npm run preview][stderr] ERR!
252
+ // [15:36:10.626][\examples\react][npm run preview][stderr]
253
+ // [15:36:10.626][\examples\react][npm run preview][stderr] code
254
+ // [15:36:10.626][\examples\react][npm run preview][stderr] ELIFECYCLE
255
+ // ```
256
+ // Because stderr isn't empty, runTests() believes that the termination failed.
257
+ 'ignore', // stderr
245
258
  ],
246
259
  });
247
260
  }
248
261
  else {
249
262
  (0, utils_2.assert)(proc.pid);
250
263
  const processGroup = -1 * proc.pid;
264
+ const signal = force ? 'SIGKILL' : 'SIGTERM';
251
265
  process.kill(processGroup, signal);
252
266
  /*
253
267
  try {
@@ -288,7 +302,7 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
288
302
  logText: err.message,
289
303
  logSource: 'run() failure',
290
304
  });
291
- await terminate();
305
+ await terminate(true);
292
306
  onFailure(err);
293
307
  };
294
308
  proc.stdin.on('data', async (data) => {
@@ -344,7 +358,7 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
344
358
  function processHasExited() {
345
359
  return procExited;
346
360
  }
347
- async function terminate(signal = 'SIGKILL') {
361
+ async function terminate(force) {
348
362
  let resolve;
349
363
  let reject;
350
364
  const promise = new Promise((_resolve, _reject) => {
@@ -357,7 +371,10 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
357
371
  logSource: 'run() failure',
358
372
  logText: errMsg,
359
373
  });
360
- reject(new Error(errMsg));
374
+ /* Don't interrupt the test runner, as the test runner may recover thanks to the process-killing-by-port
375
+ reject(new Error(errMsg))
376
+ */
377
+ resolve();
361
378
  }, TIMEOUT_PROCESS_TERMINATION);
362
379
  (0, utils_2.assert)(proc);
363
380
  try {
@@ -365,7 +382,7 @@ function execRunScript({ onStdout, onFailure, onExit, }) {
365
382
  proc,
366
383
  cwd,
367
384
  cmd,
368
- signal,
385
+ force,
369
386
  });
370
387
  }
371
388
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/test-e2e",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "bin": "./bin.js",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {