1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
16 | return new (P || (P = Promise))(function (resolve, reject) {
|
17 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
18 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
19 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
20 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
21 | });
|
22 | };
|
23 | Object.defineProperty(exports, "__esModule", { value: true });
|
24 | const chai_1 = require("chai");
|
25 | function getFlowingState(stream) {
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | const privateReadableState = stream._readableState;
|
32 | return privateReadableState.flowing;
|
33 | }
|
34 | exports.getFlowingState = getFlowingState;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function emittedFiles(stream, root = '') {
|
41 | return __awaiter(this, void 0, void 0, function* () {
|
42 | const files = new Map();
|
43 | return new Promise((resolve, reject) => stream
|
44 | .on('data', (f) => files.set(f.path.substring(root.length + 1), f))
|
45 | .on('data', () => { })
|
46 | .on('end', () => resolve(files))
|
47 | .on('error', (e) => reject(e)));
|
48 | });
|
49 | }
|
50 | exports.emittedFiles = emittedFiles;
|
51 |
|
52 |
|
53 |
|
54 | exports.assertEqualIgnoringWhitespace = (actual, expected) => chai_1.assert.equal(collapseWhitespace(actual), collapseWhitespace(expected));
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | exports.assertMapEqualIgnoringWhitespace = (actual, expected) => assertMapEqual(transformMapValues(actual, collapseWhitespace), transformMapValues(expected, collapseWhitespace));
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | const collapseWhitespace = (s) => s.replace(/^\s+/gm, '').replace(/\s+$/gm, '').replace(/\n/gm, '');
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | const assertMapEqual = (actual, expected) => chai_1.assert.deepEqual([...actual.entries()], [...expected.entries()]);
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | const transformMapValues = (map, transform) => new Map([...map.entries()].map(([key, val]) => [key, transform(val)]));
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | function interceptOutput(captured) {
|
86 | return __awaiter(this, void 0, void 0, function* () {
|
87 | const originalLog = console.log;
|
88 | const originalError = console.error;
|
89 | const originalWarn = console.warn;
|
90 | const buffer = [];
|
91 |
|
92 | const capture = (...args) => {
|
93 | buffer.push(args.join(' '));
|
94 | };
|
95 | console.log = capture;
|
96 | console.error = capture;
|
97 | console.warn = capture;
|
98 | const restoreAndGetOutput = () => {
|
99 | console.log = originalLog;
|
100 | console.error = originalError;
|
101 | console.warn = originalWarn;
|
102 | return buffer.join('\n');
|
103 | };
|
104 | try {
|
105 | yield captured();
|
106 | }
|
107 | catch (err) {
|
108 | const output = restoreAndGetOutput();
|
109 | console.error(output);
|
110 | throw err;
|
111 | }
|
112 | return restoreAndGetOutput();
|
113 | });
|
114 | }
|
115 | exports.interceptOutput = interceptOutput;
|
116 |
|
\ | No newline at end of file |