Skip to content

test(plugins): stop changing the process directory in tests - #971

Merged
owjs3901 merged 1 commit into
mainfrom
test/no-process-chdir
Nov 15, 2026
Merged

owjs3901 merged 1 commit into
mainfrom
test/no-process-chdir

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Summary

딥 오딧 INF-03의 남은 부분입니다. #744에서 resetBuildState가 들어왔지만, TypeScript 테스트 6개 파일은 여전히 process.chdir을 호출해서 테스트 순서와 실행 위치에 따라 결과가 달라질 수 있었습니다. 이제 이 파일들은 fixture 루트를 명시적으로 넘기고, 프로세스 디렉터리를 바꾸지 않습니다. 테스트 파일만 바꿨고 소스는 건드리지 않았습니다. 그래서 changepack도 넣지 않았습니다.

grep -rn "process.chdir" packages --include=*.ts --include=*.tsx (node_modules, dist 제외) 결과가 이제 0건입니다.

같은 테스트 프로세스 안에서 chdir하던 파일 (순서 의존의 실제 원인):

  • next-plugin/__tests__/deterministic-numbering.test.ts: 경로를 모두 root 기준으로 만들고 있어서 chdir가 필요 없었습니다. 삭제했습니다.
  • next-plugin/__tests__/imported-styled.test.ts: withModuleResolver가 process.cwd() 기준 상대 id를 만듭니다. 그래서 chdir 대신 spyOn(process, 'cwd').mockReturnValue(root)를 쓰고 afterEach에서 복원합니다. 이 함수에 root 파라미터가 없어 소스를 고치는 방법도 있었지만, fix(plugins): resolve relative options against the bundler project root #962/#934와 겹치지 않도록 테스트 쪽 mock을 택했습니다.

자식 프로세스 안에서 chdir하던 파일: 자식을 fixture를 cwd로 띄우고, 자식 안에서는 cwd가 fixture인지 realpathSync.native로 assert만 합니다.

  • next-plugin/__tests__/plugin.test.ts (native Turbo prewarm): fixture를 부모에서 만들고 spawnSync({ cwd: root })로 실행합니다. 정리도 부모가 합니다.
  • next-plugin/__tests__/atom-hoist-harness.ts: execFileSync({ cwd: root })로 실행합니다.
  • bun-plugin/__tests__/order-independent-build.helper.ts: 부모가 이미 cwd: fixture로 띄우고 있어서 chdir가 중복이었습니다. 삭제했습니다.
  • vite-plugin/__tests__/css-http-native.ts 및 css-http-representation.test.ts: 부모가 project 디렉터리를 만들고 spawnSync({ cwd: project })로 실행합니다.

남겨 둔 것

테스트가 별도 프로세스로 띄우는 .cjs/.mjs 헬퍼 10개에는 아직 process.chdir가 있습니다. 모두 자식 프로세스 안에서만 실행되므로 테스트 러너 프로세스의 상태에는 영향을 주지 않습니다. 필요하면 같은 방식(spawn할 때 cwd 지정)으로 후속 PR에서 정리할 수 있습니다.

  • bun-plugin: reservation-roots.cjs
  • next-plugin: availability-child.mjs, native-webpack-server.cjs
  • rsbuild-plugin: audit-native.cjs, entry-revisions.cjs, reservation-native.cjs, reservation-scenarios.cjs
  • vite-plugin: reservation-native-boundary.cjs, reservation-native-installed.cjs

겹치는 PR

  • fix(plugins): resolve relative options against the bundler project root #962 (bundler project root)와 #934는 둘 다 packages/next-plugin/src/__tests__/plugin.test.ts를 고칩니다. 이 PR은 그 파일에서 native Turbo prewarm 테스트 하나만 바꾸므로 충돌이 나도 범위가 작습니다. 이 PR은 플러그인 옵션 해석 소스를 건드리지 않습니다.
  • #934는 next-plugin/__tests__/atom-hoist.test.ts도 고칩니다. 이 PR은 그 테스트가 쓰는 atom-hoist-harness.ts만 고칩니다.

Test plan

  • bun test packages/next-plugin: 230 pass, 0 fail
  • bun test packages/bun-plugin: 59 pass, 0 fail
  • bun --config=./bunfig.vite.toml test (repo root): 876 pass, 3 fail
    • 실패한 3개는 reservation-native-boundary와 serve-coherence-prereq-native의 native 테스트이고, 이 PR이 건드리지 않은 파일입니다.
    • 이 PR의 vite 변경을 origin/main 상태로 되돌려도 똑같이 3개가 실패했습니다. 다른 worktree에서 복사한 native 바이너리 때문에 생긴 로컬 환경 문제로 보입니다.
    • 이 PR이 바꾼 css-http-representation.test.ts는 2/2 통과했습니다.
  • tsc --noEmit 통과: next-plugin, bun-plugin, vite-plugin (@typescript/native)
  • bunx prettier --single-quote --no-semi --check 통과 (변경한 파일 전부)
  • git diff --stat으로 줄바꿈 때문에 파일 전체가 바뀌지 않았는지 확인 (plugin.test.ts는 index에서 CRLF라서 core.autocrlf=false로 stage)
  • 커버리지: 소스 변경이 없고, 바꾼 테스트도 같은 소스 경로를 실행합니다. 전체 --coverage 실행은 CI에 맡겼습니다.

Refs #683

🤖 Generated with Claude Code

process.chdir in a test makes the result depend on which tests ran
before it and on the directory the runner started in. Every TypeScript
test now gives the fixture root explicitly instead:

- next-plugin deterministic-numbering: every path is already built from
  the fixture root, so the chdir was dead; drop it.
- next-plugin imported-styled: withModuleResolver names files relative
  to process.cwd(), so spy on process.cwd for the fixture instead of
  changing the directory of the whole test process.
- next-plugin plugin (native Turbo prewarm), next-plugin atom-hoist
  harness, bun-plugin order-independent build and vite-plugin CSS HTTP
  probe: spawn the child process with the fixture as its cwd and assert
  it, instead of calling chdir inside the child.

No source changes.

Refs #683

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
...es/next-plugin/src/__tests__/atom-hoist-harness.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@owjs3901
owjs3901 merged commit c6b8501 into main Nov 15, 2026
27 checks passed
@owjs3901
owjs3901 deleted the test/no-process-chdir branch November 15, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant