run-in-all
Version:
A CLI tool to run the same npm-script in multiple directories in parallel or sequential.
104 lines • 3.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
jest.setTimeout(10000);
const testcases = [
{
command: 'npm',
script: 'sleep',
silent: true,
directories: ['test/lib1'],
minRuntime: 1000,
maxRuntime: 2000,
},
{
command: 'yarn',
script: 'sleep',
directories: ['test/lib1'],
minRuntime: 1000,
maxRuntime: 2000,
},
{
command: 'npm',
script: 'sleep',
directories: ['test/lib1'],
minRuntime: 1000,
maxRuntime: 2000,
},
{
command: 'yarn',
script: 'sleep',
directories: ['test/lib1', 'test/lib2', 'test/lib3'],
minRuntime: 6000,
maxRuntime: 7000,
},
{
command: 'yarn',
script: 'sleep',
parallel: true,
directories: ['test/lib1', 'test/lib2', 'test/lib3'],
minRuntime: 3000,
maxRuntime: 4000,
},
{
command: 'yarn',
script: 'echo',
args: ['first', 'second'],
directories: ['test/lib1', 'test/lib2', 'test/lib3'],
},
{
command: 'npm',
script: 'sleep',
directories: ['test/lib1', 'test/lib2', 'test/lib3'],
minRuntime: 6000,
maxRuntime: 7000,
},
{
command: 'npm',
script: 'sleep',
parallel: true,
directories: ['test/lib1', 'test/lib2', 'test/lib3'],
minRuntime: 3000,
maxRuntime: 4000,
},
{
command: 'npm',
script: 'echo',
args: ['first', 'second'],
directories: ['test/lib1', 'test/lib2', 'test/lib3'],
},
];
function getTestName({ command, script, silent, parallel, args, directories, }) {
return `should run script '${script}' using '${command}' ${silent ? 'silently and ' : ''}${parallel ? 'in parallel' : 'sequentially'} ${(args === null || args === void 0 ? void 0 : args.length) ? 'using args ' : ''}in ${directories.length > 1 ? 'multiple directories' : 'a single directory'}`;
}
describe('Runner', () => {
testcases.forEach((testcase) => {
it(getTestName(testcase), (done) => {
const { command, script, silent, parallel, args, directories, maxRuntime, minRuntime, } = testcase;
const startTime = Date.now();
let output = '';
const child = child_process_1.spawn('yarn', [
'start:prod',
command === 'yarn' ? '-y' : '',
silent ? '-s' : '',
parallel ? '-p' : '',
(args === null || args === void 0 ? void 0 : args.length) ? `-a "${args.join(' ')}"` : '',
script,
...directories,
].filter(Boolean), {
cwd: process.cwd(),
});
child.stdout.on('data', (chunk) => (output += chunk.toString()));
child.on('exit', (exitCode) => {
expect(exitCode).toBe(0);
if (minRuntime && maxRuntime) {
const runTime = Date.now() - startTime;
expect(runTime).toBeGreaterThan(minRuntime);
expect(runTime).toBeLessThan(maxRuntime);
}
done();
});
});
});
});
//# sourceMappingURL=runner.spec.js.map