concurrently
Version:
Run commands concurrently
38 lines (37 loc) • 1.06 kB
JavaScript
import EventEmitter from 'node:events';
import { PassThrough, Writable } from 'node:stream';
import { vi } from 'vitest';
import { Command } from '../command.js';
import { createMockInstance } from './create-mock-instance.js';
export class FakeCommand extends Command {
constructor(name = 'foo', command = 'echo foo', index = 0, info) {
super({
index,
name,
command,
...info,
}, {}, vi.fn(), vi.fn());
this.stdin = createMockInstance(Writable);
this.start = vi.fn();
this.kill = vi.fn();
}
}
export const createFakeProcess = (pid) => Object.assign(new EventEmitter(), {
pid,
send: vi.fn(),
stdin: new PassThrough(),
stdout: new PassThrough(),
stderr: new PassThrough(),
});
export const createFakeCloseEvent = (overrides) => ({
command: new FakeCommand(),
index: 0,
killed: false,
exitCode: 0,
timings: {
startDate: new Date(),
endDate: new Date(),
durationSeconds: 0,
},
...overrides,
});