Skip to content

feat: add bun-test-env-dom/next, stand-ins for every next/* module - #14

Merged
owjs3901 merged 4 commits into
mainfrom
owjs3901/next-entry
Sep 23, 2026
Merged

owjs3901 merged 4 commits into
mainfrom
owjs3901/next-entry

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

요약

bun-test-env-dom/next preload entry를 추가합니다. Next.js의 공개 next/* 모듈을 모두 stand-in으로 바꾸고, 테스트에서 URL·params·headers·cookies를 설정하고 navigation을 검증할 수 있는 제어 함수를 제공합니다. 기본 entry는 그대로이며, 필요한 프로젝트만 opt-in으로 preload합니다.

[test]
preload = ["bun-test-env-dom", "bun-test-env-dom/next"]
import { router, setParams, setUrl } from 'bun-test-env-dom/next'

앱 코드는 계속 next/*를 import하므로, Next.js 런타임(vinext 등)이 바뀌어도 테스트는 그대로 동작합니다. Next.js가 설치되어 있지 않아도 next/* import가 해결됩니다.

동작

  • 대상 모듈: next/navigation, link, image, legacy/image, script, head, dynamic, form, headers, cache, server, og, font/google, font/local, router, compat/router, document, app, error, offline, web-vitals, root-params. export 이름은 next@16.3.6 런타임과 같습니다. named import는 이름이 있어야 link되므로 Proxy를 쓰지 않았습니다. font/google의 1942개 폰트는 scripts/generate-google-fonts.ts로 생성합니다.
  • navigation: router.push 등은 호출만 기록하고 URL 변경이나 리렌더는 하지 않습니다. next/link 클릭과 string action next/form 제출은 Next.js가 client-side로 이동하는 경우에만 router.push/replace를 호출합니다. modifier 키, 다른 target, download, 다른 origin은 브라우저에 맡깁니다.
  • 마크업: next/link, next/image(unoptimized), next/form, next/error는 Next.js 16과 같은 마크업을 렌더합니다. util-support에서 실제 next@16.3.6 컴포넌트와 27개 케이스를 innerHTML로 비교해 모두 일치했습니다.
  • 에러: redirect, notFound, forbidden, unauthorized는 Next.js와 같은 digest로 throw합니다.
  • server: happy-dom의 Request/Response는 cookie/set-cookie 헤더를 버리지만, NextRequest/NextResponse는 이 헤더를 유지합니다.
  • 리셋: 매 테스트 전(beforeEach)에 모든 상태와 mock을 리셋합니다.
  • react: react >=18을 peer dependency로 추가했습니다.

검증

  • bun lint, bun test(163 pass, line/function coverage 100%), bun run build
  • dist fixture: Next.js가 없는 임시 디렉터리에서 빌드된 dist/next.cjs와 dist/next.mjs를 preload해 next/link, next/navigation이 stand-in으로 해결되는지 확인했습니다.
  • 소비자 관점 타입 체크: skipLibCheck: false로 dist/next/index.d.ts를 확인했습니다.

릴리즈

changepack Minor로 1.1.0을 배포합니다.

owjs3901 and others added 4 commits September 23, 2026 21:33
Page tests should not depend on Next's runtime: its router, server and
compiler. Each stand-in keeps the runtime exports of next@16.3.6 - a named
import only links when the name is listed, so none of them is a Proxy - and
reads the URL, params, headers and cookies a test sets.

- next/link, next/form: a client-side navigation calls router.push or
  replace, with Next's rules for what is left to the browser.
- next/link, next/image (unoptimized), next/form and next/error render the
  markup of Next.js 16, checked against next@16.3.6 in happy-dom.
- redirect, notFound, forbidden and unauthorized throw the digests of Next.
- next/server keeps the cookie and set-cookie headers that happy-dom's
  Request and Response drop.
- next/font/google lists its 1942 fonts, generated by
  scripts/generate-google-fonts.ts from the declarations of Next.js.

State lives on globalThis, so a built and a source copy loaded together
read and reset the same values.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
The suite preloads src/next/index.ts after the DOM, as a consumer would,
and keeps coverage at 100%. The tests check each module's export names
against next@16.3.6, the markup of next/link, next/image and next/form,
which clicks and submits reach the router, the error digests, catchError,
the Pages Router, next/headers, next/cache and next/server, and that every
test starts from a reset state.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
The package exports ./next next to the DOM entry: a CJS bundle, and an ESM
entry that re-exports it, so a preload and a test that import the entry
share one copy. react becomes a peer dependency, since the stand-ins render
with it.

The dist preload test now also runs the built next entries from a directory
without Next.js, where next/link and next/navigation have to resolve to the
stand-ins alone.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
@owjs3901
owjs3901 merged commit 03fe3e8 into main Sep 23, 2026
1 check passed
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