test('off() - listenerAdded', t => { const emitter = new Emittery(); const off = emitter.on(Emittery.listenerAdded, () => t.fail()); off(); emitter.emit('a'); 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.before('get dev account for testing', async t => { // Find main dev account const devAccount = await Account.findOne({nickname: devAccountUsername}) if (!devAccount) { t.fail(`dev account for test (nickname '${devAccountUsername}') not found in DB`) } Object.assign(t.context, {devAccount}) })
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('filenamePrefix uses metadata to prefix filename', t => { const transform = wrap({ transform: () => t.fail(), filenamePrefix: metadata => path.parse(metadata.filename || '').name + '-' }); makeDir.sync(transform.cacheDir); const filename = path.join(transform.cacheDir, 'source-' + hasha([PKG_HASH, 'foo'], {algorithm: 'sha256'})); fs.writeFileSync(filename, 'foo bar'); t.is(transform('foo', {filename: path.join(__dirname, 'source.js')}), 'foo bar'); });
test('createUser returns a rejected promise if creating the user failed', t => { const createUser = UserModel.create = sinon.stub(); const input = {username: 'JohnDoe123'}; const p = Mutation.createUser(null, {input}).then(() => { t.fail('Should not use success handler'); }, () => { t.pass('Should use error handler'); }); createUser.callArgWith(1, 'Error'); return p; });
test('custom encoding changes value loaded from disk', t => { const transform = wrap({ transform: () => t.fail(), encoding: 'hex' }); makeDir.sync(transform.cacheDir); fs.writeFileSync(path.join(transform.cacheDir, hasha([PKG_HASH, 'foo'], {algorithm: 'sha256'})), 'foo bar'); t.is(transform('foo'), Buffer.from('foo bar').toString('hex')); });
test("does not expect resource", async t => { const Component = () => 10; // a component that doesn't return a resource try { await t.context.context.evaluate(<Parallel tasks={[<Component />]} />); t.pass(); } catch (e) { t.fail(); } });
test('_atob error', async t => { try { _atob('abcde') } catch (e) { t.is(e.name, 'InvalidCharacterError', 'error name not match') return } t.fail('should fail') })
test('skips transform if cache file exists', t => { const transform = wrap(() => t.fail()); transform.makeDir.sync(transform.cacheDir); fs.writeFileSync(path.join(transform.cacheDir, '1dc458245419414bbdd40b53bb266691bacc8abcd21ff3440e0f4bc5a04c77d2'), 'foo bar'); t.is(transform('foo'), 'foo bar'); });
test('getPrData should return a pull request object with the repository url', t => { if (!pr.repoUrl) { return t.fail() } return t.pass() })
test("evaluate: expectResource", async t => { try { await t.context.context .extend({ expectResource: true }) .evaluate(() => 3); t.fail("expected rejection"); } catch (e) { t.pass(); } });
test('buffer encoding returns a buffer', t => { const transform = wrap({ transform: () => t.fail(), encoding: 'buffer' }); makeDir.sync(transform.cacheDir); fs.writeFileSync(path.join(transform.cacheDir, hasha([PKG_HASH, 'foo'], {algorithm: 'sha256'})), 'foo bar'); const result = transform('foo'); t.true(Buffer.isBuffer(result)); t.is(result.toString(), 'foo bar'); });
test("does not expect resource", async t => { const Component = () => 10; // a component that doesn't return a resource try { await t.context.context.evaluate(<Parallel tasks={[<Component />]} />); t.pass(); } catch (e) { t.fail(); } });
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(); } });