Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(integration): improve build failure output in tests #3567

Merged
merged 1 commit into from
Jun 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions integration/helpers/create-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -170,6 +160,12 @@ export async function createFixtureProject(init: FixtureInit): Promise<string> {
// 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);
Expand All @@ -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"));
Expand Down