Repository navigation
feat: add bun-test-env-dom/next, stand-ins for every next/* module - #14
Merged
Merged
Conversation
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>
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.
요약
bun-test-env-dom/nextpreload entry를 추가합니다. Next.js의 공개next/*모듈을 모두 stand-in으로 바꾸고, 테스트에서 URL·params·headers·cookies를 설정하고 navigation을 검증할 수 있는 제어 함수를 제공합니다. 기본 entry는 그대로이며, 필요한 프로젝트만 opt-in으로 preload합니다.앱 코드는 계속
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로 생성합니다.router.push등은 호출만 기록하고 URL 변경이나 리렌더는 하지 않습니다.next/link클릭과 string actionnext/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합니다.Request/Response는cookie/set-cookie헤더를 버리지만,NextRequest/NextResponse는 이 헤더를 유지합니다.beforeEach)에 모든 상태와 mock을 리셋합니다.react >=18을 peer dependency로 추가했습니다.검증
bun lint,bun test(163 pass, line/function coverage 100%),bun run builddist/next.cjs와dist/next.mjs를 preload해next/link,next/navigation이 stand-in으로 해결되는지 확인했습니다.skipLibCheck: false로dist/next/index.d.ts를 확인했습니다.릴리즈
changepack Minor로 1.1.0을 배포합니다.