UNPKG

gulp-spawn

Version:
77 lines (67 loc) 1.83 kB
import Stream from 'node:stream'; import assert from 'node:assert'; import es from 'event-stream'; import Vinyl from 'vinyl'; import gSpawn from '../index.js'; describe('gulp-spawn', () => { describe('in stream mode', () => { it('should work with sync streams', done => { const stream = gSpawn({ cmd: 'cat', }); const inputStream = new Stream.PassThrough({objectMode: true}); const outputStream = new Stream.PassThrough({objectMode: true}); let n = 0; const fakeFile = new Vinyl({ cwd: './', base: 'test', path: 'test/file.js', contents: new Stream.PassThrough(), }); const fakeFile2 = new Vinyl({ cwd: './', base: 'test', path: 'test/file2.js', contents: new Stream.PassThrough(), }); inputStream.pipe(stream).pipe(outputStream); outputStream.on('readable', () => { let newFile; while ((newFile = outputStream.read())) { assert(newFile); assert.equal(newFile.cwd, './'); assert.equal(newFile.base, 'test'); assert(newFile.contents instanceof Stream); if (++n === 1) { assert.equal(newFile.path, 'test/file.js'); newFile.contents.pipe( es.wait((error, data) => { assert.equal(data, 'plipplap'); }), ); } else { assert.equal(newFile.path, 'test/file2.js'); newFile.contents.pipe( es.wait((error, data) => { assert.equal(data, 'plopplup'); }), ); } } }); outputStream.on('end', () => { assert.equal(n, 2); done(); }); stream.write(fakeFile); stream.write(fakeFile2); stream.end(); fakeFile.contents.write('plip'); fakeFile.contents.write('plap'); fakeFile.contents.end(); fakeFile2.contents.write('plop'); fakeFile2.contents.write('plup'); fakeFile2.contents.end(); }); }); });