qunitx-cli 0.22.1 → 0.22.3

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.
Files changed (2) hide show
  1. package/dist/cli.js +41 -31
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -2037,6 +2037,27 @@ var init_open_output_in_browser = __esm({
2037
2037
  }
2038
2038
  });
2039
2039
 
2040
+ // lib/utils/close-with-grace.ts
2041
+ function closeWithGrace(closes, graceMs = CLEANUP_GRACE_MS) {
2042
+ return new Promise((resolve) => {
2043
+ const timer = setTimeout(() => {
2044
+ process.stderr.write(`# qunitx: cleanup timed out after ${graceMs} ms \u2014 exiting anyway
2045
+ `);
2046
+ resolve();
2047
+ }, graceMs);
2048
+ Promise.allSettled(closes).then(() => {
2049
+ clearTimeout(timer);
2050
+ resolve();
2051
+ });
2052
+ });
2053
+ }
2054
+ var CLEANUP_GRACE_MS;
2055
+ var init_close_with_grace = __esm({
2056
+ "lib/utils/close-with-grace.ts"() {
2057
+ CLEANUP_GRACE_MS = 1e4;
2058
+ }
2059
+ });
2060
+
2040
2061
  // lib/utils/time-counter.ts
2041
2062
  function timeCounter() {
2042
2063
  const startTime = /* @__PURE__ */ new Date();
@@ -2273,11 +2294,11 @@ async function runTestsInBrowser(config, cachedContent = {}, connections, target
2273
2294
  }
2274
2295
  if (!config.watch) {
2275
2296
  await flushConsoleHandlers(config._pendingConsoleHandlers);
2276
- await Promise.all([
2277
- connections.server && connections.server.close(),
2278
- connections.browser && connections.browser.close()
2297
+ await closeWithGrace([
2298
+ connections.server?.close(),
2299
+ connections.browser?.close(),
2300
+ shutdownPrelaunch()
2279
2301
  ]);
2280
- await shutdownPrelaunch();
2281
2302
  return process.exit(config.COUNTER.failCount > 0 ? 1 : 0);
2282
2303
  }
2283
2304
  }
@@ -2593,11 +2614,11 @@ async function failOnNonWatchMode(watchMode = false, connections = {}, groupMode
2593
2614
  throw new Error("Browser test run failed");
2594
2615
  }
2595
2616
  await flushConsoleHandlers(pendingHandlers);
2596
- await Promise.all([
2597
- connections.server && connections.server.close(),
2598
- connections.browser && connections.browser.close()
2617
+ await closeWithGrace([
2618
+ connections.server?.close(),
2619
+ connections.browser?.close(),
2620
+ shutdownPrelaunch()
2599
2621
  ]);
2600
- await shutdownPrelaunch();
2601
2622
  process.exit(1);
2602
2623
  }
2603
2624
  }
@@ -2612,6 +2633,7 @@ var init_tests_in_browser = __esm({
2612
2633
  "lib/commands/run/tests-in-browser.ts"() {
2613
2634
  init_color();
2614
2635
  init_chrome_prelaunch();
2636
+ init_close_with_grace();
2615
2637
  init_time_counter();
2616
2638
  init_run_user_module();
2617
2639
  init_display_final_result();
@@ -3068,7 +3090,7 @@ async function run(config) {
3068
3090
  config.webServer = connections.server;
3069
3091
  setupKeyboardEvents(config, cachedContent, connections);
3070
3092
  process.once("SIGTERM", () => {
3071
- connections.server.close().finally(() => process.exit(EXIT_CODE_SIGTERM));
3093
+ closeWithGrace([connections.server.close()]).finally(() => process.exit(EXIT_CODE_SIGTERM));
3072
3094
  });
3073
3095
  const isHeadedWatchMode = config.open === true && config.watch;
3074
3096
  if (config.open && !isHeadedWatchMode) {
@@ -3080,10 +3102,7 @@ async function run(config) {
3080
3102
  try {
3081
3103
  await runTestsInBrowser(config, cachedContent, connections);
3082
3104
  } catch (error) {
3083
- await Promise.all([
3084
- connections.server && connections.server.close(),
3085
- connections.browser && connections.browser.close()
3086
- ]);
3105
+ await closeWithGrace([connections.server?.close(), connections.browser?.close()]);
3087
3106
  throw error;
3088
3107
  }
3089
3108
  if (isHeadedWatchMode && (cachedContent._buildError || cachedContent._noTestsWarning)) {
@@ -3224,18 +3243,9 @@ async function run(config) {
3224
3243
  await runTestsInBrowser(groupConfig, groupCachedContents[i], connections);
3225
3244
  } finally {
3226
3245
  await flushConsoleHandlers(groupConfig._pendingConsoleHandlers);
3227
- await Promise.all([
3228
- !sharedServer && connections.server?.close(),
3229
- connections.page && // Unref'd: the keepAlive interval above holds the event loop open, so this
3230
- // timer still fires if page.close() hangs, without preventing process exit later.
3231
- Promise.race([
3232
- connections.page.close(),
3233
- new Promise((resolve) => {
3234
- const pageCloseTimeoutId = setTimeout(resolve, PAGE_CLOSE_GRACE_MS);
3235
- pageCloseTimeoutId.unref();
3236
- })
3237
- ]).catch(() => {
3238
- })
3246
+ await closeWithGrace([
3247
+ sharedServer ? void 0 : connections.server?.close(),
3248
+ connections.page?.close()
3239
3249
  ]);
3240
3250
  }
3241
3251
  })();
@@ -3273,7 +3283,7 @@ async function run(config) {
3273
3283
  exitTimer.unref();
3274
3284
  process.stdout.write("\n", async () => {
3275
3285
  clearTimeout(exitTimer);
3276
- await Promise.all([
3286
+ await closeWithGrace([
3277
3287
  sharedServer?.close().catch(
3278
3288
  (err) => config.debug && process.stderr.write(`# [qunitx] server.close: ${err.message}
3279
3289
  `)
@@ -3281,9 +3291,9 @@ async function run(config) {
3281
3291
  browser.close().catch(
3282
3292
  (err) => config.debug && process.stderr.write(`# [qunitx] browser.close: ${err.message}
3283
3293
  `)
3284
- )
3294
+ ),
3295
+ shutdownPrelaunch()
3285
3296
  ]);
3286
- await shutdownPrelaunch();
3287
3297
  clearInterval(keepAlive);
3288
3298
  process.exit(exitCode);
3289
3299
  });
@@ -3419,7 +3429,7 @@ function resolveQunitxRoot(projectRoot) {
3419
3429
  if (!match) throw new Error(`Could not derive qunitx root from ${mainEntry}`);
3420
3430
  return match[1];
3421
3431
  }
3422
- var WATCH_NAV_TIMEOUT_MS, PAGE_CLOSE_GRACE_MS, STDOUT_FLUSH_GRACE_MS, KEEP_ALIVE_INTERVAL_MS, EXIT_CODE_SIGTERM;
3432
+ var WATCH_NAV_TIMEOUT_MS, STDOUT_FLUSH_GRACE_MS, KEEP_ALIVE_INTERVAL_MS, EXIT_CODE_SIGTERM;
3423
3433
  var init_run = __esm({
3424
3434
  "lib/commands/run.ts"() {
3425
3435
  init_browser();
@@ -3439,8 +3449,8 @@ var init_run = __esm({
3439
3449
  init_display_final_result();
3440
3450
  init_read_template();
3441
3451
  init_html();
3452
+ init_close_with_grace();
3442
3453
  WATCH_NAV_TIMEOUT_MS = 5e3;
3443
- PAGE_CLOSE_GRACE_MS = 1e4;
3444
3454
  STDOUT_FLUSH_GRACE_MS = 5e3;
3445
3455
  KEEP_ALIVE_INTERVAL_MS = 1e4;
3446
3456
  EXIT_CODE_SIGTERM = 128 + 15;
@@ -3458,7 +3468,7 @@ init_color();
3458
3468
  var package_default = {
3459
3469
  name: "qunitx-cli",
3460
3470
  type: "module",
3461
- version: "0.22.1",
3471
+ version: "0.22.3",
3462
3472
  description: "Browser runner for QUnitx: run your qunitx tests in google-chrome",
3463
3473
  author: "Izel Nakri",
3464
3474
  license: "MIT",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qunitx-cli",
3
3
  "type": "module",
4
- "version": "0.22.1",
4
+ "version": "0.22.3",
5
5
  "description": "Browser runner for QUnitx: run your qunitx tests in google-chrome",
6
6
  "author": "Izel Nakri",
7
7
  "license": "MIT",