@brillout/test-e2e 0.1.19 → 0.1.21
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 +1 -1
- package/dist/Logs.js +1 -1
- package/dist/runTests.js +8 -2
- package/dist/setup.js +69 -56
- package/package.json +1 -1
package/dist/Logs.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare type LogEntry = {
|
|
|
13
13
|
logTimestamp: string;
|
|
14
14
|
isNotFailure: boolean;
|
|
15
15
|
};
|
|
16
|
-
declare function hasError(onlyFailOnBrowserError
|
|
16
|
+
declare function hasError(onlyFailOnBrowserError?: boolean): boolean;
|
|
17
17
|
declare function clear(): void;
|
|
18
18
|
declare function flush(): void;
|
|
19
19
|
declare function add({ logSource, logText }: {
|
package/dist/Logs.js
CHANGED
|
@@ -17,7 +17,7 @@ const getCurrentTest_1 = require("./getCurrentTest");
|
|
|
17
17
|
const getConfig_1 = require("./getConfig");
|
|
18
18
|
let logEntries = [];
|
|
19
19
|
let logEntriesNotPrinted = [];
|
|
20
|
-
function hasError(onlyFailOnBrowserError) {
|
|
20
|
+
function hasError(onlyFailOnBrowserError = false) {
|
|
21
21
|
const logErrors = logEntries.filter(({ logSource, isNotFailure }) => {
|
|
22
22
|
if (isNotFailure) {
|
|
23
23
|
return;
|
package/dist/runTests.js
CHANGED
|
@@ -5,6 +5,7 @@ const getCurrentTest_1 = require("./getCurrentTest");
|
|
|
5
5
|
const Logs_1 = require("./Logs");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
7
|
const picocolors_1 = require("picocolors");
|
|
8
|
+
const logsContainError_errMsg = 'The browser/server threw/logged one or more error/warning, see logs below.';
|
|
8
9
|
async function runTests(browser) {
|
|
9
10
|
const testInfo = (0, getCurrentTest_1.getCurrentTest)();
|
|
10
11
|
if (utils_1.isTTY) {
|
|
@@ -60,7 +61,7 @@ async function runTests(browser) {
|
|
|
60
61
|
console.error(err);
|
|
61
62
|
}
|
|
62
63
|
if (hasErrorLog) {
|
|
63
|
-
console.log(new Error(
|
|
64
|
+
console.log(new Error(logsContainError_errMsg));
|
|
64
65
|
}
|
|
65
66
|
Logs_1.Logs.flush();
|
|
66
67
|
process.exit(1);
|
|
@@ -71,6 +72,11 @@ async function runTests(browser) {
|
|
|
71
72
|
}
|
|
72
73
|
await testInfo.terminateServer();
|
|
73
74
|
await page.close();
|
|
75
|
+
// Handle case that an error occured during `terminateServer()`
|
|
76
|
+
if (Logs_1.Logs.hasError()) {
|
|
77
|
+
console.log(new Error(logsContainError_errMsg));
|
|
78
|
+
Logs_1.Logs.flush();
|
|
79
|
+
}
|
|
74
80
|
logTestsResult(true);
|
|
75
81
|
}
|
|
76
82
|
exports.runTests = runTests;
|
|
@@ -110,7 +116,7 @@ function logTestsResult(success) {
|
|
|
110
116
|
return;
|
|
111
117
|
}
|
|
112
118
|
if (testInfo.skipped) {
|
|
113
|
-
console.log(`${skipStyle('
|
|
119
|
+
console.log(`${skipStyle('WARN')} ${testInfo.testFile} (${testInfo.skipped})`);
|
|
114
120
|
}
|
|
115
121
|
else {
|
|
116
122
|
console.log(`${failStyle('FAIL')} ${testInfo.testFile}`);
|
package/dist/setup.js
CHANGED
|
@@ -25,7 +25,7 @@ exports.urlBaseChange = urlBaseChange;
|
|
|
25
25
|
var editFile_2 = require("./editFile");
|
|
26
26
|
Object.defineProperty(exports, "editFile", { enumerable: true, get: function () { return editFile_2.editFile; } });
|
|
27
27
|
Object.defineProperty(exports, "editFileRevert", { enumerable: true, get: function () { return editFile_2.editFileRevert; } });
|
|
28
|
-
const TIMEOUT_NPM_SCRIPT =
|
|
28
|
+
const TIMEOUT_NPM_SCRIPT = 2 * 60 * 1000;
|
|
29
29
|
const TIMEOUT_TEST_FUNCTION = 60 * 1000 * (!isGithubAction() ? 1 : isWindows() ? 5 : 3);
|
|
30
30
|
const TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!isGithubAction() ? 1 : isLinux() ? 1 : 4);
|
|
31
31
|
const TIMEOUT_AUTORETRY = TIMEOUT_TEST_FUNCTION / 2;
|
|
@@ -79,19 +79,15 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
testInfo.terminateServer = async () => {
|
|
82
|
+
Logs_1.Logs.add({
|
|
83
|
+
logSource: 'run()',
|
|
84
|
+
logText: 'Terminate server.',
|
|
85
|
+
});
|
|
82
86
|
page_1.page.off('console', onConsole);
|
|
83
87
|
page_1.page.off('pageerror', onPageError);
|
|
84
88
|
// `runProcess` is `undefined` if `start()` failed.
|
|
85
89
|
if (runProcess) {
|
|
86
|
-
|
|
87
|
-
await runProcess.terminate('SIGINT');
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
Logs_1.Logs.add({
|
|
91
|
-
logSource: 'run()',
|
|
92
|
-
logText: String(err),
|
|
93
|
-
});
|
|
94
|
-
}
|
|
90
|
+
await runProcess.terminate('SIGINT');
|
|
95
91
|
}
|
|
96
92
|
};
|
|
97
93
|
return;
|
|
@@ -141,9 +137,11 @@ async function start() {
|
|
|
141
137
|
let rejectServerStart;
|
|
142
138
|
const promise = new Promise((_resolve, _reject) => {
|
|
143
139
|
resolveServerStart = () => {
|
|
140
|
+
(0, utils_2.assert)(!processHasExited());
|
|
141
|
+
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
144
142
|
Logs_1.Logs.add({
|
|
145
143
|
logSource: 'run()',
|
|
146
|
-
logText: '
|
|
144
|
+
logText: 'Server is ready.',
|
|
147
145
|
});
|
|
148
146
|
hasSuccessfullyStarted = true;
|
|
149
147
|
clearTimeout(serverStartTimeout);
|
|
@@ -151,45 +149,40 @@ async function start() {
|
|
|
151
149
|
_resolve(runProcess);
|
|
152
150
|
};
|
|
153
151
|
rejectServerStart = async (err) => {
|
|
152
|
+
(0, utils_2.assert)(processHasExited());
|
|
154
153
|
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
155
154
|
done(true);
|
|
156
|
-
Logs_1.Logs.add({
|
|
157
|
-
logSource: 'run() failure',
|
|
158
|
-
logText: String(err),
|
|
159
|
-
});
|
|
160
155
|
clearTimeout(serverStartTimeout);
|
|
161
|
-
try {
|
|
162
|
-
await terminate('SIGKILL');
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
Logs_1.Logs.add({
|
|
166
|
-
logSource: 'run()',
|
|
167
|
-
logText: String(err),
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
156
|
_reject(err);
|
|
171
157
|
};
|
|
172
158
|
});
|
|
173
159
|
const timeoutTotal = TIMEOUT_NPM_SCRIPT + additionalTimeout;
|
|
174
160
|
let hasTimedout = false;
|
|
175
|
-
const serverStartTimeout = setTimeout(() => {
|
|
161
|
+
const serverStartTimeout = setTimeout(async () => {
|
|
162
|
+
hasTimedout = true;
|
|
176
163
|
let errMsg = '';
|
|
177
164
|
errMsg += `Server still didn't start after ${(0, utils_1.humanizeTime)(timeoutTotal)} of running the npm script \`${cmd}\`.`;
|
|
178
165
|
if (serverIsReadyMessage) {
|
|
179
166
|
errMsg += ` (The stdout of the npm script did not include: "${serverIsReadyMessage}".)`;
|
|
180
167
|
}
|
|
181
|
-
|
|
168
|
+
Logs_1.Logs.add({
|
|
169
|
+
logSource: 'run() failure',
|
|
170
|
+
logText: errMsg,
|
|
171
|
+
});
|
|
172
|
+
await terminate();
|
|
182
173
|
rejectServerStart(new Error(errMsg));
|
|
183
174
|
}, timeoutTotal);
|
|
184
175
|
// Kill any process that listens to port `3000`
|
|
185
176
|
if (!process.env.CI && isLinux()) {
|
|
186
177
|
await (0, utils_1.runCommand)('fuser -k 3000/tcp', { swallowError: true, timeout: 10 * 1000 });
|
|
187
178
|
}
|
|
188
|
-
const { terminate } = execRunScript({
|
|
189
|
-
|
|
179
|
+
const { terminate, processHasExited } = execRunScript({
|
|
180
|
+
async onFailure(err) {
|
|
181
|
+
(0, utils_2.assert)(processHasExited());
|
|
190
182
|
rejectServerStart(err);
|
|
191
183
|
},
|
|
192
184
|
onExit() {
|
|
185
|
+
(0, utils_2.assert)(processHasExited());
|
|
193
186
|
const exitIsPossible = hasSuccessfullyStarted === true || hasTimedout;
|
|
194
187
|
return exitIsPossible;
|
|
195
188
|
},
|
|
@@ -211,11 +204,6 @@ async function start() {
|
|
|
211
204
|
done();
|
|
212
205
|
}
|
|
213
206
|
},
|
|
214
|
-
onStderr(data) {
|
|
215
|
-
if (data.includes('EADDRINUSE')) {
|
|
216
|
-
rejectServerStart(new Error('Port conflict? Port already in use EADDRINUSE.'));
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
207
|
});
|
|
220
208
|
return promise;
|
|
221
209
|
}
|
|
@@ -276,7 +264,7 @@ function stopProcess({ proc, cwd, cmd, signal, }) {
|
|
|
276
264
|
}
|
|
277
265
|
return promise;
|
|
278
266
|
}
|
|
279
|
-
function execRunScript({ onStdout,
|
|
267
|
+
function execRunScript({ onStdout, onFailure, onExit, }) {
|
|
280
268
|
const { cwd, cmd } = getRunInfo();
|
|
281
269
|
let [command, ...args] = cmd.split(' ');
|
|
282
270
|
let detached = true;
|
|
@@ -291,10 +279,20 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
291
279
|
logText: `Spawn command \`${cmd}\``,
|
|
292
280
|
});
|
|
293
281
|
const proc = (0, child_process_1.spawn)(command, args, { cwd, detached });
|
|
282
|
+
let procExited = false;
|
|
283
|
+
const exitAndFail = async (err) => {
|
|
284
|
+
Logs_1.Logs.add({
|
|
285
|
+
logText: err.message,
|
|
286
|
+
logSource: 'run() failure',
|
|
287
|
+
});
|
|
288
|
+
await terminate();
|
|
289
|
+
onFailure(err);
|
|
290
|
+
};
|
|
294
291
|
proc.stdin.on('data', async (data) => {
|
|
295
|
-
|
|
292
|
+
await exitAndFail(new Error(`Command is \`${cmd}\` (${cwd}) is invoking \`stdin\`: ${data}.`));
|
|
296
293
|
});
|
|
297
294
|
proc.stdout.on('data', (data) => {
|
|
295
|
+
(0, utils_2.assert)(!procExited);
|
|
298
296
|
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
299
297
|
data = data.toString();
|
|
300
298
|
Logs_1.Logs.add({
|
|
@@ -303,16 +301,22 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
303
301
|
});
|
|
304
302
|
onStdout?.(data);
|
|
305
303
|
});
|
|
306
|
-
proc.stderr.on('data', (data) => {
|
|
304
|
+
proc.stderr.on('data', async (data) => {
|
|
305
|
+
(0, utils_2.assert)(!procExited);
|
|
307
306
|
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
308
307
|
data = data.toString();
|
|
309
308
|
Logs_1.Logs.add({
|
|
310
309
|
logSource: 'stderr',
|
|
311
310
|
logText: data,
|
|
312
311
|
});
|
|
313
|
-
|
|
312
|
+
if (data.includes('EADDRINUSE')) {
|
|
313
|
+
await exitAndFail(new Error('Port conflict? Port already in use EADDRINUSE.'));
|
|
314
|
+
}
|
|
314
315
|
});
|
|
316
|
+
let exitPromiseResolve;
|
|
317
|
+
const exitPromise = new Promise((r) => (exitPromiseResolve = r));
|
|
315
318
|
proc.on('exit', (code) => {
|
|
319
|
+
procExited = true;
|
|
316
320
|
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
317
321
|
const exitIsPossible = onExit();
|
|
318
322
|
const isSuccessCode = [0, null].includes(code) || (isWindows() && code === 1);
|
|
@@ -323,16 +327,7 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
323
327
|
logText: errMsg,
|
|
324
328
|
logSource: 'run() failure',
|
|
325
329
|
});
|
|
326
|
-
|
|
327
|
-
/*
|
|
328
|
-
try {
|
|
329
|
-
await terminate('SIGKILL')
|
|
330
|
-
} catch (err: unknown) {
|
|
331
|
-
if( !err.code === 'ESRCH' ) {
|
|
332
|
-
onError(err as Error)
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
*/
|
|
330
|
+
onFailure(new Error(errMsg));
|
|
336
331
|
}
|
|
337
332
|
else {
|
|
338
333
|
Logs_1.Logs.add({
|
|
@@ -340,9 +335,13 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
340
335
|
logSource: 'run()',
|
|
341
336
|
});
|
|
342
337
|
}
|
|
338
|
+
exitPromiseResolve();
|
|
343
339
|
});
|
|
344
|
-
return { terminate };
|
|
345
|
-
|
|
340
|
+
return { terminate, processHasExited };
|
|
341
|
+
function processHasExited() {
|
|
342
|
+
return procExited;
|
|
343
|
+
}
|
|
344
|
+
async function terminate(signal = 'SIGKILL') {
|
|
346
345
|
let resolve;
|
|
347
346
|
let reject;
|
|
348
347
|
const promise = new Promise((_resolve, _reject) => {
|
|
@@ -350,16 +349,30 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
350
349
|
reject = _reject;
|
|
351
350
|
});
|
|
352
351
|
const timeout = setTimeout(() => {
|
|
353
|
-
|
|
352
|
+
const errMsg = 'Process termination timeout. Cmd: ' + cmd;
|
|
353
|
+
Logs_1.Logs.add({
|
|
354
|
+
logSource: 'run() failure',
|
|
355
|
+
logText: errMsg,
|
|
356
|
+
});
|
|
357
|
+
reject(new Error(errMsg));
|
|
354
358
|
}, TIMEOUT_PROCESS_TERMINATION);
|
|
355
359
|
(0, utils_2.assert)(proc);
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
360
|
+
try {
|
|
361
|
+
await stopProcess({
|
|
362
|
+
proc,
|
|
363
|
+
cwd,
|
|
364
|
+
cmd,
|
|
365
|
+
signal,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
Logs_1.Logs.add({
|
|
370
|
+
logSource: 'run() failure',
|
|
371
|
+
logText: String(err),
|
|
372
|
+
});
|
|
373
|
+
}
|
|
362
374
|
clearTimeout(timeout);
|
|
375
|
+
await exitPromise;
|
|
363
376
|
resolve();
|
|
364
377
|
return promise;
|
|
365
378
|
}
|