Skip to content

Commit

Permalink
feat(test-kit): include stderr in spawnSync error (#2625)
Browse files Browse the repository at this point in the history
  • Loading branch information
AviVahl authored Jan 8, 2025
1 parent d6d03dd commit 8253192
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/test-kit/src/with-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export function withFeature(withFeatureOptions: IWithFeatureOptions = {}): WithF
const installOptions = {
cwd: projectPath,
shell: true,
stdio: debugMode ? 'inherit' : 'ignore',
stdio: debugMode ? 'inherit' : 'pipe',
} satisfies SpawnSyncOptions;
const shouldRetryInstall = !!process.env.NEW_FIXTURE_DEPENDENCIES_INSTALLATION;

Expand Down Expand Up @@ -785,17 +785,18 @@ function isNonReactDevMessage(type: string, [firstArg]: unknown[]) {
const throwNonZeroExitCodeError = (
args: Parameters<typeof spawnSync | typeof spawn>,
status: ChildProcess['exitCode'],
stderr?: string,
) => {
const command = args.filter((arg) => typeof arg === 'string').join(' ');
const exitCode = status ?? 'null';

throw new Error(`Command "${command}" failed with exit code ${exitCode}.`);
throw new Error(`Command "${command}" failed with exit code ${exitCode}.${stderr ? `\n${stderr}` : ''}`);
};

export const spawnSyncSafe = (...args: Parameters<typeof spawnSync>) => {
const spawnResult = spawnSync(...args);
if (spawnResult.status !== 0) {
throwNonZeroExitCodeError(args, spawnResult.status);
throwNonZeroExitCodeError(args, spawnResult.status, spawnResult.stderr.toString());
}
return spawnResult;
};
Expand Down

0 comments on commit 8253192

Please sign in to comment.