Skip to content

Commit

Permalink
Refactor suite-setup-util to avoid knock on errors.
Browse files Browse the repository at this point in the history
This is a small refactor that does a few things:

* migrate the manual promise chaining to async/await
* unify the error handling (so that it is all done in the same way)
* migrate from `process.stderr.write` to `console.error`
  (`process.stderr.write` only accepts a string or buffer, if you pass
  it an instance of `Error` you get an error that actually masks the
  _real_ error)
* migrate to `process.exitCode` instead of `process.exit` (forcing exit
  with `process.exit()` _in general_ should be avoided, and doesn't seem
  required in this context)
  • Loading branch information
rwjblue committed Feb 23, 2021
1 parent 1f7452a commit 33012e2
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions test-packages/support/suite-setup-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,33 +152,29 @@ export async function emitDynamicSuites() {
}
}

if (require.main === module) {
if (process.argv.includes('--list')) {
allSuites()
.then(result => {
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
})
.catch(err => {
process.stderr.write(err);
process.exit(-1);
});
}
async function main() {
try {
if (process.argv.includes('--list')) {
const result = await allSuites();

if (process.argv.includes('--matrix')) {
githubMatrix()
.then(result => {
process.stdout.write(JSON.stringify(result));
})
.catch(err => {
process.stderr.write(err);
process.exit(-1);
});
}
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
}

if (process.argv.includes('--emit')) {
emitDynamicSuites().catch(err => {
console.log(err);
process.exit(-1);
});
if (process.argv.includes('--matrix')) {
const result = await githubMatrix();

process.stdout.write(JSON.stringify(result));
}

if (process.argv.includes('--emit')) {
await emitDynamicSuites();
}
} catch (error) {
console.error(error);
process.exitCode = -1;
}
}

if (require.main === module) {
main();
}

0 comments on commit 33012e2

Please sign in to comment.