UNPKG

concurrently-with-grid

Version:
42 lines (32 loc) 1.34 kB
const { createMockInstance } = require('jest-create-mock-instance'); const Logger = require('../logger'); const LogOutput = require('./log-output'); const createFakeCommand = require('./fixtures/fake-command'); let controller, logger, commands; beforeEach(() => { commands = [ createFakeCommand(), createFakeCommand(), ]; logger = createMockInstance(Logger); controller = new LogOutput({ logger, grid: false }); }); it('returns same commands', () => { expect(controller.handle(commands)).toBe(commands); }); it('logs the stdout of each command', () => { controller.handle(commands); commands[0].stdout.next(Buffer.from('foo')); commands[1].stdout.next(Buffer.from('bar')); expect(logger.logCommandText).toHaveBeenCalledTimes(2); expect(logger.logCommandText).toHaveBeenCalledWith('foo', commands[0]); expect(logger.logCommandText).toHaveBeenCalledWith('bar', commands[1]); }); it('logs the stderr of each command', () => { controller.handle(commands); commands[0].stderr.next(Buffer.from('foo')); commands[1].stderr.next(Buffer.from('bar')); expect(logger.logCommandText).toHaveBeenCalledTimes(2); expect(logger.logCommandText).toHaveBeenCalledWith('foo', commands[0]); expect(logger.logCommandText).toHaveBeenCalledWith('bar', commands[1]); });