test.cb('remove temporary files on cancel', t => { t.plan(1); const cp = spawn('../cli.js', ['https://sindresorhus.com', '320x240']); cp.on('exit', () => { t.false(fs.existsSync('sindresorhus.com-320x240.png')); t.end(); }); setTimeout(() => { cp.kill('SIGINT'); }, 500); });
test.cb('sanity check: child_process.exec also has killed.false if killed indirectly', t => { const {pid} = childProcess.exec('noop', error => { t.truthy(error); t.false(error.killed); t.end(); }); process.kill(pid, 'SIGINT'); });
test.cb('default', t => { // TODO: Use `execa` here when the `spawn` API is done const cp = childProcess.spawn('./cli.js', {stdio: 'inherit'}); cp.on('error', t.fail); cp.on('close', code => { t.is(code, 0); t.end(); }); });
test.cb('emitSerial()', t => { t.plan(1); const emitter = new Emittery(); const events = []; const listener = async data => { await delay(Math.random() * 100); events.push(data); if (events.length >= 5) { t.deepEqual(events, [1, 2, 3, 4, 5]); t.end(); } }; emitter.on('🦄', () => listener(1)); emitter.on('🦄', () => listener(2)); emitter.on('🦄', () => listener(3)); emitter.on('🦄', () => listener(4)); emitter.on('🦄', () => listener(5)); emitter.emitSerial('🦄', 'e'); });
test.cb('emit() - multiple events', t => { t.plan(1); const emitter = new Emittery(); let count = 0; emitter.on('🦄', async () => { await delay(Math.random() * 100); if (++count >= 5) { t.is(count, 5); t.end(); } }); emitter.emit('🦄'); emitter.emit('🦄'); emitter.emit('🦄'); emitter.emit('🦄'); emitter.emit('🦄'); });
test.cb('emit() - is async', t => { t.plan(2); const emitter = new Emittery(); let unicorn = false; emitter.on('🦄', () => { unicorn = true; t.pass(); t.end(); }); emitter.emit('🦄'); t.false(unicorn); });
test.cb('emit() - one event', t => { t.plan(1); const emitter = new Emittery(); const eventFixture = {foo: true}; emitter.on('🦄', data => { t.deepEqual(data, eventFixture); t.end(); }); emitter.emit('🦄', eventFixture); });
test.cb('should emit error when non-existent target backupPath', t => { const storage = new Storage({ backupPath: join(tmpdir(), `random-${Math.round(Math.random() * 10000)}`), appName: 'test', }); storage.reset({ random: Math.random() }); storage.on('error', err => { t.truthy(err); t.true(err.code === 'ENOENT'); t.end(); }); });
test.cb('sendMetrics should emit warn on non 200 statusCode', t => { const url = getUrl(); const metEP = nockMetrics(url, 500); const metrics = new Metrics({ url, }); metrics.on('warn', () => { t.true(metEP.isDone()); t.end(); }); metrics.count('x-y-z', true); metrics.sendMetrics(); });
test.cb('emitSerial() - is async', t => { t.plan(2); const emitter = new Emittery(); let unicorn = false; emitter.on('🦄', () => { unicorn = true; t.pass(); t.end(); }); emitter.emitSerial('🦄'); t.false(unicorn); });
test.cb('decompress to an empty buffer', function(t) { testBuffer(brotli.decompress, 'empty.compressed', 'empty', t); });
test.cb('compress text data with quality=9', function(t) { testStream(brotli.compressStream, 'data.txt', 'data.txt.compressed.09', t, { quality: 9 }); });
test.cb('decompress to a random buffer', function(t) { testStream(brotli.decompressStream, 'rand.compressed', 'rand', t); });
test.cb('main', t => { const cp = childProcess.spawn('./cli.js', {stdio: 'inherit'}); cp.on('error', t.fail); cp.on('close', code => { t.is(code, 0); t.end(); }); });
test.cb('compress a random buffer', function(t) { testStream(brotli.compressStream, 'rand', 'rand.compressed', t); });