UNPKG

gulp-spawn

Version:
61 lines (53 loc) 1.5 kB
import Stream from 'node:stream'; import assert from 'node:assert'; import {Buffer} from 'node:buffer'; import Vinyl from 'vinyl'; import gSpawn from '../index.js'; describe('gulp-spawn', () => { describe('in buffer mode', () => { it('should work', 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: Buffer.from('plipplap'), }); const fakeFile2 = new Vinyl({ cwd: './', base: 'test', path: 'test/file2.js', contents: Buffer.from('plipplup'), }); 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 Buffer); if (++n === 1) { assert.equal(newFile.path, 'test/file.js'); assert.equal(newFile.contents.toString(), 'plipplap'); } else { assert.equal(newFile.path, 'test/file2.js'); assert.equal(newFile.contents.toString(), 'plipplup'); } } }); outputStream.on('end', () => { assert.equal(n, 2); done(); }); inputStream.write(fakeFile); inputStream.write(fakeFile2); inputStream.end(); }); }); });