Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d80cb30
test: scaffold the Next.js suite package with core and cloudflare tar…
conico974 Oct 31, 2026
0738b86
test: add process management for suite deployments
conico974 Oct 31, 2026
e3ce3f2
test: implement the Next.js harness deploy, logs and cleanup hooks
conico974 Oct 31, 2026
98782b3
test: add per-adapter disable lists for the Next.js suite
conico974 Oct 31, 2026
36f1f17
test: add a local runner for the Next.js suite
conico974 Oct 31, 2026
d5fc145
test: run the Next.js suite on Cloudflare through wrangler dev
conico974 Oct 31, 2026
85a61ba
test: seed Next.js suite disable lists from JUnit reports
conico974 Oct 31, 2026
30be880
ci: run the Next.js adapter suite nightly and on demand
conico974 Oct 31, 2026
b1603bb
test: harden the Next.js suite hooks and CI after review
conico974 Oct 31, 2026
f2e0085
test: disable edge runtime tests in the Next.js suite
conico974 Nov 1, 2026
792af00
fix: define the global AsyncLocalStorage in the request handler
conico974 Nov 1, 2026
3b013ff
test: read JUnit reports with long failure messages
conico974 Nov 1, 2026
19af0b1
test: record the Next.js suite baseline for core and cloudflare
conico974 Nov 1, 2026
573b386
test: keep exact case names when seeding Next.js suite disable lists
conico974 Nov 1, 2026
64fe5df
test: only disable tests using the edge runtime
conico974 Nov 1, 2026
bdf7df8
fix: fail the request for a missing image with the fs-dev loader
conico974 Nov 1, 2026
7c7630a
fix: reject image paths which are not files with the fs-dev loader
conico974 Nov 1, 2026
7b19e83
fix: serve the pages router pages rendered to HTML at build time
conico974 Nov 1, 2026
45c9e98
test: reseed the Next.js suite baseline after the static page fix
conico974 Nov 2, 2026
575e0e2
fix: route static pages with the base path and locales of the build
conico974 Nov 2, 2026
7c42387
ci: run the Next.js test suite on pull requests changing the packages
conico974 Nov 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/core-fs-dev-missing-image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/core": patch
---

Fail the request for a missing image with the `fs-dev` image loader, it used to crash the server.
5 changes: 5 additions & 0 deletions .changeset/core-global-async-local-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/core": patch
---

Define the global `AsyncLocalStorage` in the request handler, the server crashed on its first render when the app has no middleware.
5 changes: 5 additions & 0 deletions .changeset/core-static-html-pages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/core": patch
---

Serve the pages router pages Next.js renders to HTML at build time, they returned a 404.
5 changes: 4 additions & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ inputs:
node-version:
description: Node.js version to install
default: "24"
pnpm-cache:
description: Restores and saves the pnpm store
default: "true"

runs:
using: composite
Expand All @@ -19,7 +22,7 @@ runs:
with:
node-version: ${{ inputs.node-version }}
registry-url: https://registry.npmjs.org
cache: pnpm
cache: ${{ inputs.pnpm-cache == 'true' && 'pnpm' || '' }}

# Enable node compile cache (effective for Node 22+)
# See https://nodejs.org/docs/v24.11.1/api/module.html#module-compile-cache
Expand Down
136 changes: 136 additions & 0 deletions .github/workflows/next-suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Next.js Test Suite

on:
schedule:
- cron: "0 3 * * *"
workflow_dispatch:
inputs:
nextRef:
description: Next.js ref (tag, branch or commit)
default: v16.2.1
type: string
# The adapters' runtime is in the packages, a change there can make a test of the suite fail.
pull_request:
paths:
- ".github/actions/setup/**"
- ".github/workflows/next-suite.yml"
- "packages/**"
- "pnpm-lock.yaml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

env:
NEXT_REF: ${{ inputs.nextRef || 'v16.2.1' }}
NEXT_DIR: packages/tests-next-suite/.cache/next.js

jobs:
# Checks out and builds Next.js once, the other jobs restore it from the cache.
next:
name: Build Next.js
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup

- name: Cache the Next.js checkout
id: next-cache
uses: actions/cache@v6
with:
path: |
packages/tests-next-suite/.cache/next.js
~/.cache/ms-playwright
key: next-suite-${{ runner.os }}-${{ inputs.nextRef || 'v16.2.1' }}

- name: Build Next.js
if: steps.next-cache.outputs.cache-hit != 'true'
run: pnpm next-suite setup --ref "$NEXT_REF"

suite:
name: Suite (${{ matrix.target }} ${{ matrix.group }}/16)
needs: next
runs-on: ubuntu-24.04
timeout-minutes: 180
strategy:
fail-fast: false
matrix:
target: [core, cloudflare]
group: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
steps:
- uses: actions/checkout@v7
# These jobs run unlocked packages from npm, they must not save to a cache release jobs restore.
- uses: ./.github/actions/setup
with:
pnpm-cache: "false"

- name: Restore the Next.js checkout
uses: actions/cache/restore@v6
with:
path: |
packages/tests-next-suite/.cache/next.js
~/.cache/ms-playwright
key: next-suite-${{ runner.os }}-${{ inputs.nextRef || 'v16.2.1' }}
fail-on-cache-miss: true

- name: Install the browser dependencies
working-directory: ${{ env.NEXT_DIR }}
run: pnpm playwright install --with-deps chromium

- name: Run the tests
run: pnpm next-suite run --target ${{ matrix.target }} --ref "$NEXT_REF" --group ${{ matrix.group }}/16 -c 2 --retries 1

- name: Upload the reports
if: always()
uses: actions/upload-artifact@v7
with:
name: junit-${{ matrix.target }}-${{ matrix.group }}
path: |
${{ env.NEXT_DIR }}/test/turbopack-test-junit-report
${{ env.NEXT_DIR }}/test/test-junit-report
include-hidden-files: true
if-no-files-found: ignore
retention-days: 14

# Lists what failed, as disable lists which can replace the ones in `packages/tests-next-suite/disabled`.
report:
name: Report
needs: suite
if: always() && needs.suite.result != 'skipped'
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup

- name: Download the reports
uses: actions/download-artifact@v8
with:
pattern: junit-*
path: reports

- name: Summarize the failures
run: |
mkdir -p candidates
for target in core cloudflare; do
mkdir -p "reports-$target"
for dir in reports/junit-"$target"-*; do
if [ -d "$dir" ]; then cp -r "$dir" "reports-$target/"; fi
done
pnpm --silent next-suite disabled-from-junit \
--target "$target" \
--input "reports-$target" \
--output "candidates/$target.json" \
--reason "Failing in CI run $GITHUB_RUN_ID" >> "$GITHUB_STEP_SUMMARY"
done

- name: Upload the candidate disable lists
uses: actions/upload-artifact@v7
with:
name: next-suite-disabled
path: candidates
retention-days: 14
14 changes: 14 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ pnpm --filter tests-unit vitest
pnpm --filter @opennextjs/cloudflare test
```

### Next.js test suite

Runs the Next.js e2e suite against the `core` and `cloudflare` adapters. See `packages/tests-next-suite/README.md`.

```bash
# Check out and build Next.js, once
pnpm next-suite setup

# Run a test file on an adapter
pnpm next-suite run --target cloudflare -c 1 test/e2e/app-dir/hello-world/hello-world.test.ts
```

Tests are disabled per adapter in `packages/tests-next-suite/disabled/<target>.json`.

### Package-specific commands

```bash
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"e2e:dev": "pnpm build && pnpm -r e2e:dev",
"install-playwright": "playwright install --with-deps",
"benchmark": "pnpm run --filter benchmarking benchmark",
"next-suite": "pnpm --filter tests-next-suite next-suite",
"postinstall": "pnpm build:opennext"
},
"devDependencies": {
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/build/createRoutingConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { RuntimeRoutingConfig } from "../types/adapter.js";
import type { BuildCompleteContext } from "./adapter.js";
import type * as buildHelper from "./helper.js";
import { normalizeRouting } from "./normalizeRouting.js";
import { getStaticPages } from "./staticPages.js";

const EXECUTABLE_OUTPUT_TYPES = ["pages", "pagesApi", "appPages", "appRoutes"] as const;
const PATHNAME_OUTPUT_TYPES = [...EXECUTABLE_OUTPUT_TYPES, "staticFiles"] as const;
Expand Down Expand Up @@ -142,6 +143,13 @@ export function createRoutingConfig(
// The set has to be snapshotted before the prerendered pathnames are indexed - they are servable
// but not executable, and may never be the resolution target of another prerendered pathname.
const executableRoutes = new Set(Object.keys(routeIndex));
const staticPageRoutes = getStaticPages(context.outputs, {
basePath: context.config.basePath,
locales: context.config.i18n?.locales,
}).map(({ route }) => route);
for (const route of staticPageRoutes) {
routeIndex[route] = { type: "static", isFallback: false, isISR: false };
}
const resolvePrerenderRoute = createPrerenderRouteResolver(context, executableRoutes);
const prerenderPathnames: string[] = [];

Expand All @@ -162,7 +170,7 @@ export function createRoutingConfig(
const outputPathnames = PATHNAME_OUTPUT_TYPES.flatMap((outputType) =>
(context.outputs[outputType] ?? []).map((output) => output.pathname)
);
const servablePathnames = [...outputPathnames, ...prerenderPathnames];
const servablePathnames = [...outputPathnames, ...prerenderPathnames, ...staticPageRoutes];
const pathnames = [
...new Set(
context.config.trailingSlash ? withTrailingSlashVariants(servablePathnames) : servablePathnames
Expand Down
54 changes: 54 additions & 0 deletions packages/core/src/build/staticPages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { NextAdapterOutputs } from "../types/adapter.js";

export type StaticPage = {
/** The pathname the page is served on. */
route: string;
filePath: string;
};

export type StaticPageOptions = {
basePath?: string;
locales?: string[];
};

const ERROR_PAGES = new Set(["/404", "/500"]);

/** Inverse of the `normalizePagePath` of Next.js, which prefixes `/index` to the pages starting with it. */
function denormalizePagePath(page: string): string {
if (page === "/index") {
return "/";
}
return page.startsWith("/index/") ? page.slice("/index".length) : page;
}

/**
* Lists the pages Next.js fully rendered to HTML at build time, i.e. pages without data fetching.
*
* Next.js reports them as static files with no route to reach them. Their pathname holds the base path,
* the locale and the page path as Next.js normalizes it, `/index` for the index page. The html files of
* the public directory are static files too, those are assets whose pathname is their file name.
*
* @param outputs The outputs of the build.
* @param options The base path and the locales of the build.
* @returns The pages, with the pathname they are served on.
*/
export function getStaticPages(
outputs: Pick<NextAdapterOutputs, "staticFiles">,
{ basePath = "", locales = [] }: StaticPageOptions = {}
): StaticPage[] {
return (outputs.staticFiles ?? []).flatMap(({ pathname, filePath }) => {
if (!filePath.endsWith(".html") || pathname.endsWith(".html")) {
return [];
}
let page = basePath && pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
const segment = page.split("/")[1] ?? "";
const locale = locales.includes(segment) ? `/${segment}` : "";
page = page.slice(locale.length) || "/";
// The error pages are rendered by the server with their status code, they are not routes.
if (ERROR_PAGES.has(page)) {
return [];
}
const route = denormalizePagePath(page);
return [{ route: `${basePath}${locale}${route === "/" ? "" : route}` || "/", filePath }];
});
}
4 changes: 4 additions & 0 deletions packages/core/src/core/requestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import routingHandler, {
MIDDLEWARE_HEADER_PREFIX_LEN,
} from "./routingHandler";

// Next.js sets this when `next-server` is loaded, which the adapter bundle does not do. Without it, the
// runtime of the routes throws when it gets loaded, when nothing else (like node middleware) has set it.
globalThis.AsyncLocalStorage ??= AsyncLocalStorage;

// This is used to identify requests in the cache
globalThis.__openNextAls = new AsyncLocalStorage();

Expand Down
25 changes: 25 additions & 0 deletions packages/core/src/core/routing/adapterHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@ export async function adapterHandler(
}
}

/**
* Creates the handler of a page Next.js rendered to HTML at build time.
*
* @param html The content of the page.
* @returns The handler, it answers like the Next.js server does.
*/
export function createStaticPageHandler(html: string) {
return {
handler: async (req: IncomingMessage, res: OpenNextNodeResponse) => {
const isHead = req.method === "HEAD";
if (req.method !== "GET" && !isHead) {
res.statusCode = 405;
res.setHeader("allow", "GET, HEAD");
res.end("Method Not Allowed");
} else {
// A rewrite can have set the status code, it applies to the page.
res.statusCode ||= 200;
res.setHeader("content-type", "text/html; charset=utf-8");
res.end(isHead ? undefined : html);
}
await finished(res);
},
};
}

async function handle404(req: IncomingMessage, res: OpenNextNodeResponse, waitUntil?: WaitUntil) {
try {
// TODO: find the correct one to use.
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/overrides/imageLoader/fs-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default {
load: async (url: string) => {
const urlWithoutBasePath = NextConfig.basePath ? url.slice(NextConfig.basePath.length) : url;
const imagePath = path.join(getMonorepoRelativePath(), "assets", urlWithoutBasePath);
// A stream emits this as an `error` event nothing listens to, which would kill the server.
const stats = await fs.promises.stat(imagePath);
if (!stats.isFile()) {
throw new Error(`The image is not a file: ${imagePath}`);
}
const body = fs.createReadStream(imagePath);
const contentType = url.endsWith(".png") ? "image/png" : "image/jpeg";
return {
Expand Down
Loading
Loading