chore: builds in child process for e2e
This commit is contained in:
7
test/helpers/build.js
Normal file
7
test/helpers/build.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import nextBuild from 'next/dist/build/index.js'
|
||||
|
||||
const build = async () => {
|
||||
await nextBuild.default(process.env.NEXTJS_DIR, false, false, false, true, true, false, 'default')
|
||||
}
|
||||
|
||||
build()
|
||||
@@ -1,8 +1,10 @@
|
||||
import { createServer } from 'http'
|
||||
import nextImport from 'next'
|
||||
import nextBuild from 'next/dist/build/index.js'
|
||||
import { spawn } from 'node:child_process'
|
||||
import { dirname, resolve } from 'path'
|
||||
import { wait } from 'payload/utilities'
|
||||
import { parse } from 'url'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import type { GeneratedTypes } from './sdk/types.js'
|
||||
|
||||
@@ -11,6 +13,9 @@ import { getNextJSRootDir } from './getNextJSRootDir.js'
|
||||
import { PayloadTestSDK } from './sdk/index.js'
|
||||
import startMemoryDB from './startMemoryDB.js'
|
||||
|
||||
const _filename = fileURLToPath(import.meta.url)
|
||||
const _dirname = dirname(_filename)
|
||||
|
||||
type Args = {
|
||||
dirname: string
|
||||
prebuild?: boolean
|
||||
@@ -38,9 +43,27 @@ export async function initPayloadE2ENoConfig<T extends GeneratedTypes<T>>({
|
||||
const dir = getNextJSRootDir(testSuiteName)
|
||||
|
||||
if (prebuild) {
|
||||
await nextBuild.default(dir, false, false, false, true, true, false, 'default')
|
||||
await new Promise<void>((res, rej) => {
|
||||
const buildArgs = ['--max-old-space-size=8192', resolve(_dirname, 'build.js')]
|
||||
|
||||
const childProcess = spawn('node', buildArgs, {
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
PATH: process.env.PATH,
|
||||
NODE_ENV: 'production',
|
||||
NEXTJS_DIR: dir,
|
||||
},
|
||||
})
|
||||
|
||||
childProcess.on('close', (code) => {
|
||||
if (code === 0) res()
|
||||
rej()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
process.env.NODE_OPTIONS = '--max-old-space-size=8192'
|
||||
|
||||
// @ts-expect-error
|
||||
const app = nextImport({
|
||||
dev: !prebuild,
|
||||
|
||||
Reference in New Issue
Block a user