UNPKG

889 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const mock = require("stdout-stderr");
4const create = (std) => (opts = {}) => ({
5 run(ctx) {
6 mock[std].start();
7 mock[std].print = opts.print || process.env.TEST_OUTPUT === '1';
8 mock[std].stripColor = opts.stripColor !== false;
9 if (ctx[std] !== undefined)
10 return;
11 Object.defineProperty(ctx, std, {
12 get: () => mock[std].output,
13 });
14 },
15 finally() {
16 mock[std].stop();
17 },
18});
19exports.stdout = create('stdout');
20exports.stderr = create('stderr');
21exports.stdin = (input, delay = 0) => {
22 let stdin;
23 return {
24 run: () => {
25 stdin = require('mock-stdin').stdin();
26 setTimeout(() => stdin.send(input), delay);
27 },
28 finally() {
29 stdin.restore();
30 },
31 };
32};