Closed tommy-mitchell closed 1 year ago
I’m not sure why the tests are failing in Node 14.
Turns out error.cause
isn't supported in Node 14:
throw new Error(formatter(diagnostics, showDiff), {cause: 'tsd found diagnostics'});
It now only throws on failure, and otherwise exits with an error code if any error
-level diagnostics are found:
const exit = (message: string, {isError = true}: {isError?: boolean} = {}) => {
if (isError) {
console.error(message);
process.exit(1);
} else {
console.log(message);
process.exit(0);
}
};
try {
// ...
if (diagnostics.length > 0) {
const hasErrors = diagnostics.some(diagnostic => diagnostic.severity === 'error');
const formattedDiagnostics = formatter(diagnostics, showDiff);
exit(formattedDiagnostics, {isError: hasErrors});
}
} catch (error: unknown) {
const potentialError = error as Error | undefined;
const errorMessage = potentialError?.stack ?? potentialError?.message ?? 'tsd unexpectedly crashed.';
exit(`Error running tsd:\n${errorMessage}`);
}
The formatter also needs to report the number of warnings, but I have another PR for that.
Edit: #184
Starting in
v0.26.1
, successful runs of the CLI (i.e. when it doesn't crash) incorrectly report an error and error stack while runningtsd
:This PR restores the old behavior and makes sure that the error message and stack are only displayed when
tsd
crashes.