chore: builds in child process for e2e

This commit is contained in:
James
2024-04-05 15:23:07 -04:00
parent 9147d30152
commit 3c09b95a8c
2 changed files with 32 additions and 2 deletions

7
test/helpers/build.js Normal file
View 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()

View File

@@ -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,