Files
wehub-resource-sync 70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:11 +08:00

40 lines
1.7 KiB
TypeScript

import { describe, test } from "vitest";
import { runLongLived, seed } from "./helpers";
describe("nodejs_compat warnings - Node.js built-ins imported directly", () => {
const projectPath = seed("nodejs-compat-warnings/direct-import", {
pm: "pnpm",
});
test("displays warnings if Node.js built-ins are imported and the `nodejs_compat` flag is not enabled", async ({
expect,
}) => {
const proc = await runLongLived("pnpm", "dev", projectPath);
expect(await proc.exitCode).not.toBe(0);
const errorLogs = proc.stderr.replaceAll("\\", "/");
expect(errorLogs).toContain(
'Unexpected Node.js imports for environment "worker". Do you need to enable the "nodejs_compat" compatibility flag? Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details.'
);
expect(errorLogs).toContain('- "node:assert/strict" imported from');
expect(errorLogs).toContain('- "node:perf_hooks" imported from');
});
});
describe("nodejs_compat warnings - Node.js built-ins imported via dependency", () => {
const projectPath = seed("nodejs-compat-warnings/dependency-import", {
pm: "pnpm",
});
test("displays warnings if Node.js built-ins are imported and the `nodejs_compat` flag is not enabled", async ({
expect,
}) => {
const proc = await runLongLived("pnpm", "dev", projectPath);
expect(await proc.exitCode).not.toBe(0);
const errorLogs = proc.stderr.replaceAll("\\", "/");
expect(errorLogs).toContain(
'Unexpected Node.js imports for environment "worker". Do you need to enable the "nodejs_compat" compatibility flag? Refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/ for more details.'
);
expect(errorLogs).toContain('- "node:fs" imported from');
});
});