Skip to content

Commit

Permalink
Add command string to error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Jun 18, 2023
1 parent 2bbe0e5 commit 6d83c2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion run-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ const runScripts = {
const logItems = settings.verbose ? [chalk.white(group), chalk.yellow(step), arrow] : [];
logger(...logItems, chalk.cyanBright(command));
const task = spawnSync(command, { shell: true, stdio: 'inherit' });
const errorMessage = () =>
`[run-scripts-util] Task: ${group} (step ${step}), Status: ${task.status}`;
if (task.status !== 0)
throw Error(`[run-scripts-util] ${group} #${step}, error status: ${task.status}`);
throw Error(errorMessage() + '\nCommand: ' + command);
logger(...logItems, chalk.green('done'), chalk.white(`(${Date.now() - startTime}ms)`));
};
const active = (step: number) => settings.only === null || step === settings.only;
Expand Down
8 changes: 4 additions & 4 deletions spec/mocha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ describe('Correct error is thrown', () => {

////////////////////////////////////////////////////////////////////////////////
describe('Executing the CLI', () => {
const cmd = (posix) => process.platform === 'win32' ? posix.replaceAll('\\ ', '" "') : posix;
const run = (posix) => execSync(cmd(posix), { stdio: 'inherit' });

it('correctly runs parallel commands', () => {
// Handy script:
// "devp": "tsc && add-dist-header build dist && rimraf spec/fixtures/target/b && mocha spec/*.spec.js --grep parallel --timeout 7000",
const cmd = 'node bin/cli.js spec-b1 spec-b2 --parallel --verbose';
execSync(cmd, { stdio: 'inherit' });
run('node bin/cli.js spec-b1 spec-b2 --parallel --verbose');
const actual = revWebAssets.readFolderRecursive('spec/fixtures/target/b');
const expected = [
'spec/fixtures/target/b/1/w.json',
Expand All @@ -92,8 +93,7 @@ describe('Executing the CLI', () => {
});

it('with two command groups correctly runs them in serial', () => {
const cmd = 'node bin/cli.js spec-c1 spec-c2 --note=hello --quiet';
execSync(cmd, { stdio: 'inherit' });
run('node bin/cli.js spec-c1 spec-c2 --note=hello --quiet');
const actual = revWebAssets.readFolderRecursive('spec/fixtures/target/c');
const expected = [
'spec/fixtures/target/c/2/last.txt',
Expand Down

0 comments on commit 6d83c2d

Please sign in to comment.