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