Skip to content

Commit d4b4c3a

Browse files
authored
fix: use builtin node:process module over polyfill for Vitest pool (#5101)
1 parent 2aa7913 commit d4b4c3a

File tree

4 files changed

+8
-346
lines changed

4 files changed

+8
-346
lines changed

packages/vitest-pool-workers/src/mock-agent/index.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
globalThis.global = globalThis;
2+
process.versions = { node: "18.0.0" };
23

34
const MockAgent = require("undici/lib/mock/mock-agent");
45
const { kClients } = require("undici/lib/core/symbols");

packages/vitest-pool-workers/src/pool/module-fallback.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ function trimSuffix(suffix: string, value: string) {
3939
}
4040

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

4945
// `chai` contains circular `require()`s which aren't supported by `workerd`

packages/vitest-pool-workers/src/worker/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from "node:assert";
22
import { Buffer } from "node:buffer";
33
import events from "node:events";
4+
import process from "node:process";
45
import * as vm from "node:vm";
56
import {
67
importModule,
@@ -24,6 +25,11 @@ function structuredSerializableParse(value: string): unknown {
2425
}
2526

2627
globalThis.Buffer = Buffer; // Required by `vite-node/source-map`
28+
29+
globalThis.process = process; // Required by `vite-node`
30+
process.argv = []; // Required by `@vitest/utils`
31+
Object.setPrototypeOf(process, events.EventEmitter.prototype); // Required by `vitest`
32+
2733
globalThis.__console = console;
2834

2935
const originalSetTimeout = globalThis.setTimeout;

packages/vitest-pool-workers/src/worker/lib/node/process.cts

Lines changed: 0 additions & 341 deletions
This file was deleted.

0 commit comments

Comments
 (0)