@hughescr/stryker-bun-runner 1.7.0 → 1.7.2

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.
@@ -341,6 +341,9 @@ function formatSyncNotReadyMessage(syncPort, problem) {
341
341
  "would not be seen by the runner's inspector, so their results and per-test coverage would be lost."
342
342
  ].join(" ");
343
343
  }
344
+ function formatDrainRequest(startedTests) {
345
+ return `drain-request ${startedTests}`;
346
+ }
344
347
  var PRELOAD_TIMINGS_ENV = "__STRYKER_PRELOAD_TIMINGS__";
345
348
  function preloadEpochNow() {
346
349
  return performance.timeOrigin + performance.now();
@@ -946,6 +949,7 @@ var discovering = plan?.mode === "discover";
946
949
  var shouldCollectCoverage2 = shouldCollectCoverage(config) || discovering;
947
950
  var ws = null;
948
951
  var DRAIN_ACK_TIMEOUT_MS = 40000;
952
+ var DRAIN_HOOK_TIMEOUT_MS = DRAIN_ACK_TIMEOUT_MS + 20000;
949
953
  var perFileCounters = new Map;
950
954
  function extractFilePrefix(bunMain) {
951
955
  if (!bunMain) {
@@ -1066,7 +1070,7 @@ var drainAndClose = async () => {
1066
1070
  if (timings) {
1067
1071
  timings["at.drainRequested"] = nowEpoch();
1068
1072
  }
1069
- wsForDrain.send("drain-request");
1073
+ wsForDrain.send(formatDrainRequest(startedTests));
1070
1074
  } catch {
1071
1075
  clearTimeout(timeout);
1072
1076
  resolve();
@@ -1137,5 +1141,5 @@ if (shouldCollectCoverage2) {
1137
1141
  lateHits.length = 0;
1138
1142
  writeDryRunRecord();
1139
1143
  await drainAndClose();
1140
- });
1144
+ }, DRAIN_HOOK_TIMEOUT_MS);
1141
1145
  }
@@ -4,6 +4,12 @@ import { readFileSync, realpathSync, statSync } from "fs";
4
4
  import { createRequire, isBuiltin } from "module";
5
5
  import path from "path";
6
6
  import { pathToFileURL } from "url";
7
+
8
+ // src/utils/code-files.ts
9
+ var CODE_EXTENSION_PATTERN = String.raw`(?:[jt]sx?|[mc][jt]s)`;
10
+ var CODE_FILE_RE = new RegExp(String.raw`\.${CODE_EXTENSION_PATTERN}$`);
11
+
12
+ // src/coverage/import-scan.ts
7
13
  var INSTRUMENTER_GLOBAL_IDIOM = 'globalThis.Math === Math && globalThis || new Function("return this")()';
8
14
 
9
15
  class ScanProblem extends Error {
@@ -533,7 +539,6 @@ function loaderOf(file) {
533
539
  }
534
540
  return /\.[cm]js$/.test(file) ? "js" : "jsx";
535
541
  }
536
- var CODE_FILE = /\.(?:[cm]?[jt]s|[jt]sx)$/;
537
542
  var JSX_RUNTIME = /^.+\/jsx(?:-dev)?-runtime$/;
538
543
  var DIRECTORY_CONFIGS = ["tsconfig.json", "jsconfig.json"];
539
544
  var RUNTIME = "/jsx-runtime";
@@ -582,6 +587,7 @@ function real(file) {
582
587
  return file;
583
588
  }
584
589
  }
590
+ var SCAN_DEFINE = Object.fromEntries(["process.env.NODE_ENV", "process.env.BUN_ENV", "process.browser"].map((key) => [key, key]));
585
591
 
586
592
  class ImportScan {
587
593
  input;
@@ -594,7 +600,7 @@ class ImportScan {
594
600
  notes = [];
595
601
  tsconfig;
596
602
  transpilers = new Map;
597
- outputScanner = new Bun.Transpiler({ loader: "js" });
603
+ outputScanner = new Bun.Transpiler({ loader: "js", define: SCAN_DEFINE });
598
604
  resolutions = new Map;
599
605
  requires = new Map;
600
606
  configChains = new Map;
@@ -697,7 +703,7 @@ class ImportScan {
697
703
  const key = `${loader} ${autoImportJSX}`;
698
704
  let transpiler = this.transpilers.get(key);
699
705
  if (transpiler === undefined) {
700
- const options = { loader, trimUnusedImports: loader === "ts" || loader === "tsx", autoImportJSX };
706
+ const options = { loader, trimUnusedImports: loader === "ts" || loader === "tsx", autoImportJSX, define: SCAN_DEFINE };
701
707
  try {
702
708
  transpiler = new Bun.Transpiler({ ...options, ...this.tsconfig === undefined ? {} : { tsconfig: this.tsconfig } });
703
709
  } catch (error) {
@@ -790,7 +796,7 @@ class ImportScan {
790
796
  if (importTarget !== requireTarget) {
791
797
  return { kind: "unknown", reason: `${where} resolves differently for import and require` };
792
798
  }
793
- return CODE_FILE.test(importTarget) ? { kind: "follow", file: importTarget } : { kind: "ignore", projectFile: true };
799
+ return CODE_FILE_RE.test(importTarget) ? { kind: "follow", file: importTarget } : { kind: "ignore", projectFile: true };
794
800
  }
795
801
  isProjectCode(target) {
796
802
  return path.isAbsolute(target) && (!this.isPackageCode(target) || this.candidatesAt.has(target));
@@ -890,6 +896,7 @@ if (import.meta.main) {
890
896
  export {
891
897
  INSTRUMENTER_GLOBAL_IDIOM,
892
898
  MACRO_ATTRIBUTE,
899
+ SCAN_DEFINE,
893
900
  ScanProblem,
894
901
  analyseOutput,
895
902
  generatedJsxResolution,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hughescr/stryker-bun-runner",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Stryker mutation testing test runner plugin for Bun (bun test), with per-test coverage",
5
5
  "keywords": [
6
6
  "stryker",