Skip to content

Commit

Permalink
add env to options callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Apr 8, 2022
1 parent 595e7c0 commit c27f8b2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 16 deletions.
4 changes: 1 addition & 3 deletions test/integration/react-18/test/index.test.js
Expand Up @@ -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.
Expand Down
Expand Up @@ -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'
)
Expand Down
Expand Up @@ -14,7 +14,6 @@ import {
import {
appDir,
nativeModuleTestAppDir,
distDir,
appPage,
appServerPage,
error500Page,
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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')
Expand Down
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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'))
Expand Down
16 changes: 12 additions & 4 deletions test/lib/next-test-utils.js
Expand Up @@ -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, [], {
Expand All @@ -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)
}
Expand Down

0 comments on commit c27f8b2

Please sign in to comment.