UNPKG

@fontoxml/fontoxml-development-tools

Version:
911 lines (833 loc) 28.4 kB
'use strict'; const assert = require('assert'); const stream = require('stream'); const fontoxmlDevelopmentTools = require('../'); const AssertableWritableStream = fontoxmlDevelopmentTools.AssertableWritableStream; let testOutput; describe('AssertableWritableStream', () => { beforeEach(() => { testOutput = new AssertableWritableStream(); }); it('extends stream.Writable', () => { assert.ok(testOutput instanceof stream.Writable); assert.ok(testOutput._write); }); it('can write to stream', () => { assert.ok(typeof testOutput.write === 'function'); assert.ok(typeof testOutput._write === 'function'); assert.doesNotThrow(() => { testOutput.write('test output'); }); }); it('can capture output', () => { testOutput.write('test output'); testOutput.assert('test output'); }); it('can give a copy of all written output', () => { testOutput.write('test output 1'); testOutput.write('test output 2'); const output = testOutput.getOutput(); assert.ok(output); assert.strictEqual(output.length, 2); assert.deepEqual(output, [ 'test output 1', 'test output 2' ]); }); it('can reset the output', () => { testOutput.write('test output'); testOutput.assert('test output'); testOutput.resetOutput(); const output = testOutput.getOutput(); assert.ok(output); assert.strictEqual(output.length, 0); }); it('can write multiple values when in cork mode', () => { testOutput.cork(); testOutput.write('test output 1'); testOutput.write('test output 2'); let output = testOutput.getOutput(); assert.ok(output); assert.strictEqual(output.length, 0); testOutput.uncork(); output = testOutput.getOutput(); assert.ok(output); assert.strictEqual(output.length, 2); assert.deepEqual(output, [ 'test output 1', 'test output 2' ]); }); it('can provide raw output', () => { testOutput = new AssertableWritableStream({ decodeStrings: true }); testOutput.write('test output 1'); testOutput.write('test output 2', 'utf8'); testOutput.write('test output 3', 'ascii'); testOutput.write(new Buffer('test output 4', 'utf8')); const rawOutput = testOutput.getRawOutput(); assert.ok(rawOutput); assert.strictEqual(rawOutput.length, 4); assert.deepEqual(rawOutput, [ { chunk: new Buffer('test output 1', 'utf8'), encoding: 'buffer' }, { chunk: new Buffer('test output 2', 'utf8'), encoding: 'buffer' }, { chunk: new Buffer('test output 3', 'ascii'), encoding: 'buffer' }, { chunk: new Buffer('test output 4', 'utf8'), encoding: 'buffer' } ]); }); it('can re-enable decodeStrings and get raw output', () => { testOutput.write('test output 1'); testOutput.write('test output 2', 'utf8'); testOutput.write('test output 3', 'ascii'); testOutput.write(new Buffer('test output 4', 'utf8')); const rawOutput = testOutput.getRawOutput(); assert.ok(rawOutput); assert.strictEqual(rawOutput.length, 4); assert.deepEqual(rawOutput, [ { chunk: 'test output 1', encoding: 'utf8' }, { chunk: 'test output 2', encoding: 'utf8' }, { chunk: 'test output 3', encoding: 'ascii' }, { chunk: new Buffer('test output 4', 'utf8'), encoding: 'buffer' } ]); const output = testOutput.getOutput(); assert.ok(output); assert.strictEqual(output.length, 4); assert.deepEqual(output, [ 'test output 1', 'test output 2', 'test output 3', 'test output 4' ]); }); it('supports object mode', () => { testOutput = new AssertableWritableStream({ objectMode: true }); testOutput.write('test output 1'); testOutput.write('test output 2', 'utf8'); testOutput.write('test output 3', 'ascii'); testOutput.write(new Buffer('test output 4', 'utf8')); testOutput.write({ test: 'output 5' }); const rawOutput = testOutput.getRawOutput(); assert.ok(rawOutput); assert.strictEqual(rawOutput.length, 5); assert.deepEqual(rawOutput, [ { chunk: 'test output 1', encoding: 'utf8' }, { chunk: 'test output 2', encoding: 'utf8' }, { chunk: 'test output 3', encoding: 'ascii' }, { chunk: new Buffer('test output 4', 'utf8'), encoding: 'buffer' }, { chunk: { test: 'output 5' }, encoding: 'utf8' } ]); const output = testOutput.getOutput(); assert.ok(output); assert.strictEqual(output.length, 5); assert.deepEqual(output, [ 'test output 1', 'test output 2', 'test output 3', 'test output 4', {}.toString() ]); }); describe('.(start|stop)CaptureStream', () => { it('can start capture of a stream', () => { const testStream = new stream.Writable(); testOutput.startCaptureStream(testStream); testStream.write('test output 1'); testOutput.assert('test output 1'); }); it('can stop capture of a stream', () => { const testWrite = () => {}; const testStream = new stream.Writable({ write: testWrite }); testOutput.startCaptureStream(testStream); let capturedStreams = testOutput.getCapturedStreams(); assert.strictEqual(capturedStreams.length, 1); assert.notStrictEqual(testStream._write, testWrite); testStream.write('test output 1'); testOutput.assert('test output 1'); testOutput.stopCaptureStream(testStream); capturedStreams = testOutput.getCapturedStreams(); assert.strictEqual(capturedStreams.length, 0); assert.strictEqual(testStream._write, testWrite); testStream.write('test output 2'); testOutput.assert('test output 1'); assert.throws(() => { testOutput.assert('test output 2'); }, assert.AssertionError); }); it('can capture a corked stream', () => { const testWrite = () => {}; const testWritev = () => {}; const testStream = new stream.Writable({ write: testWrite, writev: testWritev }); testOutput.startCaptureStream(testStream); assert.notStrictEqual(testStream._write, testWrite); assert.notStrictEqual(testStream._writev, testWritev); testStream.cork(); testStream.write('test output 1'); testStream.write('test output 2'); let output = testOutput.getOutput(); assert.ok(output); assert.strictEqual(output.length, 0); testStream.uncork(); output = testOutput.getOutput(); assert.ok(output); assert.strictEqual(output.length, 2); assert.deepEqual(output, [ 'test output 1', 'test output 2' ]); testOutput.stopCaptureStream(testStream); assert.strictEqual(testStream._write, testWrite); assert.strictEqual(testStream._writev, testWritev); }); it('throws an error when the specified stream is not a steam', () => { // start assert.throws(() => { testOutput.startCaptureStream(); }, TypeError); assert.throws(() => { testOutput.startCaptureStream({ _write: () => {} }); }, TypeError); // stop assert.throws(() => { testOutput.stopCaptureStream({ _write: () => {} }); }, TypeError); }); it('returns early when not capturing any stream', () => { const testStream = new stream.Writable(); testOutput.stopCaptureStream(testStream); const capturedStreams = testOutput.getCapturedStreams(); assert.strictEqual(capturedStreams.length, 0); }); it('can capture from multiple streams', () => { const testWrite = () => {}; const testStream1 = new stream.Writable({ write: testWrite }); const testStream2 = new stream.Writable({ write: testWrite }); testOutput.startCaptureStream(testStream1); testOutput.startCaptureStream(testStream1); testOutput.startCaptureStream(testStream2); let capturedStreams = testOutput.getCapturedStreams(); assert.strictEqual(capturedStreams.length, 2); assert.notStrictEqual(testStream1._write, testWrite); assert.notStrictEqual(testStream2._write, testWrite); testStream1.write('test output 1'); testStream2.write('test output 1'); testOutput.assert('test output 1'); testOutput.assert('test output 1', 1); testOutput.stopCaptureStream(testStream1); testOutput.stopCaptureStream(testStream2); capturedStreams = testOutput.getCapturedStreams(); assert.strictEqual(capturedStreams.length, 0); assert.strictEqual(testStream1._write, testWrite); assert.strictEqual(testStream2._write, testWrite); testStream1.write('test output 2'); testStream2.write('test output 2'); assert.throws(() => { testOutput.assert('test output 2'); }, assert.AssertionError); }); it('can have multiple captures on a stream', () => { const testWrite = () => {}; const testStream = new stream.Writable({ write: testWrite }); const testOutput1 = new AssertableWritableStream(); const testOutput2 = new AssertableWritableStream(); testOutput1.startCaptureStream(testStream); testOutput2.startCaptureStream(testStream); let capturedStreams1 = testOutput1.getCapturedStreams(); let capturedStreams2 = testOutput2.getCapturedStreams(); assert.strictEqual(capturedStreams1.length, 1); assert.strictEqual(capturedStreams2.length, 1); assert.notStrictEqual(testStream._write, testWrite); testStream.write('test output 1'); testOutput1.assert('test output 1'); testOutput2.assert('test output 1'); testOutput1.stopCaptureStream(testStream); capturedStreams1 = testOutput1.getCapturedStreams(); capturedStreams2 = testOutput2.getCapturedStreams(); assert.strictEqual(capturedStreams1.length, 0); assert.strictEqual(capturedStreams2.length, 1); assert.notStrictEqual(testStream._write, testWrite); testStream.write('test output 2'); assert.throws(() => { testOutput1.assert('test output 2'); }, assert.AssertionError); testOutput2.assert('test output 2'); testOutput2.stopCaptureStream(testStream); capturedStreams1 = testOutput1.getCapturedStreams(); capturedStreams2 = testOutput2.getCapturedStreams(); assert.strictEqual(capturedStreams1.length, 0); assert.strictEqual(capturedStreams2.length, 0); assert.strictEqual(testStream._write, testWrite); testStream.write('test output 3'); assert.throws(() => { testOutput1.assert('test output 3'); }, assert.AssertionError); assert.throws(() => { testOutput2.assert('test output 3'); }, assert.AssertionError); }); it('can stop capturing all own captured streams', () => { const testWrite = () => {}; const testStream1 = new stream.Writable({ write: testWrite }); const testStream2 = new stream.Writable({ write: testWrite }); const testOutput1 = new AssertableWritableStream(); const testOutput2 = new AssertableWritableStream(); testOutput1.startCaptureStream(testStream1); testOutput1.startCaptureStream(testStream2); testOutput2.startCaptureStream(testStream1); testOutput2.startCaptureStream(testStream2); let capturedStreams1 = testOutput1.getCapturedStreams(); let capturedStreams2 = testOutput2.getCapturedStreams(); assert.strictEqual(capturedStreams1.length, 2); assert.strictEqual(capturedStreams2.length, 2); assert.notStrictEqual(testStream1._write, testWrite); assert.notStrictEqual(testStream2._write, testWrite); testStream1.write('test output 1'); testStream2.write('test output 1'); testOutput1.assert('test output 1'); testOutput1.assert('test output 1', 1); testOutput2.assert('test output 1'); testOutput2.assert('test output 1', 1); testOutput1.stopCaptureStream(); capturedStreams1 = testOutput1.getCapturedStreams(); capturedStreams2 = testOutput2.getCapturedStreams(); assert.strictEqual(capturedStreams1.length, 0); assert.strictEqual(capturedStreams2.length, 2); assert.notStrictEqual(testStream1._write, testWrite); assert.notStrictEqual(testStream2._write, testWrite); testStream1.write('test output 2'); testStream2.write('test output 2'); assert.throws(() => { testOutput1.assert('test output 2'); }, assert.AssertionError); testOutput2.assert('test output 2'); testOutput2.assert('test output 2', 2); testOutput2.stopCaptureStream(); capturedStreams1 = testOutput1.getCapturedStreams(); capturedStreams2 = testOutput2.getCapturedStreams(); assert.strictEqual(capturedStreams1.length, 0); assert.strictEqual(capturedStreams2.length, 0); assert.strictEqual(testStream1._write, testWrite); assert.strictEqual(testStream2._write, testWrite); testStream1.write('test output 3'); testStream2.write('test output 3'); assert.throws(() => { testOutput1.assert('test output 3'); }, assert.AssertionError); assert.throws(() => { testOutput2.assert('test output 3'); }, assert.AssertionError); }); it('handles callback correctly', function (done) { this.slow(500); const testWriteOutput = []; const testWrite = (streamIndex, chunk, _encoding, callback) => { testWriteOutput.push({ streamIndex, chunk }); // Delay second write callback if (testWriteOutput.length) { setTimeout(callback, 100); } else { callback(); } }; const testStream = new stream.Writable(); const testOutput1 = new AssertableWritableStream(); const testOutput2 = new AssertableWritableStream(); testOutput1._write = testWrite.bind(testOutput1, 1); testOutput2._write = testWrite.bind(testOutput2, 2); testOutput1.startCaptureStream(testStream); testOutput2.startCaptureStream(testStream); testStream.write('test output 1', 'utf8', () => { assert.deepEqual(testWriteOutput, [ { streamIndex: 1, chunk: new Buffer('test output 1', 'utf8') }, { streamIndex: 2, chunk: new Buffer('test output 1', 'utf8') } ]); done(); }); }); it('handles callback errors correctly', function (done) { this.slow(500); const testWriteOutput = []; const testWrite = (streamIndex, chunk, _encoding, callback) => { // Delay second write callback if (streamIndex === 2) { setTimeout(callback, 100); } else { testWriteOutput.push({ streamIndex, chunk }); callback(new Error('Write error')); } }; const testStream = new stream.Writable(); const testOutput1 = new AssertableWritableStream(); const testOutput2 = new AssertableWritableStream(); testOutput1._write = testWrite.bind(testOutput1, 1); testOutput2._write = testWrite.bind(testOutput2, 2); testOutput1.startCaptureStream(testStream); testOutput2.startCaptureStream(testStream); assert.throws(() => { testStream.write('test output 1', 'utf8', (error) => { assert(error); assert.deepEqual(testWriteOutput, [ { streamIndex: 1, chunk: new Buffer('test output 1', 'utf8') } ]); done(); }); }, /Write error/); }); it('throws error when callbacks are called multiple times', function () { const testWriteOutput = []; const testWrite = (streamIndex, chunk, _encoding, callback) => { testWriteOutput.push({ streamIndex, chunk }); // Call twice callback(); callback(); }; const testStream = new stream.Writable(); const testOutput1 = new AssertableWritableStream(); const testOutput2 = new AssertableWritableStream(); testOutput1._write = testWrite.bind(testOutput1, 1); testOutput2._write = testWrite.bind(testOutput2, 2); testOutput1.startCaptureStream(testStream); testOutput2.startCaptureStream(testStream); assert.throws(() => { testStream.write('test output 1', 'utf8', () => { // Do nothing }); }, /called multiple times/); }); it.skip('handles callback correctly in cork mode', function (done) { this.slow(500); const testWritevOutput = []; const testWritev = (streamIndex, chunks, callback) => { testWritevOutput.push({ streamIndex, chunks }); // Delay second write callback if (testWritevOutput.length) { setTimeout(callback, 100); } else { callback(); } }; const testStream = new stream.Writable({ writev: function (chunks, callback) { function writeOne () { const chunk = chunks.shift(); if (!chunk) { callback(); return; } testStream._write(chunk, writeOne); } writeOne(testStream); } }); const testOutput1 = new AssertableWritableStream(); const testOutput2 = new AssertableWritableStream(); testOutput1._writev = testWritev.bind(undefined, 1); testOutput2._writev = testWritev.bind(undefined, 2); testOutput1.startCaptureStream(testStream); testOutput2.startCaptureStream(testStream); testOutput1.cork(); testOutput2.cork(); testStream.write('test output 1', 'utf8', () => { assert.deepEqual(testWritevOutput, []); }); testOutput1.uncork(); testOutput2.uncork(); // TODO: fix uncork testOutput2.end(() => { assert.deepEqual(testWritevOutput, [ { streamIndex: 1, chunks: [ new Buffer('test output 1', 'utf8') ] }, { streamIndex: 2, chunks: [ new Buffer('test output 1', 'utf8') ] } ]); done(); }); }); }); describe('.findOutputIndex()', () => { it('can find the index of a value', () => { testOutput.write('test output'); const index = testOutput.findOutputIndex('test output'); assert.strictEqual(index, 0); }); it('can find the index of a partial value', () => { testOutput.write('test partial output'); const index = testOutput.findOutputIndex('partial'); assert.strictEqual(index, 0); }); it('can find the index of a RegExp value', () => { testOutput.write('test partial output'); testOutput.write('test RegExp output'); const index = testOutput.findOutputIndex(/test (?!partial).+ output/); assert.strictEqual(index, 1); }); it('returns -1 when the value is not found', () => { testOutput.write('test output'); const index = testOutput.findOutputIndex('non existing value'); assert.strictEqual(index, -1); }); it('returns -1 early when not output is available', () => { const index = testOutput.findOutputIndex('test output'); assert.strictEqual(index, -1); }); it('can find the index of a value while starting at a specific index', () => { [ 'test output 1a', 'test output 2a', 'test output 3a', 'test output 1b', 'test output 2b', 'test output 3b' ].forEach(testOutput.write.bind(testOutput)); const index = testOutput.findOutputIndex('test output 1', 1); assert.strictEqual(index, 2); }); it('returns -1 when value is not found while starting at a specific index', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); const index = testOutput.findOutputIndex('test output 1', 1); assert.strictEqual(index, -1); }); it('throws when startAtIndex is set to a value other then undefined, null or a number', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.findOutputIndex('test output 2', '1'); }, TypeError); }); }); describe('.outputContains()', () => { it('can check if the output contains a value', () => { testOutput.write('test output'); assert.ok(testOutput.outputContains('test output')); }); it('can check if the output contains a partial value', () => { testOutput.write('test partial output'); assert.ok(testOutput.outputContains('partial')); }); it('can check if the output contains a RegExp value', () => { testOutput.write('test partial output'); testOutput.write('test RegExp output'); assert.ok(testOutput.outputContains(/test (?!partial).+ output/)); }); it('returns -1 when the output does not contain a value', () => { testOutput.write('test output'); assert.ok(!testOutput.outputContains('non existing value')); }); it('can check if the output contains a value at the expected index', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.ok(testOutput.outputContains('test output 2', 1)); }); it('returns -1 when the output does not contain a value at the expected index', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.ok(!testOutput.outputContains('test output 3', 1)); }); it('throws when expectedIndex is set to a value other then undefined, null or a number', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.outputContains('test output 2', '1'); }, TypeError); }); it('can check if the output contains a value at the expected index while starting at a specific index', () => { [ 'test output 1a', 'test output 2a', 'test output 3a', 'test output 1b', 'test output 2b', 'test output 3b' ].forEach(testOutput.write.bind(testOutput)); assert.ok(testOutput.outputContains('test output 1', 2, 1)); }); it('returns -1 when the output does not contain a value at the expected index while starting at a specific index', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.ok(!testOutput.outputContains('test output 1', undefined, 1)); }); }); describe('.assert()', () => { it('unit test sanity check: can assert AssertionErrors', () => { assert.ok(assert.AssertionError); assert.doesNotThrow(() => { const _error = new assert.AssertionError('test assertion error'); }); assert.throws(() => { throw new assert.AssertionError('test assertion error'); }, assert.AssertionError); }); it('can assert if the output contains a value', () => { testOutput.write('test output'); testOutput.assert('test output'); }); it('fails assertion if the output does not contain a value', () => { testOutput.write('test output'); assert.throws(() => { testOutput.assert('non existing value'); }, assert.AssertionError); }); it('fails assertion with message if the output does not contain a value', () => { testOutput.write('test output'); assert.throws(() => { testOutput.assert('non existing value', undefined, undefined, 'test error message'); }, /test error message/); }); it('can assert if the output contains a value at the expected index', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); testOutput.assert('test output 2', 1); }); it('fails assertion if the output does not contain a value at the expected index', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.assert('test output 3', 1); }, assert.AssertionError); }); it('fails assertion if the output does not contain a value at the expected index and the expected index does not exist', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.assert('test output 3', 42); }, assert.AssertionError); }); it('fails assertion with message if the output does not contain a value at the expected index', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.assert('test output 3', 1, undefined, 'test error message'); }, /test error message/); }); it('fails assertion with message if the output does not contain a value at the expected index and the expected index does not exist', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.assert('test output 3', 42, undefined, 'test error message'); }, assert.AssertionError); }); it('throws when expectedIndex is set to a value other then undefined, null or a number', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.assert('test output 2', '1'); }, TypeError); }); it('can assert if the output contains a value at the expected index while starting at a specific index', () => { [ 'test output 1a', 'test output 2a', 'test output 3a', 'test output 1b', 'test output 2b', 'test output 3b' ].forEach(testOutput.write.bind(testOutput)); testOutput.assert('test output 1', 2, 1, 'unused test error message'); }); it('can assert if the output contains a value at the expected index while not starting at a specific index', () => { [ 'test output 1a', 'test output 2a', 'test output 3a', 'test output 1b', 'test output 2b', 'test output 3b' ].forEach(testOutput.write.bind(testOutput)); testOutput.assert('test output 1', 3, undefined, 'unused test error message'); }); it('fails assertion if the output does not contain a value at the expected index while starting at a specific index', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.assert('test output 1', undefined, 1); }, assert.AssertionError); }); it('fails assertion with message if the output does not contain a value at the expected index while starting at a specific index', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.assert('test output 1', undefined, 1, 'test error message'); }, /test error message/); }); it('throws if the value is not a string or RegExp', () => { [ 'test output 1', 'test output 2', 'test output 3' ].forEach(testOutput.write.bind(testOutput)); assert.throws(() => { testOutput.assert(undefined); }, /Invalid type for value./); }); }); describe('strip ansi', () => { it('disables strips ansi by default', () => { assert.strictEqual(testOutput.stripAnsi, false); }); it('can strip ansi from a string chunk', () => { testOutput = new AssertableWritableStream({ stripAnsi: true }); assert.strictEqual(testOutput.stripAnsi, true); testOutput.write('May I have some \u001b[4mcake\u001b[0m please.'); testOutput.assert('May I have some cake please.', 0); }); it('can enable strip ansi after instantiation', () => { testOutput = new AssertableWritableStream(); assert.strictEqual(testOutput.stripAnsi, false); testOutput.stripAnsi = true; testOutput.write('May I have some \u001b[4mcake\u001b[0m please.'); testOutput.assert('May I have some cake please.', 0); }); it('can disable strip ansi after instantiation', () => { testOutput = new AssertableWritableStream({ stripAnsi: true }); assert.strictEqual(testOutput.stripAnsi, true); testOutput.write('May I have some \u001b[4mcake\u001b[0m please.'); testOutput.assert('May I have some cake please.', 0); testOutput.stripAnsi = false; testOutput.write('May I have some \u001b[4mcake\u001b[0m please.'); testOutput.assert('May I have some \u001b[4mcake\u001b[0m please.', 1); }); it('does not strip ansi from a non string chunk', () => { testOutput = new AssertableWritableStream({ stripAnsi: true }); assert.strictEqual(testOutput.stripAnsi, true); testOutput.write(new Buffer('May I have some \u001b[4mcake\u001b[0m please.')); testOutput.assert('May I have some \u001b[4mcake\u001b[0m please.', 0); }); it('can strip ansi from chunks in cork mode', () => { testOutput = new AssertableWritableStream({ stripAnsi: true }); assert.strictEqual(testOutput.stripAnsi, true); testOutput.cork(); testOutput.write('May I have some \u001b[4mcake\u001b[0m please.'); testOutput.write(new Buffer('May I have some \u001b[4mcake\u001b[0m please.')); testOutput.uncork(); testOutput.assert('May I have some cake please.', 0); testOutput.assert('May I have some \u001b[4mcake\u001b[0m please.', 1); }); }); });