Skip to content

Commit

Permalink
fix: --json can now fail
Browse files Browse the repository at this point in the history
Also `--linger` outputs the temp dir(s) in non-JSON mode.
  • Loading branch information
boneskull committed Aug 7, 2023
1 parent 41b423c commit 5df9d9c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,25 @@ async function main(args: string[]): Promise<void> {
.removeAllListeners(events.RUN_SCRIPTS_FAILED);
output = result;
};
const writeResult = () => {
const cleanup = () => {
smoker
.removeAllListeners(events.SMOKE_OK)
.removeAllListeners(events.SMOKE_FAILED);
};
const writeOk = () => {
cleanup();
console.log(JSON.stringify(output, null, 2));
};
const writeFailed = () => {
cleanup();
console.log(JSON.stringify(output, null, 2));
process.exitCode = 1;
};
smoker
.once(events.RUN_SCRIPTS_OK, setResult)
.once(events.RUN_SCRIPTS_FAILED, setResult)
.once(events.SMOKE_FAILED, writeResult)
.once(events.SMOKE_OK, writeResult);
.once(events.SMOKE_FAILED, writeFailed)
.once(events.SMOKE_OK, writeOk);
await smoker.smoke();
} else {
const spinner = ora();
Expand Down Expand Up @@ -264,6 +272,14 @@ async function main(args: string[]): Promise<void> {
})
.on(events.SMOKE_OK, () => {
spinner.succeed('Lovey-dovey! 💖');
})
.on(events.LINGERED, (dirs) => {
console.error(
`Lingering ${pluralize('temp directory', dirs.length)}:\n`,
);
for (const dir of dirs) {
console.error(` ${yellow(dir)}`);
}
});
await smoker.smoke();
}
Expand Down

0 comments on commit 5df9d9c

Please # to comment.