test('write to fast-exit process', async t => { // Try-catch here is necessary, because this test is not 100% accurate // Sometimes process can manage to accept input before exiting try { await execa(`fast-exit-${process.platform}`, [], {input: 'data'}); t.pass(); } catch (error) { t.is(error.code, 'EPIPE'); } });
test('off() - listenerAdded', t => { const emitter = new Emittery(); const off = emitter.on(Emittery.listenerAdded, () => t.fail()); off(); emitter.emit('a'); t.pass(); });
test.serial('heartbeat event is fired', async t => { const stubDevice = new TuyAPI({id: '22325186db4a2217dc8e', key: '4226aa407d5c1e2b', ip: 'localhost'}); const thisStub = clone(stub); thisStub.startServer(); await new Promise((resolve, reject) => { // One heartbeat must be in 20s as each one has 10s between const toleranceTimeout = setTimeout(() => reject(), 20000); stubDevice.on('heartbeat', () => { clearTimeout(toleranceTimeout); resolve(); }); stubDevice.on('error', error => reject(error)); stubDevice.connect(); }); stubDevice.disconnect(); thisStub.shutdown(); t.pass(); });
test.serial('catch data event when property changes', async t => { const stubDevice = new TuyAPI({id: '22325186db4a2217dc8e', key: '4226aa407d5c1e2b', ip: 'localhost'}); const thisStub = clone(stub); thisStub.startServer(); await new Promise((resolve, reject) => { stubDevice.on('data', data => { t.is(data.dps['1'], thisStub.getProperty('1')); resolve(); }); stubDevice.on('connected', () => { thisStub.setProperty('1', true); }); stubDevice.on('error', error => reject(error)); stubDevice.connect(); }); stubDevice.disconnect(); thisStub.shutdown(); t.pass(); });
// TODO: check output length once big outputs are actually fixed test.serial('Big plugin output is not truncated', async t => { await runFixture(t, 'big', { snapshot: false }) t.pass() })
test("evaluate: promise", async t => { const output = await t.context.context.evaluate(Promise.resolve(10)); t.is(output, 10); try { await t.context.context.evaluate(Promise.reject()); t.fail("expected rejection"); } catch (e) { t.pass(); } });
test('printAllDaysReport with week change runs without crashing', t => { const reprotRecord = [{date: '2017-03-09', workHours: diff('2017-03-09 09:15', '2017-03-09 17:10')}, {date: '2017-03-10', workHours: diff('2017-03-10 09:15', '2017-03-10 17:10')}, {date: '2017-03-14', workHours: diff('2017-03-14 09:10', '2017-03-14 17:10')}, {date: '2017-03-15', workHours: diff('2017-03-15 09:10', '2017-03-15 17:10')}] t.pass(printAllDaysReport(reprotRecord)) })
test('should deny access to requests that do not have "x-hub-signature" header', t => { const authenticate = auth(new Request()) if (authenticate.error === 403) { return t.pass() } return t.fail() })
test('singleDayReport runs without crashing', t => { const sampleDayRecord = { id: 1, date: '2017-03-10', start: '05:15', end: '05:15', breakDuration: 30, notes: [ { id: 1, date: '2017-03-10', createdat: '06:29', note: 'hello' } ], dayReport: '0 Hours and -30 Minutes' } t.pass(printSingleDayReport(sampleDayRecord)) })
test('getPrData should return a pull request object with the repository url', t => { if (!pr.repoUrl) { return t.fail() } return t.pass() })
test('printAllDaysReport runs without crashing', t => { const reprotRecord = [{ date: '2017-03-10', workHours: diff('2017-03-10 09:15', '2017-03-10 17:10') }] t.pass(printAllDaysReport(reprotRecord)) })
test("evaluate: NaN", async t => { // regression test: NaN result should not cause infinite loop await t.context.context.evaluate(NaN); t.pass(); });
// TODO: check output length once big outputs are actually fixed test.serial('Big plugin output is not truncated', async t => { await runFixture(t, 'big', { snapshot: false }) t.pass() })
test("evaluate: promise", async t => { const output = await t.context.context.evaluate(Promise.resolve(10)); t.is(output, 10); try { await t.context.context.evaluate(Promise.reject()); t.fail("expected rejection"); } catch (e) { t.pass(); } });