Skip to content

Commit 625f05b

Browse files
dividedmindclaude
andcommitted
test: switch main project to node-modules linker, add pnpm-compat sub-project
Yarn 4 changed the pnpm linker's .store subdirectory name to 'package/' (was the package name in yarn 3), breaking path-based hook detection. Switch the main project to nodeLinker: node-modules to avoid the issue, and add test/pnpm-compat/ as a minimal independent yarn sub-project with nodeLinker: pnpm to specifically test the pnpm linker path format support. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 17e0acc commit 625f05b

17 files changed

Lines changed: 1670 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ jobs:
4343
node-version: ${{matrix.node-version}}
4444
cache: yarn
4545
- run: yarn
46+
- uses: actions/cache@v4
47+
with:
48+
path: |
49+
test/pnpm-compat/.yarn/cache
50+
test/pnpm-compat/.yarn/global
51+
key: pnpm-compat-yarn-${{ runner.os }}-${{ hashFiles('test/pnpm-compat/yarn.lock') }}
4652
- run: node test/smoketest.mjs
4753
- run: yarn test
4854
env:
@@ -57,6 +63,12 @@ jobs:
5763
with:
5864
cache: yarn
5965
- run: yarn
66+
- uses: actions/cache@v4
67+
with:
68+
path: |
69+
test/pnpm-compat/.yarn/cache
70+
test/pnpm-compat/.yarn/global
71+
key: pnpm-compat-yarn-${{ runner.os }}-${{ hashFiles('test/pnpm-compat/yarn.lock') }}
6072
- run: yarn prepack
6173
- run: yarn test || yarn jest --no-silent --verbose --onlyFailures
6274
- run: node test/smoketest.mjs

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ compressionLevel: mixed
22

33
enableGlobalCache: true
44

5-
nodeLinker: pnpm
5+
nodeLinker: node-modules
66

77
npmMinimalAgeGate: 2880
88

test/__snapshots__/next16.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ exports[`mapping a Next.js 16 appmap 1`] = `
192192
"http_server_response": {
193193
"headers": {
194194
"Cache-Control": "no-store, must-revalidate",
195-
"Content-Length": "2238",
195+
"Content-Length": "2210",
196196
"Content-Type": "text/html; charset=utf-8",
197197
"Vary": "Accept-Encoding",
198198
"X-Powered-By": "Next.js",

test/next.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { IncomingMessage, request } from "node:http";
2+
import { resolve } from "node:path";
23

34
import { getFreePort, integrationTest, readAppmaps, spawnAppmapNode } from "./helpers";
45

6+
const nextBin = require.resolve("next/dist/bin/next", {
7+
paths: [resolve(__dirname, "next")],
8+
});
9+
510
async function spawnNextJsApp(port: number) {
611
// On Windows, we give "node" argument explicitly because next is a js file with
712
// shebang (#!/usr/bin/env node) which does not work on Windows.
813
const app =
914
process.platform == "win32"
10-
? spawnAppmapNode("node", "node_modules\\next\\dist\\bin\\next", "dev", "-p", String(port))
11-
: spawnAppmapNode("node_modules/next/dist/bin/next", "dev", "-p", String(port));
15+
? spawnAppmapNode("node", nextBin, "dev", "-p", String(port))
16+
: spawnAppmapNode(nextBin, "dev", "-p", String(port));
1217

1318
await new Promise<void>((r) => {
1419
const onData = (chunk: Buffer) => {

test/next16.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import { IncomingMessage, request } from "node:http";
2+
import { resolve } from "node:path";
23

34
import { getFreePort, integrationTest, readAppmaps, spawnAppmapNode } from "./helpers";
45

6+
const nextBin = require.resolve("next/dist/bin/next", {
7+
paths: [resolve(__dirname, "next16")],
8+
});
9+
510
async function spawnNextJsApp(port: number) {
611
// On Windows, we give "node" argument explicitly because next is a js file with
712
// shebang (#!/usr/bin/env node) which does not work on Windows.
813
// Turbopack (the default bundler in Next.js 16) respects webpack loaders configured
914
// via next.config turbopack.rules, which we inject in src/hooks/next.ts.
1015
const app =
1116
process.platform == "win32"
12-
? spawnAppmapNode("node", "node_modules\\next\\dist\\bin\\next", "dev", "-p", String(port))
13-
: spawnAppmapNode("node_modules/next/dist/bin/next", "dev", "-p", String(port));
17+
? spawnAppmapNode("node", nextBin, "dev", "-p", String(port))
18+
: spawnAppmapNode(nextBin, "dev", "-p", String(port));
1419

1520
await new Promise<void>((r) => {
1621
const onData = (chunk: Buffer) => {

test/pnpm-compat.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { spawnSync } from "node:child_process";
2+
import { existsSync } from "node:fs";
3+
import { resolve } from "node:path";
4+
5+
import { integrationTest, readAppmaps, runAppmapNode } from "./helpers";
6+
7+
// This test runs vitest in a separate project installed with yarn pnpm linker,
8+
// verifying that matchesPackageFile() correctly identifies hook targets in the
9+
// .store/pkg-npm-version-hash/package/ path format used by yarn 4 pnpm linker.
10+
11+
integrationTest("pnpm linker: vitest hooks instrument code in .store paths", () => {
12+
const dir = resolve(__dirname, "pnpm-compat");
13+
if (!existsSync(resolve(dir, "node_modules")))
14+
spawnSync("yarn", ["install"], { cwd: dir, stdio: "inherit" });
15+
16+
expect(runAppmapNode("yarn", "vitest", "run").status).toBe(0);
17+
expect(readAppmaps()).not.toEqual({});
18+
});

test/pnpm-compat/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.yarn/

test/pnpm-compat/.yarnrc.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
nodeLinker: pnpm
2+
3+
enableGlobalCache: false
4+
5+
cacheFolder: ./.yarn/cache
6+
7+
globalFolder: ./.yarn/global
8+
9+
yarnPath: ../../.yarn/releases/yarn-4.13.0.cjs

test/pnpm-compat/appmap.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: pnpm-compat-appmap-node-test
2+
packages:
3+
- path: .
4+
language: javascript

test/pnpm-compat/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "pnpm-compat-appmap-node-test",
3+
"private": true,
4+
"dependencies": {
5+
"vitest": "^0.34.6"
6+
}
7+
}

0 commit comments

Comments
 (0)