fake.returns({ restart: fake.resolves(true), exec: ({ Cmd }) => { const mockedStream = new stream.Readable(); return fake.resolves({ start: sinon.stub().yields(Cmd[0] === 'fail' ? 'error' : null, mockedStream), })(); }, })
function capture () { const ws = writer((chunk, enc, cb) => { ws.data += chunk.toString() cb() }) ws.data = '' return ws }
test('do not use SonicBoom is someone tampered with process.stdout.write', async ({ isNot }) => { var actual = '' const child = fork(join(__dirname, 'fixtures', 'stdout-hack-protection.js'), { silent: true }) child.stdout.pipe(writer((s, enc, cb) => { actual += s cb() })) await once(child, 'close') isNot(actual.match(/^hack/), null) })
function isReadableStream(obj) { return ( obj instanceof stream.Stream && (getType(obj._read) === "Function" || getType(obj._read) === "AsyncFunction") && getType(obj._readableState) === "Object" ); }
test.serial('Running `carbon-now` fails without file or stdin', async t => { try { // https://github.com/sindresorhus/get-stdin/issues/13#issuecomment-279234249 const command = exec(`node ${SCRIPT}`); command.childProcess.stdin.end(); await command; t.fail(); } catch (error) { t.pass(); } });
function test (file) { file = join('fixtures', 'broken-pipe', file) t.test(file, { parallel: true }, async ({ is }) => { const child = fork(join(__dirname, file), { silent: true }) child.stdout.destroy() child.stderr.pipe(process.stdout) const res = await once(child, 'close') is(res, 0) // process exits successfully }) }
function sink (func) { const result = split((data) => { try { return JSON.parse(data) } catch (err) { console.log(err) console.log(data) } }) if (func) result.pipe(writer.obj(func)) return result }
test('pino uses LF by default', async ({ ok }) => { const stream = capture() const logger = pino(stream) logger.info('foo') logger.error('bar') ok(/foo[^\r\n]+\n[^\r\n]+bar[^\r\n]+\n/.test(stream.data)) })
child.stdout.on("data", (data) => { dashboard.onEvent({ type: "stdout", data: data.toString("utf8") }); });
child.stdout.on("data", msg => { msg = msg .toString() .split("\n") .filter(m => { return m.indexOf("already satisfied") === -1; }) .join("\n"); process.stdout.write(msg); });
child.stderr.on("data", (data) => { dashboard.onEvent({ type: "stderr", data: data.toString("utf8") }); });
fake.returns({ restart: fake.resolves(true), exec: ({ Cmd }) => { const mockedStream = new stream.Readable(); return fake.resolves({ start: sinon.stub().yields(Cmd[0] === 'fail' ? 'error' : null, mockedStream), })(); }, })
child.stdout.on("data", msg => { msg = msg .toString() .split("\n") .filter(m => { return m.indexOf("already satisfied") === -1; }) .join("\n"); process.stdout.write(msg); });
test('pino can log CRLF', async ({ ok }) => { const stream = capture() const logger = pino({ crlf: true }, stream) logger.info('foo') logger.error('bar') ok(/foo[^\n]+\r\n[^\n]+bar[^\n]+\r\n/.test(stream.data)) })