diff --git a/test/lib/next-test-utils.ts b/test/lib/next-test-utils.ts index 1816d5c9c9559..95229a59ca50d 100644 --- a/test/lib/next-test-utils.ts +++ b/test/lib/next-test-utils.ts @@ -46,6 +46,8 @@ export function initNextServerScript( nodeArgs?: string[] onStdout?: (data: any) => void onStderr?: (data: any) => void + // If true, the promise will reject if the process exits with a non-zero code + shouldRejectOnError?: boolean } ): Promise { return new Promise((resolve, reject) => { @@ -83,6 +85,14 @@ export function initNextServerScript( } } + if (opts?.shouldRejectOnError) { + instance.on('exit', (code) => { + if (code !== 0) { + reject(new Error('exited with code: ' + code)) + } + }) + } + instance.stdout.on('data', handleStdout) instance.stderr.on('data', handleStderr) diff --git a/test/production/standalone-mode/required-server-files/required-server-files.test.ts b/test/production/standalone-mode/required-server-files/required-server-files.test.ts index 1d99d8f7afdd8..ef60f87d8912d 100644 --- a/test/production/standalone-mode/required-server-files/required-server-files.test.ts +++ b/test/production/standalone-mode/required-server-files/required-server-files.test.ts @@ -142,6 +142,7 @@ describe('required server files', () => { errors.push(msg) stderr += msg }, + shouldRejectOnError: true, } ) })