Test: the detectProject "cf package" test fails under `pnpm test` because pnpm's `vp` shim sets NODE_PATH

Open Beginner friendly
#4,585 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
79/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript, vite
Domain
devtools, testing

Research direction

Start with the detectProject tests in tests/deploy.test.ts and the isPackageResolvable lookup described in the issue. Run the focused test through pnpm test, then compare it with the same test using the global vp or with NODE_PATH removed. Done means both Wrangler presence tests give consistent results based only on the test project's dependencies.

Written by the indexing model from the issue text.

Description

What happens

The detectProject test "does not mistake the separate cf package for Wrangler" fails when the suite runs through pnpm test, the command AGENTS.md documents:

FAIL  tests/deploy.test.ts > detectProject > does not mistake the separate cf package for Wrangler
AssertionError: expected true to be false // Object.is equality

pnpm's bin shim for vp sets NODE_PATH, and the last entry is the workspace's node_modules/.pnpm/node_modules. Wrangler is installed there. detectProject finds Wrangler with createRequire(root).resolve("wrangler/package.json") (isPackageResolvable), and Node's resolver also searches NODE_PATH, so the lookup finds the workspace's Wrangler instead of the test project's. CI runs a global vp with no NODE_PATH, so it never sees the failure.

Repro

On current main, after pnpm install:

pnpm test tests/deploy.test.ts -t "does not mistake the separate cf package"
# Tests  1 failed

# same binary, NODE_PATH removed
env -u NODE_PATH node node_modules/.pnpm/vite-plus@*/node_modules/vite-plus/bin/vp \
  test run tests/deploy.test.ts -t "does not mistake the separate cf package"
# Tests  1 passed

The mechanism without vinext:

// resolve.mjs
import { createRequire } from "node:module";
import path from "node:path";

const req = createRequire(path.join(process.argv[2], "package.json"));
try {
  console.log(req.resolve("wrangler/package.json"));
} catch {
  console.log("not resolvable");
}
mkdir -p global/wrangler project
echo '{"name":"wrangler"}' > global/wrangler/package.json
echo '{}' > project/package.json

node resolve.mjs project                       # not resolvable
NODE_PATH=$PWD/global node resolve.mjs project # …/global/wrangler/package.json
Expected

The Wrangler presence tests give the same result under pnpm test and a global vp, checking only the test project's own node_modules.

The positive companion test, "detects Wrangler independently of its executable shim", passes under the pnpm shim even without its fixture package, for the same reason.

Dominant language
TypeScript
Stars
9.3k
Forks
463
Avg merge
22h 22m
Merged PRs (30d)
502

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/vinext

All issues in cloudflare/vinext

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.