@brillout/test-e2e 0.1.18 → 0.1.20
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 +16 -5
- package/dist/setup.js +65 -56
- package/package.json +1 -1
package/dist/Logs.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const Logs: {
|
|
|
6
6
|
hasError: typeof hasError;
|
|
7
7
|
flushEagerly: boolean;
|
|
8
8
|
};
|
|
9
|
-
declare type LogSource = 'stdout' | 'stderr' | 'Browser Error' | 'Browser Warning' | 'Browser Log' | 'Playwright' | 'run()' | 'test()' | 'Connection Error';
|
|
9
|
+
declare type LogSource = 'stdout' | 'stderr' | 'Browser Error' | 'Browser Warning' | 'Browser Log' | 'Playwright' | 'run()' | 'run() failure' | 'test()' | 'Connection Error';
|
|
10
10
|
declare type LogEntry = {
|
|
11
11
|
logSource: LogSource;
|
|
12
12
|
logText: string;
|
package/dist/Logs.js
CHANGED
|
@@ -22,6 +22,9 @@ function hasError(onlyFailOnBrowserError) {
|
|
|
22
22
|
if (isNotFailure) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
+
if (logSource === 'run() failure') {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
25
28
|
if (!onlyFailOnBrowserError && (logSource === 'Browser Warning' || logSource === 'stderr')) {
|
|
26
29
|
return true;
|
|
27
30
|
}
|
|
@@ -106,15 +109,23 @@ function printLog(logEntry) {
|
|
|
106
109
|
}
|
|
107
110
|
function colorize(logSource) {
|
|
108
111
|
const { bold } = picocolors_1.default;
|
|
109
|
-
if (logSource === 'stderr' ||
|
|
112
|
+
if (logSource === 'stderr' ||
|
|
113
|
+
logSource === 'Browser Error' ||
|
|
114
|
+
logSource === 'Connection Error' ||
|
|
115
|
+
logSource === 'run() failure') {
|
|
110
116
|
return bold(picocolors_1.default.red(logSource));
|
|
111
|
-
|
|
117
|
+
}
|
|
118
|
+
if (logSource === 'Browser Warning') {
|
|
112
119
|
return bold(picocolors_1.default.yellow(logSource));
|
|
113
|
-
|
|
120
|
+
}
|
|
121
|
+
if (logSource === 'stdout' || logSource === 'Browser Log') {
|
|
114
122
|
return bold(picocolors_1.default.blue(logSource));
|
|
115
|
-
|
|
123
|
+
}
|
|
124
|
+
if (logSource === 'Playwright') {
|
|
116
125
|
return bold(picocolors_1.default.magenta(logSource));
|
|
117
|
-
|
|
126
|
+
}
|
|
127
|
+
if (logSource === 'run()' || logSource === 'test()') {
|
|
118
128
|
return bold(picocolors_1.default.cyan(logSource));
|
|
129
|
+
}
|
|
119
130
|
(0, utils_1.assert)(false);
|
|
120
131
|
}
|
package/dist/setup.js
CHANGED
|
@@ -83,15 +83,7 @@ additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect
|
|
|
83
83
|
page_1.page.off('pageerror', onPageError);
|
|
84
84
|
// `runProcess` is `undefined` if `start()` failed.
|
|
85
85
|
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
|
-
}
|
|
86
|
+
await runProcess.terminate('SIGINT');
|
|
95
87
|
}
|
|
96
88
|
};
|
|
97
89
|
return;
|
|
@@ -141,6 +133,8 @@ async function start() {
|
|
|
141
133
|
let rejectServerStart;
|
|
142
134
|
const promise = new Promise((_resolve, _reject) => {
|
|
143
135
|
resolveServerStart = () => {
|
|
136
|
+
(0, utils_2.assert)(!processHasExited());
|
|
137
|
+
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
144
138
|
Logs_1.Logs.add({
|
|
145
139
|
logSource: 'run()',
|
|
146
140
|
logText: 'server is ready',
|
|
@@ -151,44 +145,40 @@ async function start() {
|
|
|
151
145
|
_resolve(runProcess);
|
|
152
146
|
};
|
|
153
147
|
rejectServerStart = async (err) => {
|
|
148
|
+
(0, utils_2.assert)(processHasExited());
|
|
149
|
+
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
154
150
|
done(true);
|
|
155
|
-
Logs_1.Logs.add({
|
|
156
|
-
logSource: 'stderr',
|
|
157
|
-
logText: String(err),
|
|
158
|
-
});
|
|
159
151
|
clearTimeout(serverStartTimeout);
|
|
160
|
-
try {
|
|
161
|
-
await terminate('SIGKILL');
|
|
162
|
-
}
|
|
163
|
-
catch (err) {
|
|
164
|
-
Logs_1.Logs.add({
|
|
165
|
-
logSource: 'run()',
|
|
166
|
-
logText: String(err),
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
152
|
_reject(err);
|
|
170
153
|
};
|
|
171
154
|
});
|
|
172
155
|
const timeoutTotal = TIMEOUT_NPM_SCRIPT + additionalTimeout;
|
|
173
156
|
let hasTimedout = false;
|
|
174
|
-
const serverStartTimeout = setTimeout(() => {
|
|
157
|
+
const serverStartTimeout = setTimeout(async () => {
|
|
158
|
+
hasTimedout = true;
|
|
175
159
|
let errMsg = '';
|
|
176
160
|
errMsg += `Server still didn't start after ${(0, utils_1.humanizeTime)(timeoutTotal)} of running the npm script \`${cmd}\`.`;
|
|
177
161
|
if (serverIsReadyMessage) {
|
|
178
162
|
errMsg += ` (The stdout of the npm script did not include: "${serverIsReadyMessage}".)`;
|
|
179
163
|
}
|
|
180
|
-
|
|
164
|
+
Logs_1.Logs.add({
|
|
165
|
+
logSource: 'run() failure',
|
|
166
|
+
logText: errMsg,
|
|
167
|
+
});
|
|
168
|
+
await terminate();
|
|
181
169
|
rejectServerStart(new Error(errMsg));
|
|
182
170
|
}, timeoutTotal);
|
|
183
171
|
// Kill any process that listens to port `3000`
|
|
184
172
|
if (!process.env.CI && isLinux()) {
|
|
185
173
|
await (0, utils_1.runCommand)('fuser -k 3000/tcp', { swallowError: true, timeout: 10 * 1000 });
|
|
186
174
|
}
|
|
187
|
-
const { terminate } = execRunScript({
|
|
188
|
-
|
|
175
|
+
const { terminate, processHasExited } = execRunScript({
|
|
176
|
+
async onFailure(err) {
|
|
177
|
+
(0, utils_2.assert)(processHasExited());
|
|
189
178
|
rejectServerStart(err);
|
|
190
179
|
},
|
|
191
180
|
onExit() {
|
|
181
|
+
(0, utils_2.assert)(processHasExited());
|
|
192
182
|
const exitIsPossible = hasSuccessfullyStarted === true || hasTimedout;
|
|
193
183
|
return exitIsPossible;
|
|
194
184
|
},
|
|
@@ -210,11 +200,6 @@ async function start() {
|
|
|
210
200
|
done();
|
|
211
201
|
}
|
|
212
202
|
},
|
|
213
|
-
onStderr(data) {
|
|
214
|
-
if (data.includes('EADDRINUSE')) {
|
|
215
|
-
rejectServerStart(new Error('Port conflict? Port already in use EADDRINUSE.'));
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
203
|
});
|
|
219
204
|
return promise;
|
|
220
205
|
}
|
|
@@ -275,7 +260,7 @@ function stopProcess({ proc, cwd, cmd, signal, }) {
|
|
|
275
260
|
}
|
|
276
261
|
return promise;
|
|
277
262
|
}
|
|
278
|
-
function execRunScript({ onStdout,
|
|
263
|
+
function execRunScript({ onStdout, onFailure, onExit, }) {
|
|
279
264
|
const { cwd, cmd } = getRunInfo();
|
|
280
265
|
let [command, ...args] = cmd.split(' ');
|
|
281
266
|
let detached = true;
|
|
@@ -290,10 +275,21 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
290
275
|
logText: `Spawn command \`${cmd}\``,
|
|
291
276
|
});
|
|
292
277
|
const proc = (0, child_process_1.spawn)(command, args, { cwd, detached });
|
|
278
|
+
let procExited = false;
|
|
279
|
+
const exitAndFail = async (err) => {
|
|
280
|
+
Logs_1.Logs.add({
|
|
281
|
+
logText: err.message,
|
|
282
|
+
logSource: 'run() failure',
|
|
283
|
+
});
|
|
284
|
+
await terminate();
|
|
285
|
+
onFailure(err);
|
|
286
|
+
};
|
|
293
287
|
proc.stdin.on('data', async (data) => {
|
|
294
|
-
|
|
288
|
+
await exitAndFail(new Error(`Command is \`${cmd}\` (${cwd}) is invoking \`stdin\`: ${data}.`));
|
|
295
289
|
});
|
|
296
|
-
proc.stdout.on('data',
|
|
290
|
+
proc.stdout.on('data', (data) => {
|
|
291
|
+
(0, utils_2.assert)(!procExited);
|
|
292
|
+
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
297
293
|
data = data.toString();
|
|
298
294
|
Logs_1.Logs.add({
|
|
299
295
|
logSource: 'stdout',
|
|
@@ -302,14 +298,20 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
302
298
|
onStdout?.(data);
|
|
303
299
|
});
|
|
304
300
|
proc.stderr.on('data', async (data) => {
|
|
301
|
+
(0, utils_2.assert)(!procExited);
|
|
302
|
+
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
305
303
|
data = data.toString();
|
|
306
304
|
Logs_1.Logs.add({
|
|
307
305
|
logSource: 'stderr',
|
|
308
306
|
logText: data,
|
|
309
307
|
});
|
|
310
|
-
|
|
308
|
+
if (data.includes('EADDRINUSE')) {
|
|
309
|
+
await exitAndFail(new Error('Port conflict? Port already in use EADDRINUSE.'));
|
|
310
|
+
}
|
|
311
311
|
});
|
|
312
|
-
proc.on('exit',
|
|
312
|
+
proc.on('exit', (code) => {
|
|
313
|
+
procExited = true;
|
|
314
|
+
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
313
315
|
const exitIsPossible = onExit();
|
|
314
316
|
const isSuccessCode = [0, null].includes(code) || (isWindows() && code === 1);
|
|
315
317
|
const isExpected = isSuccessCode && exitIsPossible;
|
|
@@ -317,18 +319,9 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
317
319
|
const errMsg = `Unexpected premature process termination, exit code: ${code}`;
|
|
318
320
|
Logs_1.Logs.add({
|
|
319
321
|
logText: errMsg,
|
|
320
|
-
logSource: '
|
|
322
|
+
logSource: 'run() failure',
|
|
321
323
|
});
|
|
322
|
-
|
|
323
|
-
/*
|
|
324
|
-
try {
|
|
325
|
-
await terminate('SIGKILL')
|
|
326
|
-
} catch (err: unknown) {
|
|
327
|
-
if( !err.code === 'ESRCH' ) {
|
|
328
|
-
onError(err as Error)
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
*/
|
|
324
|
+
onFailure(new Error(errMsg));
|
|
332
325
|
}
|
|
333
326
|
else {
|
|
334
327
|
Logs_1.Logs.add({
|
|
@@ -337,8 +330,11 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
337
330
|
});
|
|
338
331
|
}
|
|
339
332
|
});
|
|
340
|
-
return { terminate };
|
|
341
|
-
|
|
333
|
+
return { terminate, processHasExited };
|
|
334
|
+
function processHasExited() {
|
|
335
|
+
return procExited;
|
|
336
|
+
}
|
|
337
|
+
async function terminate(signal = 'SIGKILL') {
|
|
342
338
|
let resolve;
|
|
343
339
|
let reject;
|
|
344
340
|
const promise = new Promise((_resolve, _reject) => {
|
|
@@ -346,15 +342,28 @@ function execRunScript({ onStdout, onStderr, onError, onExit, }) {
|
|
|
346
342
|
reject = _reject;
|
|
347
343
|
});
|
|
348
344
|
const timeout = setTimeout(() => {
|
|
349
|
-
|
|
345
|
+
const errMsg = 'Process termination timeout. Cmd: ' + cmd;
|
|
346
|
+
Logs_1.Logs.add({
|
|
347
|
+
logSource: 'run() failure',
|
|
348
|
+
logText: errMsg,
|
|
349
|
+
});
|
|
350
|
+
reject(new Error(errMsg));
|
|
350
351
|
}, TIMEOUT_PROCESS_TERMINATION);
|
|
351
352
|
(0, utils_2.assert)(proc);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
353
|
+
try {
|
|
354
|
+
await stopProcess({
|
|
355
|
+
proc,
|
|
356
|
+
cwd,
|
|
357
|
+
cmd,
|
|
358
|
+
signal,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
catch (err) {
|
|
362
|
+
Logs_1.Logs.add({
|
|
363
|
+
logSource: 'run() failure',
|
|
364
|
+
logText: String(err),
|
|
365
|
+
});
|
|
366
|
+
}
|
|
358
367
|
clearTimeout(timeout);
|
|
359
368
|
resolve();
|
|
360
369
|
return promise;
|