UNPKG

xpm

Version:

The xPack project manager command line tool

61 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MockConsole = void 0; const node_assert_1 = require("node:assert"); const node_console_1 = require("node:console"); const node_stream_1 = require("node:stream"); class MockConsole extends node_console_1.Console { constructor() { const ostream = new node_stream_1.Writable({ decodeStrings: true, defaultEncoding: 'utf-8', write: (chunk, encoding, callback) => { (0, node_assert_1.strict)(encoding === 'buffer'); this.outBuffer += chunk.toString('utf-8'); while (true) { const ix = this.outBuffer.indexOf('\n'); if (ix === -1) { break; } this.outLines.push(this.outBuffer.substring(0, ix)); this.outBuffer = this.outBuffer.substring(ix + 1); } callback(); } }); const errstream = new node_stream_1.Writable({ decodeStrings: true, defaultEncoding: 'utf-8', write: (chunk, encoding, callback) => { (0, node_assert_1.strict)(encoding === 'buffer'); this.errBuffer += chunk.toString('utf-8'); while (true) { const ix = this.errBuffer.indexOf('\n'); if (ix === -1) { break; } this.errLines.push(this.errBuffer.substring(0, ix)); this.errBuffer = this.errBuffer.substring(ix + 1); } callback(); } }); super({ stdout: ostream, stderr: errstream }); this.outLines = []; this.errLines = []; this.outBuffer = ''; this.errBuffer = ''; } clear() { super.clear(); this.outLines = []; this.outBuffer = ''; this.errLines = []; this.errBuffer = ''; } } exports.MockConsole = MockConsole; //# sourceMappingURL=mock-console.js.map