Skip to content

Commit

Permalink
fix: use builtin node:process module over polyfill for Vitest pool (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot authored Feb 26, 2024
1 parent 2aa7913 commit d4b4c3a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 346 deletions.
1 change: 1 addition & 0 deletions packages/vitest-pool-workers/src/mock-agent/index.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
globalThis.global = globalThis;
process.versions = { node: "18.0.0" };

const MockAgent = require("undici/lib/mock/mock-agent");
const { kClients } = require("undici/lib/core/symbols");
Expand Down
6 changes: 1 addition & 5 deletions packages/vitest-pool-workers/src/pool/module-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ function trimSuffix(suffix: string, value: string) {
}

// Node.js built-in modules provided by `workerd`
const workerdBuiltinModules = VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES.filter(
// `workerd`'s implementation of "node:process" doesn't support everything we
// need, so use our polyfill instead
(specifier) => specifier !== "node:process"
);
const workerdBuiltinModules = VITEST_POOL_WORKERS_DEFINE_BUILTIN_MODULES;
const conditions = new Set(["workerd", "worker", "browser", "import"]);

// `chai` contains circular `require()`s which aren't supported by `workerd`
Expand Down
6 changes: 6 additions & 0 deletions packages/vitest-pool-workers/src/worker/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from "node:assert";
import { Buffer } from "node:buffer";
import events from "node:events";
import process from "node:process";
import * as vm from "node:vm";
import {
importModule,
Expand All @@ -24,6 +25,11 @@ function structuredSerializableParse(value: string): unknown {
}

globalThis.Buffer = Buffer; // Required by `vite-node/source-map`

globalThis.process = process; // Required by `vite-node`
process.argv = []; // Required by `@vitest/utils`
Object.setPrototypeOf(process, events.EventEmitter.prototype); // Required by `vitest`

globalThis.__console = console;

const originalSetTimeout = globalThis.setTimeout;
Expand Down
341 changes: 0 additions & 341 deletions packages/vitest-pool-workers/src/worker/lib/node/process.cts

This file was deleted.

0 comments on commit d4b4c3a

Please sign in to comment.