Commit 71029bd8 authored by Jimmy Lai's avatar Jimmy Lai Committed by Tim Neutkens

ci: add node-stream test coverage workflow

Adds a CI job that re-runs the app-dir e2e suite with
__NEXT_USE_NODE_STREAMS=true to verify the node stream path.

Includes a test manifest that selects the relevant test globs.
parent 33a702e1
...@@ -703,7 +703,6 @@ jobs: ...@@ -703,7 +703,6 @@ jobs:
uses: ./.github/workflows/build_reusable.yml uses: ./.github/workflows/build_reusable.yml
with: with:
# Keep Next.js related env variables in sync with additionalEnv in next-deploy.ts
afterBuild: | afterBuild: |
export __NEXT_CACHE_COMPONENTS=true export __NEXT_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=true export __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=true
...@@ -1010,6 +1009,63 @@ jobs: ...@@ -1010,6 +1009,63 @@ jobs:
stepName: 'test-cache-components-prod-${{ matrix.group }}' stepName: 'test-cache-components-prod-${{ matrix.group }}'
secrets: inherit secrets: inherit
test-node-streams-dev:
name: test node streams dev
needs: ['optimize-ci', 'changes', 'build-native', 'build-next']
if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
strategy:
fail-fast: false
matrix:
group: [1/6, 2/6, 3/6, 4/6, 5/6, 6/6]
uses: ./.github/workflows/build_reusable.yml
with:
# Dev tests use Turbopack (default bundler) to cover turbopack code paths.
# Prod tests below use IS_WEBPACK_TEST=1 to cover webpack code paths.
afterBuild: |
export __NEXT_USE_NODE_STREAMS=true
export __NEXT_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/cache-components-tests-manifest.json,test/use-node-streams-tests-manifest.json"
export NEXT_TEST_MODE=dev
export IS_TURBOPACK_TEST=1
export TURBOPACK_DEV=1
node run-tests.js \
--timings \
-g ${{ matrix.group }} \
--type development
stepName: 'test-node-streams-dev-${{ matrix.group }}'
secrets: inherit
test-node-streams-prod:
name: test node streams prod
needs: ['optimize-ci', 'changes', 'build-native', 'build-next']
if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
strategy:
fail-fast: false
matrix:
group: [1/7, 2/7, 3/7, 4/7, 5/7, 6/7, 7/7]
uses: ./.github/workflows/build_reusable.yml
with:
# Prod tests use webpack (IS_WEBPACK_TEST=1) to cover webpack code paths.
# Dev tests above use Turbopack (default) to cover turbopack code paths.
afterBuild: |
export __NEXT_USE_NODE_STREAMS=true
export __NEXT_CACHE_COMPONENTS=true
export __NEXT_EXPERIMENTAL_DEBUG_CHANNEL=true
export NEXT_EXTERNAL_TESTS_FILTERS="test/cache-components-tests-manifest.json,test/use-node-streams-tests-manifest.json"
export NEXT_TEST_MODE=start
export IS_WEBPACK_TEST=1
node run-tests.js \
--timings \
-g ${{ matrix.group }} \
--type production
stepName: 'test-node-streams-prod-${{ matrix.group }}'
secrets: inherit
tests-pass: tests-pass:
needs: needs:
[ [
...@@ -1028,6 +1084,8 @@ jobs: ...@@ -1028,6 +1084,8 @@ jobs:
'test-cache-components-dev', 'test-cache-components-dev',
'test-cache-components-prod', 'test-cache-components-prod',
'test-cache-components-integration', 'test-cache-components-integration',
'test-node-streams-dev',
'test-node-streams-prod',
'test-cargo-unit', 'test-cargo-unit',
'rust-check', 'rust-check',
'rustdoc-check', 'rustdoc-check',
......
...@@ -3,7 +3,9 @@ let cacheExports ...@@ -3,7 +3,9 @@ let cacheExports
if (process.env.NEXT_RUNTIME === '') { if (process.env.NEXT_RUNTIME === '') {
const notAvailableInClient = (name) => { const notAvailableInClient = (name) => {
return function notAvailable() { return function notAvailable() {
throw new Error(`\`${name}\` is only available in a Server Component.`) throw new Error(
`\`${name}\` from 'next/cache' cannot be used in Client Components. It is only available on the server.`
)
} }
} }
......
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
'use client'
// unstable_cache is allowed in client components (has a client-side fallback).
// Without the DCE guard in cache.js, the bundler would trace into the
// server-side implementation and pull in workAsyncStorage, IncrementalCache, etc.
import { unstable_cache } from 'next/cache'
console.log(typeof unstable_cache)
export default function Page() {
return <p>hello world</p>
}
import { nextTestSetup } from 'e2e-utils'
describe('cache-dce-guard', () => {
const { next, isNextDev, isTurbopack, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
skipStart: true,
})
if (isNextDev || skipped || isTurbopack) {
it.skip('only testable in webpack production (non-deployment)', () => {})
return
}
it('should keep server-only cache modules out of browser chunks', async () => {
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
// Read all sourcemaps from browser chunks and extract their source paths.
const sourcemaps = await next.readFiles('.next/static/chunks', (filename) =>
filename.endsWith('.js.map')
)
const sources = sourcemaps.flatMap(
(sourcemap) => JSON.parse(sourcemap).sources as string[]
)
// These server-only modules must NOT appear in any browser chunk.
const serverLeaks = sources.filter(
(source) =>
source.includes('spec-extension/unstable-cache') ||
source.includes('work-async-storage') ||
source.includes('incremental-cache') ||
source.includes('use-cache/cache-life') ||
source.includes('use-cache/cache-tag') ||
source.includes('spec-extension/revalidate')
)
if (serverLeaks.length > 0) {
throw new Error(
`Server-only cache modules leaked into browser chunks:\n ${serverLeaks.join('\n ')}\n` +
'The cache.js DCE guard may be broken.'
)
}
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
productionBrowserSourceMaps: true,
}
module.exports = nextConfig
{
"version": 2,
"suites": {},
"rules": {
"include": [
"test/e2e/**/*.test.{t,j}s{,x}",
"test/integration/app-*/**/*.test.{t,j}s{,x}",
"test/production/app-*/**/*.test.{t,j}s{,x}",
"test/development/app-*/**/*.test.{t,j}s{,x}",
"test/development/acceptance-app/**/*.test.{t,j}s{,x}"
],
"exclude": []
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment