From c27f8b21ff596e45be14b3588e4015960afba5f7 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 8 Apr 2022 14:15:59 +0200 Subject: [PATCH] add env to options callbacks --- test/integration/react-18/test/index.test.js | 4 +--- .../test/functions.js | 9 ++++++--- .../test/index.test.js | 2 +- .../test/runtime.js | 4 ++-- .../test/switchable-runtime.test.js | 6 ++++-- .../test/utils.js | 1 - test/lib/next-test-utils.js | 16 ++++++++++++---- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/test/integration/react-18/test/index.test.js b/test/integration/react-18/test/index.test.js index 2ed0e54f757d..43e2287ac11b 100644 --- a/test/integration/react-18/test/index.test.js +++ b/test/integration/react-18/test/index.test.js @@ -23,9 +23,7 @@ const nextConfig = new File(join(appDir, 'next.config.js')) const invalidPage = new File(join(appDir, 'pages/invalid.js')) describe('Basics', () => { - runTests('default setting with react 18', (context, env) => - basics(context, env) - ) + runTests('default setting with react 18', basics) }) // React 18 with Strict Mode enabled might cause double invocation of lifecycle methods. diff --git a/test/integration/react-streaming-and-server-components/test/functions.js b/test/integration/react-streaming-and-server-components/test/functions.js index 965190486c2f..31f98fcca124 100644 --- a/test/integration/react-streaming-and-server-components/test/functions.js +++ b/test/integration/react-streaming-and-server-components/test/functions.js @@ -10,20 +10,23 @@ import { nextBuild } from './utils' export default function (context) { it('should not generate functions manifest when filesystem API is not enabled', async () => { // Make sure there is no existing functions manifest (caused by failed tests etc). - await fs.remove(join(context.appDir, '.next')) + const distDir = join(context.appDir, '.next') + await fs.remove(distDir) await nextBuild(context.appDir) const functionsManifestPath = join( - context.distDir, + distDir, 'server', 'functions-manifest.json' ) expect(fs.existsSync(functionsManifestPath)).toBe(false) await fs.remove(join(context.appDir, '.next')) }) + it('should contain rsc paths in functions manifest', async () => { + const distDir = join(context.appDir, '.next') await nextBuild(context.appDir, { env: { ENABLE_FILE_SYSTEM_API: '1' } }) const functionsManifestPath = join( - context.distDir, + distDir, 'server', 'functions-manifest.json' ) 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 5b3935081cb8..776171e2464d 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 @@ -14,7 +14,6 @@ import { import { appDir, nativeModuleTestAppDir, - distDir, appPage, appServerPage, error500Page, @@ -62,6 +61,7 @@ describe('Edge runtime - errors', () => { const edgeRuntimeBasicSuite = { runTests: (context, env) => { const options = { runtime: 'edge', env } + const distDir = join(appDir, '.next') basic(context, options) streaming(context, options) rsc(context, options) diff --git a/test/integration/react-streaming-and-server-components/test/runtime.js b/test/integration/react-streaming-and-server-components/test/runtime.js index b166fdb4ded3..236510214b62 100644 --- a/test/integration/react-streaming-and-server-components/test/runtime.js +++ b/test/integration/react-streaming-and-server-components/test/runtime.js @@ -2,9 +2,9 @@ import { renderViaHTTP } from 'next-test-utils' import { join } from 'path' import fs from 'fs-extra' -import { distDir } from './utils' - export default async function runtime(context, { runtime, env }) { + const distDir = join(context.appDir, '.next') + if (runtime === 'edge') { it('should support per-page runtime configuration', async () => { const html1 = await renderViaHTTP(context.appPort, '/runtime') diff --git a/test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js b/test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js index d26110804049..9ab6d68d3492 100644 --- a/test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js +++ b/test/integration/react-streaming-and-server-components/test/switchable-runtime.test.js @@ -5,10 +5,12 @@ import { check, findPort, killApp, + launchApp, + nextBuild, + nextStart, renderViaHTTP, waitFor, } from 'next-test-utils' -import { nextBuild, nextDev, nextStart } from './utils' const appDir = join(__dirname, '../switchable-runtime') @@ -252,7 +254,7 @@ describe('Switchable runtime (dev)', () => { beforeAll(async () => { context.appPort = await findPort() - context.server = await nextDev(context.appDir, context.appPort) + context.server = await launchApp(context.appDir, context.appPort) }) afterAll(async () => { await killApp(context.server) diff --git a/test/integration/react-streaming-and-server-components/test/utils.js b/test/integration/react-streaming-and-server-components/test/utils.js index 92c9afe2b6b7..d1f19ed8e80f 100644 --- a/test/integration/react-streaming-and-server-components/test/utils.js +++ b/test/integration/react-streaming-and-server-components/test/utils.js @@ -7,7 +7,6 @@ export const nativeModuleTestAppDir = join( __dirname, '../unsupported-native-module' ) -export const distDir = join(__dirname, '../app/.next') export const appPage = new File(join(appDir, 'pages/_app.js')) export const appServerPage = new File(join(appDir, 'pages/_app.server.js')) export const error500Page = new File(join(appDir, 'pages/500.js')) diff --git a/test/lib/next-test-utils.js b/test/lib/next-test-utils.js index 2f75a2099ec2..a33c5970a128 100644 --- a/test/lib/next-test-utils.js +++ b/test/lib/next-test-utils.js @@ -733,7 +733,11 @@ function runSuite(suiteName, context, options) { const { appDir, env } = context describe(`${suiteName} ${env}`, () => { beforeAll(async () => { - options.beforeAll?.() + options.beforeAll?.(env) + context.stderr = '' + const onStderr = (msg) => { + context.stderr += msg + } if (env === 'prod') { context.appPort = await findPort() const { stdout, stderr, code } = await nextBuild(appDir, [], { @@ -743,14 +747,18 @@ function runSuite(suiteName, context, options) { context.stdout = stdout context.stderr = stderr context.code = code - context.server = await nextStart(context.appDir, context.appPort) + context.server = await nextStart(context.appDir, context.appPort, { + onStderr, + }) } else if (env === 'dev') { context.appPort = await findPort() - context.server = await launchApp(context.appDir, context.appPort) + context.server = await launchApp(context.appDir, context.appPort, { + onStderr, + }) } }) afterAll(async () => { - options.afterAll?.() + options.afterAll?.(env) if (context.server) { await killApp(context.server) }