@brillout/test-e2e 0.5.8 → 0.5.10
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 +2 -2
- package/dist/Logs.js +15 -7
- package/dist/TIMEOUTS.d.ts +5 -0
- package/dist/TIMEOUTS.js +9 -0
- package/dist/autoRetry.d.ts +4 -0
- package/dist/autoRetry.js +24 -0
- package/dist/buildTs.js +1 -1
- package/dist/cli.js +1 -0
- package/dist/fetch.d.ts +5 -0
- package/dist/fetch.js +30 -0
- package/dist/getCurrentTest.d.ts +30 -7
- package/dist/getCurrentTest.js +34 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +25 -16
- package/dist/logTestStatus.js +3 -0
- package/dist/run.d.ts +12 -0
- package/dist/run.js +188 -0
- package/dist/runAll.js +37 -11
- package/dist/runCommandThatTerminates.d.ts +4 -0
- package/dist/runCommandThatTerminates.js +11 -0
- package/dist/skip.d.ts +2 -0
- package/dist/skip.js +9 -0
- package/dist/testScreenshotFixture.js +1 -1
- package/dist/utils/findFiles.js +3 -3
- package/dist/utils/genPromise.d.ts +5 -0
- package/dist/utils/genPromise.js +13 -0
- package/dist/utils/humanizeTime.d.ts +1 -1
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/isMinNodeVersion.d.ts +2 -0
- package/dist/utils/isMinNodeVersion.js +12 -0
- package/dist/utils/runCommand.d.ts +4 -5
- package/dist/utils/runCommand.js +12 -32
- package/dist/utils/runCommandLongRunning.d.ts +20 -0
- package/dist/utils/runCommandLongRunning.js +232 -0
- package/dist/utils/runCommandShortLived.d.ts +6 -0
- package/dist/utils/runCommandShortLived.js +39 -0
- package/package.json +1 -1
- package/dist/setup.d.ts +0 -34
- package/dist/setup.js +0 -499
package/dist/setup.js
DELETED
|
@@ -1,499 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getServerUrl = exports.sleep = exports.isMac = exports.isWindows = exports.isLinux = exports.isCI = exports.isMinNodeVersion = exports.skip = exports.run = exports.expectError = exports.fetch = exports.fetchHtml = exports.autoRetry = exports.partRegex = void 0;
|
|
7
|
-
const child_process_1 = require("child_process");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const utils_1 = require("./utils");
|
|
10
|
-
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return utils_1.sleep; } });
|
|
11
|
-
Object.defineProperty(exports, "isWindows", { enumerable: true, get: function () { return utils_1.isWindows; } });
|
|
12
|
-
Object.defineProperty(exports, "isLinux", { enumerable: true, get: function () { return utils_1.isLinux; } });
|
|
13
|
-
Object.defineProperty(exports, "isCI", { enumerable: true, get: function () { return utils_1.isCI; } });
|
|
14
|
-
Object.defineProperty(exports, "isMac", { enumerable: true, get: function () { return utils_1.isMac; } });
|
|
15
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
16
|
-
const utils_2 = require("./utils");
|
|
17
|
-
const Logs_1 = require("./Logs");
|
|
18
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
19
|
-
const editFile_1 = require("./editFile");
|
|
20
|
-
const getCurrentTest_1 = require("./getCurrentTest");
|
|
21
|
-
const page_1 = require("./page");
|
|
22
|
-
const logTestStatus_1 = require("./logTestStatus");
|
|
23
|
-
var part_regex_1 = require("@brillout/part-regex");
|
|
24
|
-
Object.defineProperty(exports, "partRegex", { enumerable: true, get: function () { return part_regex_1.partRegex; } });
|
|
25
|
-
var Logs_2 = require("./Logs");
|
|
26
|
-
Object.defineProperty(exports, "expectError", { enumerable: true, get: function () { return Logs_2.expectError; } });
|
|
27
|
-
const serverUrlDefault = 'http://localhost:3000';
|
|
28
|
-
const TIMEOUT_NPM_SCRIPT = 2 * 60 * 1000 * (!(0, utils_1.isCI)() ? 1 : (0, utils_1.isWindows)() ? 2 : 1);
|
|
29
|
-
const TIMEOUT_TEST_FUNCTION = 60 * 1000 * (!(0, utils_1.isCI)() ? 1 : (0, utils_1.isWindows)() ? 5 : 3);
|
|
30
|
-
const TIMEOUT_PROCESS_TERMINATION = 10 * 1000 * (!(0, utils_1.isCI)() ? 1 : (0, utils_1.isWindows)() ? 3 : !(0, utils_1.isLinux)() ? 3 : 1);
|
|
31
|
-
const TIMEOUT_AUTORETRY = TIMEOUT_TEST_FUNCTION / 2;
|
|
32
|
-
const TIMEOUT_PLAYWRIGHT = TIMEOUT_TEST_FUNCTION / 2;
|
|
33
|
-
function skip(reason) {
|
|
34
|
-
const testInfo = (0, getCurrentTest_1.getCurrentTest)();
|
|
35
|
-
testInfo.skipped = { reason };
|
|
36
|
-
}
|
|
37
|
-
exports.skip = skip;
|
|
38
|
-
function run(cmd, {
|
|
39
|
-
//baseUrl = '',
|
|
40
|
-
additionalTimeout = 0, serverIsReadyMessage, serverIsReadyDelay = 1000, inspect = utils_1.cliConfig.inspect, cwd, doNotFailOnWarning = false, serverUrl = serverUrlDefault, isFlaky = false, } = {}) {
|
|
41
|
-
additionalTimeout += serverIsReadyDelay;
|
|
42
|
-
const testInfo = (0, getCurrentTest_1.getCurrentTest)();
|
|
43
|
-
testInfo.runInfo = {
|
|
44
|
-
cmd,
|
|
45
|
-
cwd: cwd || getCwd(),
|
|
46
|
-
additionalTimeout,
|
|
47
|
-
testFunctionTimeout: TIMEOUT_TEST_FUNCTION + additionalTimeout,
|
|
48
|
-
serverIsReadyMessage,
|
|
49
|
-
serverIsReadyDelay,
|
|
50
|
-
inspect,
|
|
51
|
-
doNotFailOnWarning,
|
|
52
|
-
serverUrl,
|
|
53
|
-
isFlaky,
|
|
54
|
-
};
|
|
55
|
-
if (inspect) {
|
|
56
|
-
Logs_1.Logs.logEagerly = true;
|
|
57
|
-
}
|
|
58
|
-
let runProcess = null;
|
|
59
|
-
testInfo.startServer = async () => {
|
|
60
|
-
runProcess = await start();
|
|
61
|
-
page_1.page.on('console', onConsole);
|
|
62
|
-
page_1.page.on('pageerror', onPageError);
|
|
63
|
-
// This setting will change the default maximum time for all the methods accepting timeout option.
|
|
64
|
-
// https://playwright.dev/docs/api/class-page#page-set-default-timeout
|
|
65
|
-
page_1.page.setDefaultTimeout(TIMEOUT_PLAYWRIGHT + additionalTimeout);
|
|
66
|
-
/*
|
|
67
|
-
await bailOnTimeout(
|
|
68
|
-
async () => {
|
|
69
|
-
await page.goto(getServerUrl() + baseUrl)
|
|
70
|
-
},
|
|
71
|
-
{ timeout: TIMEOUT_PAGE_LOAD + additionalTimeout },
|
|
72
|
-
)
|
|
73
|
-
*/
|
|
74
|
-
};
|
|
75
|
-
testInfo.afterEach = (hasFailed) => {
|
|
76
|
-
if (!hasFailed) {
|
|
77
|
-
(0, editFile_1.editFileAssertReverted)();
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
(0, editFile_1.editFileRevert)();
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
testInfo.terminateServer = async () => {
|
|
84
|
-
Logs_1.Logs.add({
|
|
85
|
-
logSource: 'run()',
|
|
86
|
-
logText: 'Terminate server.',
|
|
87
|
-
});
|
|
88
|
-
page_1.page.off('console', onConsole);
|
|
89
|
-
page_1.page.off('pageerror', onPageError);
|
|
90
|
-
// `runProcess` is `undefined` if `start()` failed.
|
|
91
|
-
if (runProcess) {
|
|
92
|
-
await runProcess.terminate();
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
return;
|
|
96
|
-
// Also called when the page throws an error or a warning
|
|
97
|
-
function onConsole(msg) {
|
|
98
|
-
const type = msg.type();
|
|
99
|
-
Logs_1.Logs.add({
|
|
100
|
-
logSource: (() => {
|
|
101
|
-
if (type === 'error') {
|
|
102
|
-
return 'Browser Error';
|
|
103
|
-
}
|
|
104
|
-
if (type === 'warning') {
|
|
105
|
-
return 'Browser Warning';
|
|
106
|
-
}
|
|
107
|
-
return 'Browser Log';
|
|
108
|
-
})(),
|
|
109
|
-
logText: JSON.stringify({
|
|
110
|
-
type,
|
|
111
|
-
text: msg.text(),
|
|
112
|
-
location: msg.location(),
|
|
113
|
-
args: msg.args(),
|
|
114
|
-
}, null, 2),
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
// For uncaught exceptions
|
|
118
|
-
function onPageError(err) {
|
|
119
|
-
Logs_1.Logs.add({
|
|
120
|
-
logSource: 'Browser Error',
|
|
121
|
-
logText: JSON.stringify({
|
|
122
|
-
text: err.message,
|
|
123
|
-
location: err.stack,
|
|
124
|
-
}, null, 2),
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.run = run;
|
|
129
|
-
function getRunInfo() {
|
|
130
|
-
const testInfo = (0, getCurrentTest_1.getCurrentTest)();
|
|
131
|
-
(0, utils_2.assert)(testInfo.runInfo);
|
|
132
|
-
return testInfo.runInfo;
|
|
133
|
-
}
|
|
134
|
-
async function start() {
|
|
135
|
-
const { cmd, additionalTimeout, serverIsReadyMessage, serverIsReadyDelay } = getRunInfo();
|
|
136
|
-
if (utils_1.isTTY) {
|
|
137
|
-
console.log();
|
|
138
|
-
(0, logTestStatus_1.logBoot)();
|
|
139
|
-
}
|
|
140
|
-
const done = (0, utils_1.logProgress)(`[run] ${cmd}`);
|
|
141
|
-
let hasSuccessfullyStarted = false;
|
|
142
|
-
let resolveServerStart;
|
|
143
|
-
let rejectServerStart;
|
|
144
|
-
const promise = new Promise((_resolve, _reject) => {
|
|
145
|
-
resolveServerStart = () => {
|
|
146
|
-
(0, utils_2.assert)(!processHasExited());
|
|
147
|
-
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
148
|
-
Logs_1.Logs.add({
|
|
149
|
-
logSource: 'run()',
|
|
150
|
-
logText: 'Server is ready.',
|
|
151
|
-
});
|
|
152
|
-
hasSuccessfullyStarted = true;
|
|
153
|
-
clearTimeout(serverStartTimeout);
|
|
154
|
-
const runProcess = { terminate };
|
|
155
|
-
_resolve(runProcess);
|
|
156
|
-
};
|
|
157
|
-
rejectServerStart = async (err) => {
|
|
158
|
-
(0, utils_2.assert)(processHasExited());
|
|
159
|
-
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
160
|
-
done(true);
|
|
161
|
-
clearTimeout(serverStartTimeout);
|
|
162
|
-
_reject(err);
|
|
163
|
-
};
|
|
164
|
-
});
|
|
165
|
-
const timeoutTotal = TIMEOUT_NPM_SCRIPT + additionalTimeout;
|
|
166
|
-
let hasTimedout = false;
|
|
167
|
-
const serverStartTimeout = setTimeout(async () => {
|
|
168
|
-
hasTimedout = true;
|
|
169
|
-
let errMsg = '';
|
|
170
|
-
errMsg += `Server still didn't start after ${(0, utils_1.humanizeTime)(timeoutTotal)} of running the npm script \`${cmd}\`.`;
|
|
171
|
-
if (serverIsReadyMessage) {
|
|
172
|
-
errMsg += ` (The stdout of the npm script did not include: "${serverIsReadyMessage}".)`;
|
|
173
|
-
}
|
|
174
|
-
Logs_1.Logs.add({
|
|
175
|
-
logSource: 'run() failure',
|
|
176
|
-
logText: errMsg,
|
|
177
|
-
});
|
|
178
|
-
await terminate(true);
|
|
179
|
-
rejectServerStart(new Error(errMsg));
|
|
180
|
-
}, timeoutTotal);
|
|
181
|
-
// Kill any process that listens to the server port
|
|
182
|
-
if (!process.env.CI && (0, utils_1.isLinux)()) {
|
|
183
|
-
const port = getPort();
|
|
184
|
-
(0, utils_2.assert)(/\d+/.test(port));
|
|
185
|
-
await (0, utils_1.runCommand)(`fuser -k ${port}/tcp`, { swallowError: true, timeout: 10 * 1000 });
|
|
186
|
-
}
|
|
187
|
-
const { terminate, processHasExited } = execRunScript({
|
|
188
|
-
async onFailure(err) {
|
|
189
|
-
(0, utils_2.assert)(processHasExited());
|
|
190
|
-
rejectServerStart(err);
|
|
191
|
-
},
|
|
192
|
-
onExit() {
|
|
193
|
-
(0, utils_2.assert)(processHasExited());
|
|
194
|
-
const exitIsPossible = hasSuccessfullyStarted === true || hasTimedout;
|
|
195
|
-
return exitIsPossible;
|
|
196
|
-
},
|
|
197
|
-
async onStdout(data) {
|
|
198
|
-
const log = (0, strip_ansi_1.default)(data);
|
|
199
|
-
const isServerReady =
|
|
200
|
-
// Custom
|
|
201
|
-
(typeof serverIsReadyMessage === 'string' && log.includes(serverIsReadyMessage)) ||
|
|
202
|
-
((0, utils_1.isCallable)(serverIsReadyMessage) && serverIsReadyMessage(log)) ||
|
|
203
|
-
// Express.js server
|
|
204
|
-
log.includes('Server running at') ||
|
|
205
|
-
// npm package `serve`
|
|
206
|
-
log.includes('Accepting connections at') ||
|
|
207
|
-
// Vite
|
|
208
|
-
(log.includes('Local:') && log.includes('http://localhost:3000/'));
|
|
209
|
-
if (isServerReady) {
|
|
210
|
-
(0, utils_2.assert)(serverIsReadyDelay);
|
|
211
|
-
await (0, utils_1.sleep)(serverIsReadyDelay);
|
|
212
|
-
resolveServerStart();
|
|
213
|
-
done();
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
return promise;
|
|
218
|
-
}
|
|
219
|
-
function stopProcess({ proc, cwd, cmd, force, }) {
|
|
220
|
-
const prefix = `[Run Stop][${cwd}][${cmd}]`;
|
|
221
|
-
let resolve;
|
|
222
|
-
let reject;
|
|
223
|
-
const promise = new Promise((_resolve, _reject) => {
|
|
224
|
-
resolve = _resolve;
|
|
225
|
-
reject = _reject;
|
|
226
|
-
});
|
|
227
|
-
const onProcessClose = (code) => {
|
|
228
|
-
if (code === 0 || code === null || (code === 1 && (0, utils_1.isWindows)())) {
|
|
229
|
-
resolve();
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
reject(new Error(`${prefix} Terminated with non-0 error code ${code}`));
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
proc.on('close', onProcessClose);
|
|
236
|
-
proc.on('exit', onProcessClose);
|
|
237
|
-
if ((0, utils_1.isWindows)()) {
|
|
238
|
-
// - https://github.com/nodejs/node/issues/3617#issuecomment-377731194
|
|
239
|
-
// - https://stackoverflow.com/questions/23706055/why-can-i-not-kill-my-child-process-in-nodejs-on-windows/28163919#28163919
|
|
240
|
-
// - taskkill seems to be buggy in many ways:
|
|
241
|
-
// - taskkill seems to make the process exit with code `1`
|
|
242
|
-
// - Because process exits with code `1`, Node.js/npm complains:
|
|
243
|
-
// ```
|
|
244
|
-
// [15:36:10.626][\examples\react][npm run preview][stderr] npm
|
|
245
|
-
// [15:36:10.626][\examples\react][npm run preview][stderr]
|
|
246
|
-
// [15:36:10.626][\examples\react][npm run preview][stderr] ERR!
|
|
247
|
-
// [15:36:10.626][\examples\react][npm run preview][stderr]
|
|
248
|
-
// [15:36:10.626][\examples\react][npm run preview][stderr] code
|
|
249
|
-
// [15:36:10.626][\examples\react][npm run preview][stderr] ELIFECYCLE
|
|
250
|
-
// ```
|
|
251
|
-
// Because stderr isn't empty, runTests() believes that the termination failed.
|
|
252
|
-
// - taskkill sometimes throws:
|
|
253
|
-
// ```
|
|
254
|
-
// ERROR: The process with PID 6052 (child process of PID 3184) could not be terminated.
|
|
255
|
-
// Reason: There is no running instance of the task.
|
|
256
|
-
// ```
|
|
257
|
-
// ```
|
|
258
|
-
// ERROR: The process "6564" not found.
|
|
259
|
-
// ```
|
|
260
|
-
// There doesn't seem to be an option to suppress these errors: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill#parameters
|
|
261
|
-
(0, child_process_1.spawn)('taskkill', ['/pid', String(proc.pid), '/f', '/t'], {
|
|
262
|
-
stdio: [
|
|
263
|
-
'ignore',
|
|
264
|
-
// Ignore following log to avoid polluting non-error logs. (Setting 'inherit' instead of 'ignore' attaches stdout to the root process and not to `proc` which is why the stdout of taskkill isn't intercepted by `proc.stdout.on('data', () => /* ... */)`.)
|
|
265
|
-
// ```
|
|
266
|
-
// SUCCESS: The process with PID 6932 (child process of PID 2744) has been terminated.
|
|
267
|
-
// ```
|
|
268
|
-
'ignore',
|
|
269
|
-
// Ignoring stderr doesn't solve the problem that taskkill makes the process exit with code 1
|
|
270
|
-
'inherit', // stderr
|
|
271
|
-
],
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
(0, utils_2.assert)(proc.pid);
|
|
276
|
-
const processGroup = -1 * proc.pid;
|
|
277
|
-
const signal = force ? 'SIGKILL' : 'SIGTERM';
|
|
278
|
-
process.kill(processGroup, signal);
|
|
279
|
-
/*
|
|
280
|
-
try {
|
|
281
|
-
process.kill(-proc.pid, signal)
|
|
282
|
-
} catch (err: unknown) {
|
|
283
|
-
// ESRCH: No process or process group can be found corresponding to that specified by pid.
|
|
284
|
-
// => probably means that the process was killed already.
|
|
285
|
-
if (typeof err === 'object' && err !== null && 'code' in err && err['code'] === 'ESRCH') {
|
|
286
|
-
printLog('stdout', '=============== swallowError')
|
|
287
|
-
return
|
|
288
|
-
} else {
|
|
289
|
-
printLog('stdout', '=============== no swallowError')
|
|
290
|
-
throw err
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
*/
|
|
294
|
-
}
|
|
295
|
-
return promise;
|
|
296
|
-
}
|
|
297
|
-
function execRunScript({ onStdout, onFailure, onExit, }) {
|
|
298
|
-
const { cwd, cmd } = getRunInfo();
|
|
299
|
-
let [command, ...args] = cmd.split(' ');
|
|
300
|
-
let detached = true;
|
|
301
|
-
if ((0, utils_1.isWindows)()) {
|
|
302
|
-
detached = false;
|
|
303
|
-
if (command === 'npm' || command === 'pnpm') {
|
|
304
|
-
command = command + '.cmd';
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
Logs_1.Logs.add({
|
|
308
|
-
logSource: 'run()',
|
|
309
|
-
logText: `Spawn command \`${cmd}\``,
|
|
310
|
-
});
|
|
311
|
-
const proc = (0, child_process_1.spawn)(command, args, { cwd, detached });
|
|
312
|
-
let procExited = false;
|
|
313
|
-
const exitAndFail = async (err) => {
|
|
314
|
-
Logs_1.Logs.add({
|
|
315
|
-
logText: err.message,
|
|
316
|
-
logSource: 'run() failure',
|
|
317
|
-
});
|
|
318
|
-
await terminate(true);
|
|
319
|
-
onFailure(err);
|
|
320
|
-
};
|
|
321
|
-
proc.stdin.on('data', async (chunk) => {
|
|
322
|
-
const data = String(chunk);
|
|
323
|
-
await exitAndFail(new Error(`Command is \`${cmd}\` (${cwd}) is invoking \`stdin\`: ${data}.`));
|
|
324
|
-
});
|
|
325
|
-
proc.stdout.on('data', (chunk) => {
|
|
326
|
-
const data = String(chunk);
|
|
327
|
-
Logs_1.Logs.add({
|
|
328
|
-
logSource: 'stdout',
|
|
329
|
-
logText: data,
|
|
330
|
-
loggedAfterExit: procExited,
|
|
331
|
-
});
|
|
332
|
-
onStdout?.(data);
|
|
333
|
-
});
|
|
334
|
-
proc.stderr.on('data', async (chunk) => {
|
|
335
|
-
const data = String(chunk);
|
|
336
|
-
Logs_1.Logs.add({
|
|
337
|
-
logSource: 'stderr',
|
|
338
|
-
logText: data,
|
|
339
|
-
loggedAfterExit: procExited,
|
|
340
|
-
});
|
|
341
|
-
if (data.includes('EADDRINUSE')) {
|
|
342
|
-
await exitAndFail(new Error('Port conflict? Port already in use EADDRINUSE.'));
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
let exitPromiseResolve;
|
|
346
|
-
const exitPromise = new Promise((r) => (exitPromiseResolve = r));
|
|
347
|
-
proc.on('exit', (code) => {
|
|
348
|
-
procExited = true;
|
|
349
|
-
(0, utils_2.assert)(getRunInfo().cmd === cmd);
|
|
350
|
-
const exitIsPossible = onExit();
|
|
351
|
-
const isSuccessCode = [0, null].includes(code) || ((0, utils_1.isWindows)() && code === 1);
|
|
352
|
-
const isExpected = isSuccessCode && exitIsPossible;
|
|
353
|
-
if (!isExpected) {
|
|
354
|
-
const errMsg = `Unexpected premature process termination, exit code: ${code}`;
|
|
355
|
-
Logs_1.Logs.add({
|
|
356
|
-
logText: errMsg,
|
|
357
|
-
logSource: 'run() failure',
|
|
358
|
-
});
|
|
359
|
-
onFailure(new Error(errMsg));
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
Logs_1.Logs.add({
|
|
363
|
-
logText: `Process termination. (Nominal, exit code: ${code}.)`,
|
|
364
|
-
logSource: 'run()',
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
exitPromiseResolve();
|
|
368
|
-
});
|
|
369
|
-
return { terminate, processHasExited };
|
|
370
|
-
function processHasExited() {
|
|
371
|
-
return procExited;
|
|
372
|
-
}
|
|
373
|
-
async function terminate(force) {
|
|
374
|
-
let resolve;
|
|
375
|
-
let reject;
|
|
376
|
-
const promise = new Promise((_resolve, _reject) => {
|
|
377
|
-
resolve = () => {
|
|
378
|
-
_resolve();
|
|
379
|
-
};
|
|
380
|
-
reject = () => {
|
|
381
|
-
_reject();
|
|
382
|
-
};
|
|
383
|
-
});
|
|
384
|
-
const timeout = setTimeout(() => {
|
|
385
|
-
const errMsg = 'Process termination timeout. Cmd: ' + cmd;
|
|
386
|
-
Logs_1.Logs.add({
|
|
387
|
-
logSource: 'run() failure',
|
|
388
|
-
logText: errMsg,
|
|
389
|
-
});
|
|
390
|
-
/* Don't interrupt the test runner, as the test runner may recover thanks to the process-killing-by-port
|
|
391
|
-
reject(new Error(errMsg))
|
|
392
|
-
*/
|
|
393
|
-
resolve();
|
|
394
|
-
}, TIMEOUT_PROCESS_TERMINATION);
|
|
395
|
-
(0, utils_2.assert)(proc);
|
|
396
|
-
try {
|
|
397
|
-
await stopProcess({
|
|
398
|
-
proc,
|
|
399
|
-
cwd,
|
|
400
|
-
cmd,
|
|
401
|
-
force,
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
catch (err) {
|
|
405
|
-
Logs_1.Logs.add({
|
|
406
|
-
logSource: 'run() failure',
|
|
407
|
-
logText: String(err),
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
clearTimeout(timeout);
|
|
411
|
-
await exitPromise;
|
|
412
|
-
resolve();
|
|
413
|
-
return promise;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
async function autoRetry(test, { timeout = TIMEOUT_AUTORETRY } = {}) {
|
|
417
|
-
const period = 100;
|
|
418
|
-
const numberOfTries = timeout / period;
|
|
419
|
-
let i = 0;
|
|
420
|
-
while (true) {
|
|
421
|
-
try {
|
|
422
|
-
await test();
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
catch (err) {
|
|
426
|
-
i = i + 1;
|
|
427
|
-
if (i > numberOfTries) {
|
|
428
|
-
throw err;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
await (0, utils_1.sleep)(period);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
exports.autoRetry = autoRetry;
|
|
435
|
-
async function fetchHtml(pathname) {
|
|
436
|
-
const response = await fetch(getServerUrl() + pathname);
|
|
437
|
-
const html = await response.text();
|
|
438
|
-
return html;
|
|
439
|
-
}
|
|
440
|
-
exports.fetchHtml = fetchHtml;
|
|
441
|
-
async function fetch(...args) {
|
|
442
|
-
try {
|
|
443
|
-
return await (0, node_fetch_1.default)(...args);
|
|
444
|
-
}
|
|
445
|
-
catch (err) {
|
|
446
|
-
Logs_1.Logs.add({
|
|
447
|
-
logSource: 'Connection Error',
|
|
448
|
-
logText: `Couldn't connect to \`${args[0]}\`. Args: \`${JSON.stringify(args.slice(1))}\`. Err: \`${
|
|
449
|
-
// @ts-ignore
|
|
450
|
-
err.message}\``,
|
|
451
|
-
});
|
|
452
|
-
throw new Error("Couldn't connect to server. See `Connection Error` log for more details.");
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
exports.fetch = fetch;
|
|
456
|
-
/*
|
|
457
|
-
async function bailOnTimeout(asyncFunc: () => Promise<void>, { timeout }: { timeout: number }) {
|
|
458
|
-
let resolve: () => void
|
|
459
|
-
let reject: (err: Error) => void
|
|
460
|
-
const promise = new Promise<void>((_resolve, _reject) => {
|
|
461
|
-
resolve = _resolve
|
|
462
|
-
reject = _reject
|
|
463
|
-
})
|
|
464
|
-
|
|
465
|
-
const t = setTimeout(() => {
|
|
466
|
-
reject(new Error(`Function timeout.`))
|
|
467
|
-
}, timeout)
|
|
468
|
-
await asyncFunc()
|
|
469
|
-
clearTimeout(t)
|
|
470
|
-
resolve()
|
|
471
|
-
|
|
472
|
-
return promise
|
|
473
|
-
}
|
|
474
|
-
*/
|
|
475
|
-
function isMinNodeVersion(minNodeVersion) {
|
|
476
|
-
const { version } = process;
|
|
477
|
-
(0, utils_2.assert)(version.startsWith('v'));
|
|
478
|
-
const major = parseInt(version[1] + version[2], 10);
|
|
479
|
-
(0, utils_2.assert)(12 <= major && major <= 50);
|
|
480
|
-
return major >= minNodeVersion;
|
|
481
|
-
}
|
|
482
|
-
exports.isMinNodeVersion = isMinNodeVersion;
|
|
483
|
-
function getCwd() {
|
|
484
|
-
const { testFile } = (0, getCurrentTest_1.getCurrentTest)();
|
|
485
|
-
const cwd = (0, path_1.dirname)(testFile);
|
|
486
|
-
return cwd;
|
|
487
|
-
}
|
|
488
|
-
function getServerUrl() {
|
|
489
|
-
const testInfo = (0, getCurrentTest_1.getCurrentTest)();
|
|
490
|
-
const serverUrl = testInfo.runInfo?.serverUrl;
|
|
491
|
-
return serverUrl;
|
|
492
|
-
}
|
|
493
|
-
exports.getServerUrl = getServerUrl;
|
|
494
|
-
function getPort() {
|
|
495
|
-
const serverUrl = getServerUrl();
|
|
496
|
-
const port = serverUrl.split(':').slice(-1)[0].split('/')[0];
|
|
497
|
-
(0, utils_2.assert)(/\d+/.test(port), { serverUrl });
|
|
498
|
-
return port;
|
|
499
|
-
}
|