Repository navigation
test(plugins): stop changing the process directory in tests - #971
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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에서 정리할 수 있습니다.reservation-roots.cjsavailability-child.mjs,native-webpack-server.cjsaudit-native.cjs,entry-revisions.cjs,reservation-native.cjs,reservation-scenarios.cjsreservation-native-boundary.cjs,reservation-native-installed.cjs겹치는 PR
packages/next-plugin/src/__tests__/plugin.test.ts를 고칩니다. 이 PR은 그 파일에서 native Turbo prewarm 테스트 하나만 바꾸므로 충돌이 나도 범위가 작습니다. 이 PR은 플러그인 옵션 해석 소스를 건드리지 않습니다.next-plugin/__tests__/atom-hoist.test.ts도 고칩니다. 이 PR은 그 테스트가 쓰는atom-hoist-harness.ts만 고칩니다.Test plan
bun test packages/next-plugin: 230 pass, 0 failbun test packages/bun-plugin: 59 pass, 0 failbun --config=./bunfig.vite.toml test(repo root): 876 pass, 3 failreservation-native-boundary와serve-coherence-prereq-native의 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