Skip to content

test(rsbuild-plugin): drive the plugin through its real hook sequence - #957

Merged
owjs3901 merged 2 commits into
mainfrom
test/plugin-hook-behavior
Nov 17, 2026
Merged

owjs3901 merged 2 commits into
mainfrom
test/plugin-hook-behavior

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PLG-26: the existing plugin tests mocked every file write as "already done", so they could not catch problems related to bundler hook call order or the actual file system state. This is the first slice addressing that, starting with the Rsbuild plugin.

Added packages/rsbuild-plugin/src/__tests__/hooks.test.ts. It uses a fake Rsbuild API and a fake Rspack compiler/compilation, and drives the hooks in the order Rsbuild calls them, on top of the real compiler (WASM) and a temporary-directory file system.

  • Hook registration order: onCloseBuild → modifyRspackConfig → onBeforeBuild → transform(cssDir) → modifyRspackConfig → modifyRsbuildConfig → transform(source). With extractCss: false, only onCloseBuild is registered.
  • Cold directory: checks that devup-ui.css is created even in a nested cssDir that does not exist (mkdir deliberately delayed by 20ms).
  • A style changed to the same length (red → tan): checks that the new class's rule is served and also written to the file, and that the file content matches the served content.
  • Multiple environments: only the environment whose served sheet changed (web) requests an additional pass (deletes main.js, sets modifiedFiles), and the other environment (node) does not. It does not request again in the same run.

Bug fix (PLG-10)

The cold directory test failed with ENOENT on main, because writeDataFiles started mkdir and the first writeFile concurrently with Promise.all. It now writes after mkdir finishes. Since shipped code changed, a @devup-ui/rsbuild-plugin Patch changepack was added.

Out of scope here

Test plan

  • bun test packages/rsbuild-plugin/src/__tests__/hooks.test.ts (5 pass); confirmed the cold directory test fails with ENOENT against main's plugin.ts
  • bun test --coverage packages/rsbuild-plugin (603 pass, plugin.ts·reservation.ts 100%)
  • tsc (included in the package build)
  • prettier
  • CI publish job passes

요약

PLG-26: 기존 플러그인 테스트가 파일 쓰기를 모두 "이미 끝난 것"으로 mock해서, bundler hook의 호출 순서나 실제 파일 시스템 상태와 관련된 문제를 잡지 못하던 부분에 대한 첫 번째 slice입니다. 먼저 Rsbuild 플러그인부터 다룹니다.

packages/rsbuild-plugin/src/__tests__/hooks.test.ts를 추가했습니다. fake Rsbuild API와 fake Rspack compiler/compilation을 쓰고, 실제 compiler(WASM)와 임시 디렉터리 파일 시스템 위에서 Rsbuild가 부르는 순서대로 hook을 구동합니다.

  • hook 등록 순서: onCloseBuild → modifyRspackConfig → onBeforeBuild → transform(cssDir) → modifyRspackConfig → modifyRsbuildConfig → transform(source). extractCss: false일 때는 onCloseBuild만 등록됩니다.
  • cold directory: 존재하지 않는 중첩 cssDir(mkdir을 일부러 20ms 늦춤)에서도 devup-ui.css가 만들어지는지 확인합니다.
  • 같은 길이로 바뀐 스타일(red → tan): 새 class의 규칙이 서빙되고 파일에도 쓰이는지, 파일 내용과 서빙 내용이 같은지 확인합니다.
  • 여러 environment: 서빙한 sheet가 바뀐 environment(web)만 additional pass를 요청하고(main.js 삭제, modifiedFiles 설정), 다른 environment(node)는 요청하지 않습니다. 같은 run에서는 다시 요청하지 않습니다.

버그 수정 (PLG-10)

cold directory 테스트가 main에서 ENOENT로 실패했습니다. writeDataFiles가 mkdir과 첫 writeFile을 Promise.all로 동시에 시작했기 때문입니다. 이제 mkdir이 끝난 뒤에 씁니다. 배포 코드가 바뀌어서 @devup-ui/rsbuild-plugin Patch changepack을 추가했습니다.

이번 범위에서 제외

테스트 계획

  • bun test packages/rsbuild-plugin/src/__tests__/hooks.test.ts (5 pass), main의 plugin.ts에서는 cold directory 테스트가 ENOENT로 실패하는 것 확인
  • bun test --coverage packages/rsbuild-plugin (603 pass, plugin.ts·reservation.ts 100%)
  • tsc (패키지 build에 포함)
  • prettier
  • CI publish job 통과

Refs #683

🤖 Generated with Claude Code

The existing suite mocks every file write as already done, which hides
ordering. The new suite runs setup against a fake Rsbuild API and fake
Rspack compilers with the real compiler and a temporary file system:

- the hooks are registered in the order a build runs them, and only the
  build end when CSS is not extracted
- a cold, nested cssDir exists before devup-ui.css is written into it
- a same-length edit (red to tan) is served and written
- with two environments, only the one whose served sheet went stale asks
  for one additional pass, and only once per run

The cold directory case failed with ENOENT: mkdir and the first write
ran side by side in Promise.all. writeDataFiles now awaits mkdir before
it writes.

Refs #683 (PLG-26)

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.
see 10 files with indirect coverage changes

🚀 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.

Conflicts:
- rsbuild-plugin/src/plugin.ts: #916 already made writeDataFiles create
  cssDir before writing devup-ui.css (PLG-10), the same fix as this
  branch. Kept main's version; the branch no longer changes plugin.ts.
- Dropped .changepacks/changepack_log_rsbuild_cold_css_dir.json: the
  fix it announces shipped in #916, whose changepack covers it, so this
  branch now only adds hooks.test.ts.

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

Copy link
Copy Markdown
Contributor Author

main을 머지하면서 \packages/rsbuild-plugin/src/plugin.ts\ 충돌을 해결했습니다. 이 PR의 PLG-10 수정(\cssDir\를 만든 뒤 \devup-ui.css\를 쓰기)은 #916에 같은 내용으로 이미 들어가 있어서 main 쪽 코드를 그대로 두었습니다. 같은 수정을 알리는 .changepacks/changepack_log_rsbuild_cold_css_dir.json\도 #916의 changepack과 겹쳐서 지웠습니다. 이제 이 PR은 \hooks.test.ts\만 추가합니다. cold directory 테스트를 포함해 \�un test --coverage packages/rsbuild-plugin\는 606 pass이고 \plugin.ts\·
eservation.ts\ 커버리지는 100%입니다. (13b2ab7)

@owjs3901
owjs3901 merged commit c8291de into main Nov 17, 2026
52 of 53 checks passed
@owjs3901
owjs3901 deleted the test/plugin-hook-behavior branch November 17, 2026 05:57
owjs3901 added a commit that referenced this pull request Nov 17, 2026
…rent merges (#990)

* test(rsbuild-plugin): expect the MDX post transform in the hook order

#957 recorded the hook order before #960 added an order: post transform
for .mdx modules. Both landed, so main registers two source transforms and
the test failed. Label the MDX transform and expect it last.

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

* test(wasm): count removeFile in the documented argument positions

#952 counted 45 validated argument positions; #951, merged alongside it,
added removeFile.filename, so main validates 46 and the ABI gate failed.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Keep #947's ThemeProvider limitation next to this branch's Bun line, which
now also names the packages in include. Rsbuild transforms take both #928's
addMissingDependency and this branch's environment, so the merged tests pass
both, including #957's hook tests that predate addMissingDependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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