beforeEach(done => { tailor = new Tailor({ fetchContext: mockContext, pipeDefinition: () => Buffer.from(''), fetchTemplate: (request, parseTemplate) => { const template = mockTemplate(request); if (template) { return parseTemplate(template); } else { return Promise.reject('Error fetching template'); } } }); mockContext.returns(Promise.resolve({})); server = http.createServer(tailor.requestHandler); server.listen(8080, 'localhost', done); });
_transform(chunk, encoding, done) { if (chunk instanceof Buffer) { this.queue.push(chunk); } else if (typeof this.fn !== 'function') { if (chunk.name) { this.emit( 'error', new Error('Please provide transform function') ); } } else { const st = this.fn(chunk); // Consume streams in parallel if (st instanceof stream) { st.buffer = []; const onData = data => { data = data instanceof Buffer ? data : Buffer.from(data); st.buffer.push(data); }; st.setMaxListeners(st.getMaxListeners() + 1); st.on('data', onData); st.on('error', err => this.onError(err, st)); } // Process streams in series this.queue.push(st); } this.next(); done(); }
describe('ContentLengthStream', () => { it('calculates content length and calls callback with the result', done => { const st = new ContentLengthStream(contentLength => { assert(contentLength, 'foobar'.length); done(); }); st.write(Buffer.from('foo')); st.end(Buffer.from('bar')); }); it('is a Transform stream', () => { const st = new ContentLengthStream(() => {}); assert(st instanceof Transform); }); it('passes through data chunks', done => { const chunk = Buffer.from('foo'); const st = new ContentLengthStream(() => {}); st.on('data', data => { assert.equal(data, chunk); done(); }); st.write(chunk); }); });
describe('cleanup', () => { beforeEach(() => { sandbox.stub(cp, 'execSync', cmd => { return Buffer.from(cmd.includes('--filter="name=bc_"') ? fixtures.ps.ids : fixtures.ps.allIds) }) sandbox.stub(output, 'info') it('outputs "All clean" if there are no containers to cleanup', () => { cp.execSync.restore() sandbox.stub(cp, 'execSync', () => Buffer.from('')) return utils.cleanup().then(() => { expect(output.success).to.be.calledWith('All clean')
test('MBTiles -- delete quadkey', t => { const db = new MBTiles(directories.out + 'delete.mbtiles', 'quadkey') Promise.all([ db.save('031', Buffer.from([0, 1])), db.count().then(count => t.equal(count, 1, 'save count')), db.delete('031'), db.count().then(count => t.equal(count, 0, 'delete count')) ]).then(() => { t.end() }) })