fix(core): run-commands should fail when a command in serial fails (#4477)
This commit is contained in:
parent
19c5f53ebf
commit
82f801b0db
@ -58,4 +58,25 @@ describe('Run Commands', () => {
|
|||||||
expect(result).toContain('print: y');
|
expect(result).toContain('print: y');
|
||||||
done();
|
done();
|
||||||
}, 120000);
|
}, 120000);
|
||||||
|
|
||||||
|
it('should fail when a process exits non-zero', () => {
|
||||||
|
newProject();
|
||||||
|
const myapp = uniq('myapp1');
|
||||||
|
|
||||||
|
runCLI(`generate @nrwl/web:app ${myapp}`);
|
||||||
|
|
||||||
|
const config = readJson(workspaceConfigName());
|
||||||
|
config.projects[myapp].targets.error = {
|
||||||
|
executor: '@nrwl/workspace:run-commands',
|
||||||
|
options: {
|
||||||
|
command: `exit 1`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
updateFile(workspaceConfigName(), JSON.stringify(config));
|
||||||
|
|
||||||
|
try {
|
||||||
|
runCLI('error');
|
||||||
|
fail('Should error if process errors');
|
||||||
|
} catch (e) {}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -177,7 +177,7 @@ describe('Command Runner Builder', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should stop execution when a command fails', async () => {
|
it('should stop execution and fail when a command fails', async () => {
|
||||||
const f = fileSync().name;
|
const f = fileSync().name;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -185,6 +185,7 @@ describe('Command Runner Builder', () => {
|
|||||||
commands: [`echo 1 >> ${f} && exit 1`, `echo 2 >> ${f}`],
|
commands: [`echo 1 >> ${f} && exit 1`, `echo 2 >> ${f}`],
|
||||||
parallel: false,
|
parallel: false,
|
||||||
});
|
});
|
||||||
|
fail('should fail when a command fails');
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
expect(readFile(f)).toEqual('1');
|
expect(readFile(f)).toEqual('1');
|
||||||
});
|
});
|
||||||
|
|||||||
@ -152,9 +152,9 @@ function normalizeOptions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function runSerially(options: NormalizedRunCommandsBuilderOptions) {
|
async function runSerially(options: NormalizedRunCommandsBuilderOptions) {
|
||||||
options.commands.forEach((c) => {
|
for (const c of options.commands) {
|
||||||
createSyncProcess(c.command, options.color, options.cwd);
|
createSyncProcess(c.command, options.color, options.cwd);
|
||||||
});
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -158,9 +158,16 @@ function normalizeOptions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function runSerially(options: NormalizedRunCommandsBuilderOptions) {
|
async function runSerially(options: NormalizedRunCommandsBuilderOptions) {
|
||||||
options.commands.forEach((c) => {
|
for (const c of options.commands) {
|
||||||
|
try {
|
||||||
createSyncProcess(c.command, options.color, options.cwd);
|
createSyncProcess(c.command, options.color, options.cwd);
|
||||||
});
|
} catch (e) {
|
||||||
|
process.stderr.write(
|
||||||
|
`Warning: @nrwl/run-commands command "${c.command}" exited with non-zero status code`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user