From bbd28940544191ea42ccee7aac27b6f4c552c422 Mon Sep 17 00:00:00 2001 From: Jon Jensen Date: Sat, 25 Jun 2022 00:34:19 -0600 Subject: [PATCH] chore(integration): improve build failure output in tests (#3567) --- integration/helpers/create-fixture.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/integration/helpers/create-fixture.ts b/integration/helpers/create-fixture.ts index 82a8da5cf2d..a3ca94c5ead 100644 --- a/integration/helpers/create-fixture.ts +++ b/integration/helpers/create-fixture.ts @@ -4,7 +4,6 @@ import type { Writable } from "stream"; import express from "express"; import getPort from "get-port"; import stripIndent from "strip-indent"; -import chalk from "chalk"; import { sync as spawnSync } from "cross-spawn"; import type { JsonObject } from "type-fest"; @@ -35,15 +34,6 @@ export function json(value: JsonObject) { export async function createFixture(init: FixtureInit) { let projectDir = await createFixtureProject(init); let buildPath = path.resolve(projectDir, "build"); - if (!fse.existsSync(buildPath)) { - throw new Error( - chalk.red( - `Expected build directory to exist at ${chalk.dim( - buildPath - )}. The build probably failed. Did you maybe have a syntax error in your test code strings?` - ) - ); - } let app: ServerBuild = await import(buildPath); let handler = createRequestHandler(app, "production"); @@ -170,6 +160,12 @@ export async function createFixtureProject(init: FixtureInit): Promise { // console.log(" " + setupSpawn.stdout.toString("utf-8")); // console.log(" STDERR:"); // console.log(" " + setupSpawn.stderr.toString("utf-8")); + if (setupSpawn.error || setupSpawn.status) { + console.error(setupSpawn.stderr.toString("utf-8")); + throw ( + setupSpawn.error || new Error(`Setup failed, check the output above`) + ); + } } await writeTestFiles(init, projectDir); build(projectDir, init.buildStdio, init.sourcemap); @@ -191,7 +187,11 @@ function build(projectDir: string, buildStdio?: Writable, sourcemap?: boolean) { // console.log(" STDOUT:"); // console.log(" " + buildSpawn.stdout.toString("utf-8")); // console.log(" STDERR:"); - // console.log(" " + buildSpawn.stderr.toString("utf-8")); + // console.log(" " + buildSpawn.stderr.toString("utf-8")); + if (buildSpawn.error || buildSpawn.status) { + console.error(buildSpawn.stderr.toString("utf-8")); + throw buildSpawn.error || new Error(`Build failed, check the output above`); + } if (buildStdio) { buildStdio.write(buildSpawn.stdout.toString("utf-8"));