From c2839257d8905606dc25646b765a6c1869a83eb9 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 29 Mar 2022 17:08:42 +0200 Subject: [PATCH] add test for non-custom-app treeview --- .../test/basic.js | 7 + .../test/index.test.js | 167 ++++++++---------- .../test/rsc.js | 1 - 3 files changed, 81 insertions(+), 94 deletions(-) diff --git a/test/integration/react-streaming-and-server-components/test/basic.js b/test/integration/react-streaming-and-server-components/test/basic.js index 5c5aec7ba8209..ec7952b230b0e 100644 --- a/test/integration/react-streaming-and-server-components/test/basic.js +++ b/test/integration/react-streaming-and-server-components/test/basic.js @@ -65,4 +65,11 @@ export default async function basic(context, { env }) { expect(content).toMatchInlineSnapshot('"foo.clientbar.client"') expect(dynamicIds).toBe(undefined) }) + + if (env === 'prod') { + it(`should not display custom _app or _app.server in treeview if there's not any`, () => { + const { stdout } = context + expect(stdout).not.toMatch(/\s\/_app(\.server)?/) + }) + } } diff --git a/test/integration/react-streaming-and-server-components/test/index.test.js b/test/integration/react-streaming-and-server-components/test/index.test.js index 4bdd329708b9e..239235225ebb8 100644 --- a/test/integration/react-streaming-and-server-components/test/index.test.js +++ b/test/integration/react-streaming-and-server-components/test/index.test.js @@ -77,106 +77,83 @@ describe('Edge runtime - errors', () => { }) }) -describe('Edge runtime - prod', () => { - const context = { appDir } - - beforeAll(async () => { - error500Page.write(page500) - context.appPort = await findPort() - const { stderr } = await nextBuild(context.appDir) - context.stderr = stderr - context.server = await nextStart(context.appDir, context.appPort) - }) - afterAll(async () => { - error500Page.delete() - await killApp(context.server) - }) - - it('should warn user for experimental risk with edge runtime and server components', async () => { - const edgeRuntimeWarning = - 'You are using the experimental Edge Runtime with `experimental.runtime`.' - const rscWarning = `You have experimental React Server Components enabled. Continue at your own risk.` - expect(context.stderr).toContain(edgeRuntimeWarning) - expect(context.stderr).toContain(rscWarning) - }) +const edgeRuntimeBasicSuite = { + runTests: (context, env) => { + const options = { runtime: 'edge', env } + basic(context, options) + streaming(context, options) + rsc(context, options) + runtime(context, options) - it('should generate middleware SSR manifests for edge runtime', async () => { - const distServerDir = join(distDir, 'server') - const files = [ - 'middleware-build-manifest.js', - 'middleware-ssr-runtime.js', - 'middleware-flight-manifest.js', - 'middleware-flight-manifest.json', - 'middleware-manifest.json', - ] - - const requiredServerFiles = ( - await fs.readJSON(join(distDir, 'required-server-files.json')) - ).files - - files.forEach((file) => { - const filepath = join(distServerDir, file) - expect(fs.existsSync(filepath)).toBe(true) - }) + if (env === 'dev') { + it('should have content-type and content-encoding headers', async () => { + const res = await fetchViaHTTP(context.appPort, '/') + expect(res.headers.get('content-type')).toBe('text/html; charset=utf-8') + expect(res.headers.get('content-encoding')).toBe('gzip') + }) + } + if (env === 'prod') { + it('should warn user for experimental risk with edge runtime and server components', async () => { + const edgeRuntimeWarning = + 'You are using the experimental Edge Runtime with `experimental.runtime`.' + const rscWarning = `You have experimental React Server Components enabled. Continue at your own risk.` + expect(context.stderr).toContain(edgeRuntimeWarning) + expect(context.stderr).toContain(rscWarning) + }) - requiredServerFiles.forEach((file) => { - const requiredFilePath = join(appDir, file) - expect(fs.existsSync(requiredFilePath)).toBe(true) - }) - }) + it('should generate middleware SSR manifests for edge runtime', async () => { + const distServerDir = join(distDir, 'server') + const files = [ + 'middleware-build-manifest.js', + 'middleware-ssr-runtime.js', + 'middleware-flight-manifest.js', + 'middleware-flight-manifest.json', + 'middleware-manifest.json', + ] - it('should have clientInfo in middleware manifest', async () => { - const middlewareManifestPath = join( - distDir, - 'server', - 'middleware-manifest.json' - ) - const content = JSON.parse( - await fs.readFile(middlewareManifestPath, 'utf8') - ) - for (const item of [ - ['/', true], - ['/next-api/image', true], - ['/next-api/link', true], - ['/routes/[dynamic]', true], - ]) { - expect(content.clientInfo).toContainEqual(item) - } - expect(content.clientInfo).not.toContainEqual([['/404', true]]) - }) + const requiredServerFiles = ( + await fs.readJSON(join(distDir, 'required-server-files.json')) + ).files - const options = { runtime: 'edge', env: 'prod' } - basic(context, options) - streaming(context, options) - rsc(context, options) - runtime(context, options) -}) + files.forEach((file) => { + const filepath = join(distServerDir, file) + expect(fs.existsSync(filepath)).toBe(true) + }) -describe('Edge runtime - dev', () => { - const context = { appDir } + requiredServerFiles.forEach((file) => { + const requiredFilePath = join(appDir, file) + expect(fs.existsSync(requiredFilePath)).toBe(true) + }) + }) - beforeAll(async () => { + it('should have clientInfo in middleware manifest', async () => { + const middlewareManifestPath = join( + distDir, + 'server', + 'middleware-manifest.json' + ) + const content = JSON.parse( + await fs.readFile(middlewareManifestPath, 'utf8') + ) + for (const item of [ + ['/', true], + ['/next-api/image', true], + ['/next-api/link', true], + ['/routes/[dynamic]', true], + ]) { + expect(content.clientInfo).toContainEqual(item) + } + expect(content.clientInfo).not.toContainEqual([['/404', true]]) + }) + } + }, + beforeAll: () => { error500Page.write(page500) - context.appPort = await findPort() - context.server = await nextDev(context.appDir, context.appPort) - }) - afterAll(async () => { + }, + afterAll: () => { error500Page.delete() - await killApp(context.server) - }) - - it('should have content-type and content-encoding headers', async () => { - const res = await fetchViaHTTP(context.appPort, '/') - expect(res.headers.get('content-type')).toBe('text/html; charset=utf-8') - expect(res.headers.get('content-encoding')).toBe('gzip') - }) - - const options = { runtime: 'edge', env: 'dev' } - basic(context, options) - streaming(context, options) - rsc(context, options) - runtime(context, options) -}) + }, +} const nodejsRuntimeBasicSuite = { runTests: (context, env) => { @@ -253,6 +230,8 @@ const documentSuite = { runSuite('Node.js runtime', 'dev', nodejsRuntimeBasicSuite) runSuite('Node.js runtime', 'prod', nodejsRuntimeBasicSuite) +runSuite('Edge runtime', 'dev', edgeRuntimeBasicSuite) +runSuite('Edge runtime', 'prod', edgeRuntimeBasicSuite) runSuite('Custom App', 'dev', customAppPageSuite) runSuite('Custom App', 'prod', customAppPageSuite) @@ -270,7 +249,9 @@ function runSuite(suiteName, env, options) { options.beforeAll?.() if (env === 'prod') { context.appPort = await findPort() - await nextBuild(context.appDir) + const { stdout, stderr } = await nextBuild(context.appDir) + context.stdout = stdout + context.stderr = stderr context.server = await nextStart(context.appDir, context.appPort) } if (env === 'dev') { diff --git a/test/integration/react-streaming-and-server-components/test/rsc.js b/test/integration/react-streaming-and-server-components/test/rsc.js index e96e8dd40f849..0444891c15815 100644 --- a/test/integration/react-streaming-and-server-components/test/rsc.js +++ b/test/integration/react-streaming-and-server-components/test/rsc.js @@ -15,7 +15,6 @@ export default function (context, { runtime, env }) { // should have only 1 DOCTYPE expect(homeHTML).toMatch(/^