1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const mock = require("stdout-stderr");
|
4 | const 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 | });
|
19 | exports.stdout = create('stdout');
|
20 | exports.stderr = create('stderr');
|
21 | exports.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 | };
|