@cloudflare/vitest-pool-workers 0.15.1 → 0.16.0

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.
@@ -461,7 +461,7 @@ var MetricsRegistry = class {
461
461
  };
462
462
 
463
463
  //#endregion
464
- //#region ../workers-utils/dist/chunk-A4F3D336.mjs
464
+ //#region ../workers-utils/dist/chunk-XXCQEG76.mjs
465
465
  var UserError = class extends Error {
466
466
  static {
467
467
  __name(this, "UserError");
@@ -470,7 +470,7 @@ var UserError = class extends Error {
470
470
  constructor(message, options) {
471
471
  super(message, options);
472
472
  Object.setPrototypeOf(this, new.target.prototype);
473
- this.telemetryMessage = options?.telemetryMessage === true ? message : options?.telemetryMessage;
473
+ this.telemetryMessage = typeof options?.telemetryMessage === "string" ? options.telemetryMessage : options?.telemetryMessage ? message : void 0;
474
474
  }
475
475
  };
476
476
  var DeprecationError = class extends UserError {
@@ -483,13 +483,14 @@ ${message}`, options);
483
483
  }
484
484
  };
485
485
  var FatalError = class extends UserError {
486
- constructor(message, code, options) {
487
- super(message, options);
488
- this.code = code;
489
- }
490
486
  static {
491
487
  __name(this, "FatalError");
492
488
  }
489
+ code;
490
+ constructor(message, options) {
491
+ super(message, options);
492
+ this.code = options.code;
493
+ }
493
494
  };
494
495
  var CommandLineArgsError = class extends UserError {
495
496
  static {
@@ -497,10 +498,6 @@ var CommandLineArgsError = class extends UserError {
497
498
  }
498
499
  };
499
500
  var JsonFriendlyFatalError = class extends FatalError {
500
- constructor(message, code, options) {
501
- super(message, code, options);
502
- this.code = code;
503
- }
504
501
  static {
505
502
  __name(this, "JsonFriendlyFatalError");
506
503
  }
@@ -515,9 +512,9 @@ var MissingConfigError = class extends Error {
515
512
  this.telemetryMessage = `Missing config value for ${key}`;
516
513
  }
517
514
  };
518
- function createFatalError(message, isJson, code, telemetryMessage) {
519
- if (isJson) return new JsonFriendlyFatalError(JSON.stringify(message), code, telemetryMessage);
520
- else return new FatalError(`${message}`, code, telemetryMessage);
515
+ function createFatalError(message, isJson, options) {
516
+ if (isJson) return new JsonFriendlyFatalError(JSON.stringify(message), options);
517
+ return new FatalError(`${message}`, options);
521
518
  }
522
519
  __name(createFatalError, "createFatalError");
523
520
  function createScanner(text, ignoreTrivia = false) {
@@ -2537,7 +2534,8 @@ function readFileSyncToBuffer(file2) {
2537
2534
  const { message } = err;
2538
2535
  throw new ParseError({
2539
2536
  text: `Could not read file: ${file2}`,
2540
- notes: [{ text: message.replace(file2, resolve(file2)) }]
2537
+ notes: [{ text: message.replace(file2, resolve(file2)) }],
2538
+ telemetryMessage: false
2541
2539
  });
2542
2540
  }
2543
2541
  }
@@ -2829,7 +2827,10 @@ function findRedirectedWranglerConfig(cwd, userConfigPath) {
2829
2827
  const deployConfig = parseJSONC(deployConfigFile, deployConfigPath);
2830
2828
  redirectedConfigPath = deployConfig.configPath && path.resolve(path.dirname(deployConfigPath), deployConfig.configPath);
2831
2829
  } catch (e) {
2832
- throw new UserError(`Failed to parse the deploy configuration file at ${path.relative(".", deployConfigPath)}`, { cause: e });
2830
+ throw new UserError(`Failed to parse the deploy configuration file at ${path.relative(".", deployConfigPath)}`, {
2831
+ cause: e,
2832
+ telemetryMessage: false
2833
+ });
2833
2834
  }
2834
2835
  if (!redirectedConfigPath) throw new UserError(esm_default`
2835
2836
  A deploy configuration file was found at "${path.relative(".", deployConfigPath)}".
@@ -2838,17 +2839,17 @@ function findRedirectedWranglerConfig(cwd, userConfigPath) {
2838
2839
  \`\`\`
2839
2840
  ${deployConfigFile}
2840
2841
  \`\`\`
2841
- `);
2842
+ `, { telemetryMessage: false });
2842
2843
  if (!existsSync(redirectedConfigPath)) throw new UserError(esm_default`
2843
2844
  There is a deploy configuration at "${path.relative(".", deployConfigPath)}".
2844
2845
  But the redirected configuration path it points to, "${path.relative(".", redirectedConfigPath)}", does not exist.
2845
- `);
2846
+ `, { telemetryMessage: false });
2846
2847
  if (userConfigPath) {
2847
2848
  if (path.join(path.dirname(userConfigPath), PATH_TO_DEPLOY_CONFIG) !== deployConfigPath) throw new UserError(esm_default`
2848
2849
  Found both a user configuration file at "${path.relative(".", userConfigPath)}"
2849
2850
  and a deploy configuration file at "${path.relative(".", deployConfigPath)}".
2850
2851
  But these do not share the same base path so it is not clear which should be used.
2851
- `);
2852
+ `, { telemetryMessage: false });
2852
2853
  }
2853
2854
  return {
2854
2855
  configPath: redirectedConfigPath,
@@ -7199,7 +7200,7 @@ function getBooleanEnvironmentVariableFactory(options) {
7199
7200
  switch (process.env[options.variableName]?.toLowerCase()) {
7200
7201
  case "true": return true;
7201
7202
  case "false": return false;
7202
- default: throw new UserError(`Expected ${options.variableName} to be "true" or "false", but got ${JSON.stringify(process.env[options.variableName])}`);
7203
+ default: throw new UserError(`Expected ${options.variableName} to be "true" or "false", but got ${JSON.stringify(process.env[options.variableName])}`, { telemetryMessage: false });
7203
7204
  }
7204
7205
  };
7205
7206
  }
@@ -7225,7 +7226,7 @@ function getProcessEnv(variableName, choices) {
7225
7226
  }
7226
7227
  __name(getProcessEnv, "getProcessEnv");
7227
7228
  function assertOneOf(choices, value) {
7228
- if (Array.isArray(choices) && !choices.includes(value)) throw new UserError(`Expected ${JSON.stringify(value)} to be one of ${JSON.stringify(choices)}`);
7229
+ if (Array.isArray(choices) && !choices.includes(value)) throw new UserError(`Expected ${JSON.stringify(value)} to be one of ${JSON.stringify(choices)}`, { telemetryMessage: false });
7229
7230
  }
7230
7231
  __name(assertOneOf, "assertOneOf");
7231
7232
  var getC3CommandFromEnv = getEnvironmentVariableFactory({
@@ -7249,7 +7250,7 @@ var getCloudflareComplianceRegion = /* @__PURE__ */ __name((complianceConfig) =>
7249
7250
  The compliance region has been set to different values in two places:
7250
7251
  - \`CLOUDFLARE_COMPLIANCE_REGION\` environment variable: \`${complianceRegionFromEnv}\`
7251
7252
  - \`compliance_region\` configuration property: \`${complianceConfig.compliance_region}\`
7252
- `);
7253
+ `, { telemetryMessage: false });
7253
7254
  return complianceRegionFromEnv || complianceConfig?.compliance_region || "public";
7254
7255
  }, "getCloudflareComplianceRegion");
7255
7256
  var getCloudflareApiBaseUrlFromEnv = getEnvironmentVariableFactory({
@@ -7787,7 +7788,7 @@ function applyPythonConfig(config, args) {
7787
7788
  type: "PythonModule",
7788
7789
  globs: ["**/*.py"]
7789
7790
  });
7790
- if (!config.compatibility_flags.includes("python_workers")) throw new UserError("The `python_workers` compatibility flag is required to use Python.");
7791
+ if (!config.compatibility_flags.includes("python_workers")) throw new UserError("The `python_workers` compatibility flag is required to use Python.", { telemetryMessage: false });
7791
7792
  }
7792
7793
  }
7793
7794
  __name(applyPythonConfig, "applyPythonConfig");
@@ -8083,7 +8084,6 @@ var validateStreamingTailConsumers = /* @__PURE__ */ __name((diagnostics, field,
8083
8084
  function normalizeAndValidateEnvironment(diagnostics, configPath, rawEnv, isDispatchNamespace, preserveOriginalMain, envName = "top level", topLevelEnv, useServiceEnvironments, rawConfig) {
8084
8085
  deprecated(diagnostics, rawEnv, "node_compat", `The "node_compat" field is no longer supported as of Wrangler v4. Instead, use the \`nodejs_compat\` compatibility flag. This includes the functionality from legacy \`node_compat\` polyfills and natively implemented Node.js APIs. See https://developers.cloudflare.com/workers/runtime-apis/nodejs for more information.`, true, "Removed", "error");
8085
8086
  experimental(diagnostics, rawEnv, "unsafe");
8086
- experimental(diagnostics, rawEnv, "secrets");
8087
8087
  const route = normalizeAndValidateRoute(diagnostics, topLevelEnv, rawEnv);
8088
8088
  const account_id = inheritableInWranglerEnvironments(diagnostics, useServiceEnvironments, topLevelEnv, mutateEmptyStringAccountIDValue(diagnostics, rawEnv), "account_id", isString, void 0, void 0);
8089
8089
  const routes = validateRoutes(diagnostics, topLevelEnv, rawEnv);
@@ -9583,6 +9583,7 @@ var validatePreviewsConfig = /* @__PURE__ */ __name((envName) => (diagnostics, f
9583
9583
  "secrets_store_secrets",
9584
9584
  "artifacts",
9585
9585
  "unsafe_hello_world",
9586
+ "flagship",
9586
9587
  "worker_loaders",
9587
9588
  "ratelimits",
9588
9589
  "vpc_services",
@@ -9618,6 +9619,7 @@ var validatePreviewsConfig = /* @__PURE__ */ __name((envName) => (diagnostics, f
9618
9619
  isValid2 = validateBindingArray(envName, validateSecretsStoreSecretBinding)(diagnostics, `${field}.secrets_store_secrets`, previews.secrets_store_secrets, void 0) && isValid2;
9619
9620
  isValid2 = validateBindingArray(envName, validateArtifactsBinding)(diagnostics, `${field}.artifacts`, previews.artifacts, void 0) && isValid2;
9620
9621
  isValid2 = validateBindingArray(envName, validateHelloWorldBinding)(diagnostics, `${field}.unsafe_hello_world`, previews.unsafe_hello_world, void 0) && isValid2;
9622
+ isValid2 = validateBindingArray(envName, validateFlagshipBinding)(diagnostics, `${field}.flagship`, previews.flagship, void 0) && isValid2;
9621
9623
  isValid2 = validateBindingArray(envName, validateWorkerLoaderBinding)(diagnostics, `${field}.worker_loaders`, previews.worker_loaders, void 0) && isValid2;
9622
9624
  isValid2 = validateBindingArray(envName, validateRateLimitBinding)(diagnostics, `${field}.ratelimits`, previews.ratelimits, void 0) && isValid2;
9623
9625
  isValid2 = validateBindingArray(envName, validateVpcServiceBinding)(diagnostics, `${field}.vpc_services`, previews.vpc_services, void 0) && isValid2;
@@ -9786,7 +9788,7 @@ function isDockerfile(imagePath, configPath) {
9786
9788
  const baseDir = configPath ? path.dirname(configPath) : process.cwd();
9787
9789
  const maybeDockerfile = path.resolve(baseDir, imagePath);
9788
9790
  if (fs.existsSync(maybeDockerfile)) {
9789
- if (isDirectory$1(maybeDockerfile)) throw new UserError(`${imagePath} is a directory, you should specify a path to the Dockerfile`);
9791
+ if (isDirectory$1(maybeDockerfile)) throw new UserError(`${imagePath} is a directory, you should specify a path to the Dockerfile`, { telemetryMessage: false });
9790
9792
  return true;
9791
9793
  }
9792
9794
  const errorPrefix = `The image "${imagePath}" does not appear to be a valid path to a Dockerfile, or a valid image registry path:
@@ -9794,12 +9796,12 @@ function isDockerfile(imagePath, configPath) {
9794
9796
  try {
9795
9797
  new URL(`https://${imagePath}`);
9796
9798
  } catch (e2) {
9797
- if (e2 instanceof Error) throw new UserError(errorPrefix + e2.message);
9799
+ if (e2 instanceof Error) throw new UserError(errorPrefix + e2.message, { telemetryMessage: false });
9798
9800
  throw e2;
9799
9801
  }
9800
9802
  const imageParts = imagePath.split("/");
9801
- if (!imageParts[imageParts.length - 1]?.includes(":")) throw new UserError(errorPrefix + `If this is an image registry path, it needs to include at least a tag ':' (e.g: docker.io/httpd:1)`);
9802
- if (imagePath.includes("://")) throw new UserError(errorPrefix + `Image reference should not include the protocol part (e.g: docker.io/httpd:1, not https://docker.io/httpd:1)`);
9803
+ if (!imageParts[imageParts.length - 1]?.includes(":")) throw new UserError(errorPrefix + `If this is an image registry path, it needs to include at least a tag ':' (e.g: docker.io/httpd:1)`, { telemetryMessage: false });
9804
+ if (imagePath.includes("://")) throw new UserError(errorPrefix + `Image reference should not include the protocol part (e.g: docker.io/httpd:1, not https://docker.io/httpd:1)`, { telemetryMessage: false });
9803
9805
  return false;
9804
9806
  }
9805
9807
  __name(isDockerfile, "isDockerfile");
@@ -9836,7 +9838,7 @@ var supportedPagesConfigFields = [
9836
9838
  ];
9837
9839
  function validatePagesConfig(config, envNames, projectName) {
9838
9840
  if (!config.pages_build_output_dir) throw new FatalError(`Attempting to validate Pages configuration file, but "pages_build_output_dir" field was not found.
9839
- "pages_build_output_dir" is required for Pages projects.`);
9841
+ "pages_build_output_dir" is required for Pages projects.`, { telemetryMessage: false });
9840
9842
  const diagnostics = new Diagnostics(`Running configuration file validation for Pages:`);
9841
9843
  validateMainField(config, diagnostics);
9842
9844
  validateProjectName(projectName, diagnostics);
@@ -9902,7 +9904,7 @@ function getGoArch() {
9902
9904
  cloudflared supports: x64 (amd64), arm64, arm
9903
9905
 
9904
9906
  You can manually install cloudflared and set the CLOUDFLARED_PATH environment variable.
9905
- Download instructions: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/`);
9907
+ Download instructions: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/`, { telemetryMessage: "tunnel cloudflared unsupported architecture" });
9906
9908
  }
9907
9909
  }
9908
9910
  __name(getGoArch, "getGoArch");
@@ -9916,7 +9918,7 @@ function getGoOS() {
9916
9918
  cloudflared supports: darwin (macOS), linux, win32 (Windows)
9917
9919
 
9918
9920
  You can manually install cloudflared and set the CLOUDFLARED_PATH environment variable.
9919
- Download instructions: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/`);
9921
+ Download instructions: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/`, { telemetryMessage: "tunnel cloudflared unsupported platform" });
9920
9922
  }
9921
9923
  }
9922
9924
  __name(getGoOS, "getGoOS");
@@ -9970,7 +9972,7 @@ The update service did not return results for ${goOS}/${goArch},
9970
9972
  and the fallback query also failed.
9971
9973
 
9972
9974
  You can manually install cloudflared from:
9973
- https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/`);
9975
+ https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/`, { telemetryMessage: "tunnel cloudflared version lookup failed" });
9974
9976
  const version = fallback.version;
9975
9977
  const filename = getAssetFilename(goOS, goArch);
9976
9978
  return {
@@ -10045,7 +10047,7 @@ You can try:
10045
10047
  errorMessage += ` 3. Manually installing cloudflared: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/
10046
10048
  `;
10047
10049
  errorMessage += ` 4. Setting CLOUDFLARED_PATH to point to your cloudflared binary`;
10048
- throw new UserError(errorMessage);
10050
+ throw new UserError(errorMessage, { telemetryMessage: "tunnel cloudflared validation failed" });
10049
10051
  }
10050
10052
  }
10051
10053
  __name(validateBinary, "validateBinary");
@@ -10139,14 +10141,14 @@ async function downloadCloudflared(versionInfo, binPath, options) {
10139
10141
  Network error: ${e2 instanceof Error ? e2.message : String(e2)}
10140
10142
 
10141
10143
  Please check your internet connection and try again.
10142
- If you're behind a proxy, make sure it's configured correctly.`);
10144
+ If you're behind a proxy, make sure it's configured correctly.`, { telemetryMessage: "tunnel cloudflared download network failed" });
10143
10145
  }
10144
10146
  if (!response.ok) throw new UserError(`[cloudflared] Failed to download cloudflared from ${url}
10145
10147
 
10146
10148
  HTTP ${response.status}: ${response.statusText}
10147
10149
 
10148
10150
  You can manually download cloudflared from:
10149
- https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/`);
10151
+ https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/`, { telemetryMessage: "tunnel cloudflared download response failed" });
10150
10152
  try {
10151
10153
  if (compressed) await downloadAndExtractTarball(response, checksum, binPath, cacheDir);
10152
10154
  else await downloadBinary(response, checksum, binPath);
@@ -10159,7 +10161,7 @@ https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-
10159
10161
 
10160
10162
  Error: ${e2 instanceof Error ? e2.message : String(e2)}
10161
10163
 
10162
- Please ensure you have write permissions to: ${cacheDir}`);
10164
+ Please ensure you have write permissions to: ${cacheDir}`, { telemetryMessage: "tunnel cloudflared save failed" });
10163
10165
  }
10164
10166
  if (process.platform !== "win32") chmodSync(binPath, 493);
10165
10167
  logger?.log(`cloudflared ${version} installed`);
@@ -10174,7 +10176,7 @@ async function downloadAndExtractTarball(response, expectedChecksum, binPath, ca
10174
10176
  if (actualSha256 !== expectedChecksum) throw new UserError(`[cloudflared] SHA256 mismatch for downloaded cloudflared tarball.
10175
10177
 
10176
10178
  Expected: ${expectedChecksum}
10177
- Actual: ${actualSha256}`);
10179
+ Actual: ${actualSha256}`, { telemetryMessage: "tunnel cloudflared tarball checksum mismatch" });
10178
10180
  }
10179
10181
  writeFileSync(tempTarPath, buffer);
10180
10182
  try {
@@ -10200,7 +10202,7 @@ async function downloadBinary(response, expectedChecksum, binPath) {
10200
10202
  if (actualSha256 !== expectedChecksum) throw new UserError(`[cloudflared] SHA256 mismatch for downloaded cloudflared binary.
10201
10203
 
10202
10204
  Expected: ${expectedChecksum}
10203
- Actual: ${actualSha256}`);
10205
+ Actual: ${actualSha256}`, { telemetryMessage: "tunnel cloudflared binary checksum mismatch" });
10204
10206
  }
10205
10207
  writeFileAtomic(binPath, buffer);
10206
10208
  }
@@ -10211,7 +10213,7 @@ async function getCloudflaredPath(options) {
10211
10213
  if (envPath) {
10212
10214
  if (!existsSync(envPath)) throw new UserError(`CLOUDFLARED_PATH is set to "${envPath}" but the file does not exist.
10213
10215
 
10214
- Please ensure the path points to a valid cloudflared binary.`);
10216
+ Please ensure the path points to a valid cloudflared binary.`, { telemetryMessage: "tunnel cloudflared env path missing" });
10215
10217
  logger?.debug(`Using cloudflared from CLOUDFLARED_PATH: ${envPath}`);
10216
10218
  return envPath;
10217
10219
  }
@@ -10237,7 +10239,7 @@ Please ensure the path points to a valid cloudflared binary.`);
10237
10239
  You can install it manually from:
10238
10240
  https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/
10239
10241
 
10240
- Then either add it to your PATH or set CLOUDFLARED_PATH.`);
10242
+ Then either add it to your PATH or set CLOUDFLARED_PATH.`, { telemetryMessage: "tunnel cloudflared download declined" });
10241
10243
  if (existsSync(binPath)) {
10242
10244
  const cacheDir = removeCloudflaredCache(versionInfo.version);
10243
10245
  if (cacheDir) logger?.log(`Removed cloudflared cache: ${cacheDir}`);
@@ -10443,7 +10445,7 @@ ${stderrOutput || "(no output)"}
10443
10445
 
10444
10446
  The local dev server started at ${origin.href}.
10445
10447
  ` + (isQuickTunnelRateLimited ? "Cloudflare Quick Tunnel creation was rate limited. Try again in a few minutes, or use a named tunnel if you need more reliable access." : `Check the cloudflared output above for more details, and verify that ${origin.href} is reachable from this machine if this keeps happening.`);
10446
- if (isQuickTunnelRateLimited) return new UserError(errorMessage);
10448
+ if (isQuickTunnelRateLimited) return new UserError(errorMessage, { telemetryMessage: false });
10447
10449
  return new Error(errorMessage);
10448
10450
  }
10449
10451
  __name(createTunnelStartupError, "createTunnelStartupError");
@@ -13132,6 +13134,13 @@ const RUNNER_OBJECT_BINDING = "__VITEST_POOL_WORKERS_RUNNER_OBJECT";
13132
13134
  async function buildProjectWorkerOptions(project, customOptions, main) {
13133
13135
  const relativeWranglerConfigPath = maybeApply((v) => path.relative("", v), customOptions.wrangler?.configPath);
13134
13136
  const runnerWorker = customOptions.miniflare ?? {};
13137
+ const wranglerWorkerName = getWranglerWorkerName(relativeWranglerConfigPath);
13138
+ if (wranglerWorkerName && runnerWorker.serviceBindings) {
13139
+ for (const [key, sb] of Object.entries(runnerWorker.serviceBindings)) if (typeof sb === "object" && sb !== null && "name" in sb && sb.name === wranglerWorkerName) runnerWorker.serviceBindings[key] = {
13140
+ ...sb,
13141
+ name: kCurrentWorker
13142
+ };
13143
+ }
13135
13144
  runnerWorker.name = getRunnerName(project);
13136
13145
  runnerWorker.compatibilityFlags ??= [];
13137
13146
  runnerWorker.compatibilityFlags.push("no_handle_cross_request_promise_resolution");