Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
203 lines
5.7 KiB
TypeScript
203 lines
5.7 KiB
TypeScript
import glob from 'glob'
|
|
import fs from 'fs-extra'
|
|
import { join } from 'path'
|
|
import cheerio from 'cheerio'
|
|
import { createNext, FileRef } from 'e2e-utils'
|
|
import { NextInstance } from 'e2e-utils'
|
|
import {
|
|
killApp,
|
|
findPort,
|
|
renderViaHTTP,
|
|
initNextServerScript,
|
|
fetchViaHTTP,
|
|
} from 'next-test-utils'
|
|
|
|
describe('minimal-mode-response-cache', () => {
|
|
let next: NextInstance
|
|
let server
|
|
let port
|
|
let appPort
|
|
let output = ''
|
|
|
|
beforeAll(async () => {
|
|
// test build against environment with next support
|
|
process.env.NOW_BUILDER = '1'
|
|
process.env.NEXT_PRIVATE_TEST_HEADERS = '1'
|
|
|
|
next = await createNext({
|
|
files: new FileRef(join(__dirname, 'app')),
|
|
})
|
|
await next.stop()
|
|
|
|
await fs.move(
|
|
join(next.testDir, '.next/standalone'),
|
|
join(next.testDir, 'standalone')
|
|
)
|
|
for (const file of await fs.readdir(next.testDir)) {
|
|
if (file !== 'standalone') {
|
|
await fs.remove(join(next.testDir, file))
|
|
console.log('removed', file)
|
|
}
|
|
}
|
|
const files = glob.sync('**/*', {
|
|
cwd: join(next.testDir, 'standalone/.next/server'),
|
|
nodir: true,
|
|
dot: true,
|
|
})
|
|
|
|
for (const file of files) {
|
|
if (file.match(/(pages|app)[/\\]/) && !file.endsWith('.js')) {
|
|
await fs.remove(join(next.testDir, 'standalone/.next/server', file))
|
|
console.log(
|
|
'removing',
|
|
join(next.testDir, 'standalone/.next/server', file)
|
|
)
|
|
}
|
|
}
|
|
|
|
const testServer = join(next.testDir, 'standalone/server.js')
|
|
await fs.writeFile(
|
|
testServer,
|
|
(await fs.readFile(testServer, 'utf8'))
|
|
.replace('console.error(err)', `console.error('top-level', err)`)
|
|
.replace('port:', 'minimalMode: true,port:')
|
|
)
|
|
port = await findPort()
|
|
server = await initNextServerScript(
|
|
testServer,
|
|
/- Local:/,
|
|
{
|
|
...process.env,
|
|
...next.env,
|
|
HOSTNAME: '',
|
|
PORT: port.toString(),
|
|
},
|
|
undefined,
|
|
{
|
|
cwd: next.testDir,
|
|
onStdout(msg) {
|
|
output += msg
|
|
},
|
|
onStderr(msg) {
|
|
output += msg
|
|
},
|
|
}
|
|
)
|
|
appPort = `http://127.0.0.1:${port}`
|
|
})
|
|
afterAll(async () => {
|
|
delete process.env.NOW_BUILDER
|
|
delete process.env.NEXT_PRIVATE_TEST_HEADERS
|
|
await next.destroy()
|
|
if (server) await killApp(server)
|
|
})
|
|
|
|
it('app router revalidate should work with previous response cache dynamic', async () => {
|
|
const headers = {
|
|
vary: 'rsc, next-router-state-tree, next-router-prefetch',
|
|
'x-now-route-matches': '1=compare&rsc=1',
|
|
'x-matched-path': '/app-blog/compare.rsc',
|
|
'x-invocation-id': '1',
|
|
rsc: '1',
|
|
}
|
|
const res1 = await fetchViaHTTP(
|
|
appPort,
|
|
'/app-blog/compare.rsc',
|
|
undefined,
|
|
{
|
|
headers,
|
|
}
|
|
)
|
|
const content1 = await res1.text()
|
|
expect(content1).not.toContain('<html')
|
|
expect(content1).toContain('app-blog')
|
|
expect(res1.headers.get('content-type')).toContain('text/x-component')
|
|
|
|
const res2 = await fetchViaHTTP(appPort, '/app-blog/compare', undefined, {
|
|
headers,
|
|
})
|
|
const content2 = await res2.text()
|
|
expect(content2).toContain('<html')
|
|
expect(content2).toContain('app-blog')
|
|
expect(res2.headers.get('content-type')).toContain('text/html')
|
|
})
|
|
|
|
it('app router revalidate should work with previous response cache', async () => {
|
|
const headers = {
|
|
vary: 'rsc, next-router-state-tree, next-router-prefetch',
|
|
'x-now-route-matches': '1=app-another&rsc=1',
|
|
'x-matched-path': '/app-another.rsc',
|
|
'x-invocation-id': '1',
|
|
rsc: '1',
|
|
}
|
|
const res1 = await fetchViaHTTP(appPort, '/app-another.rsc', undefined, {
|
|
headers,
|
|
})
|
|
const content1 = await res1.text()
|
|
expect(res1.headers.get('content-type')).toContain('text/x-component')
|
|
expect(content1).not.toContain('<html')
|
|
expect(content1).toContain('app-another')
|
|
|
|
const res2 = await fetchViaHTTP(appPort, '/app-another', undefined, {
|
|
headers,
|
|
})
|
|
const content2 = await res2.text()
|
|
expect(res2.headers.get('content-type')).toContain('text/html')
|
|
expect(content2).toContain('<html')
|
|
expect(content2).toContain('app-another')
|
|
})
|
|
|
|
it('should have correct "Started server on" log', async () => {
|
|
expect(output).toContain(`- Local:`)
|
|
expect(output).toContain(`http://localhost:${port}`)
|
|
})
|
|
|
|
it('should have correct responses', async () => {
|
|
const html = await renderViaHTTP(appPort, '/')
|
|
expect(html.length).toBeTruthy()
|
|
|
|
for (const { path, matchedPath, query, asPath, pathname } of [
|
|
{ path: '/', asPath: '/' },
|
|
{ path: '/', matchedPath: '/index', asPath: '/' },
|
|
{ path: '/', matchedPath: '/index/', asPath: '/' },
|
|
{ path: '/', matchedPath: '/', asPath: '/' },
|
|
{
|
|
path: '/news/',
|
|
matchedPath: '/news/',
|
|
asPath: '/news/',
|
|
pathname: '/news',
|
|
},
|
|
{
|
|
path: '/news/',
|
|
matchedPath: '/news',
|
|
asPath: '/news/',
|
|
pathname: '/news',
|
|
},
|
|
{
|
|
path: '/blog/first/',
|
|
matchedPath: '/blog/first/',
|
|
pathname: '/blog/[slug]',
|
|
asPath: '/blog/first/',
|
|
query: { slug: 'first' },
|
|
},
|
|
{
|
|
path: '/blog/second/',
|
|
matchedPath: '/blog/[slug]/',
|
|
pathname: '/blog/[slug]',
|
|
asPath: '/blog/second/',
|
|
query: { slug: 'second' },
|
|
},
|
|
]) {
|
|
const html = await renderViaHTTP(appPort, path, undefined, {
|
|
headers: {
|
|
'x-matched-path': matchedPath || path,
|
|
},
|
|
})
|
|
const $ = cheerio.load(html)
|
|
expect($('#asPath').text()).toBe(asPath)
|
|
expect($('#pathname').text()).toBe(pathname || path)
|
|
expect(JSON.parse($('#query').text())).toEqual(query || {})
|
|
}
|
|
})
|
|
})
|