app.get('/sub', function*() { const first = yield subThunk(); yield sleep(1000); const second = yield subThunk(); this.body = { foo: app.foo, first, second, }; });
test(`${upMethod} with body and querystring`, t => { t.plan(1) try { fastify[loMethod]('/with-query', function (req, reply) { req.body.hello = req.body.hello + req.query.foo reply.code(200).send(req.body) }) t.pass() } catch (e) { t.fail() } })
function listener(value) { app.foo = value; app.mockClient.subscribe({ id: 'foo' }, value => { if (value < app.foo) { throw new Error('subscribe error'); } setImmediate(() => { app.mockClient.unSubscribe({ id: 'foo' }) }); }); app.mockClient.unSubscribe({ id: 'foo' }, listener); fooDone(); }
lab.test('it makes a GET request with the get function', (done) => { const makeRequest = Actions.makeRequest; Actions.makeRequest = function (request) { Code.expect(request.method).to.equal('GET'); Code.expect(request.query.foo).to.equal('get'); Actions.makeRequest = makeRequest; done(); }; Actions.get('/', { foo: 'get' }, stub.Store, typeReq, typeRes); });
it('nested equalTo string with single quote', async () => { const obj = new TestObject({ nested: { foo: "single'quote" } }); await obj.save(); const query = new Parse.Query(TestObject); query.equalTo('nested.foo', "single'quote"); const result = await query.get(obj.id); equal(result.get('nested').foo, "single'quote"); });
fastify()[lowerCaseMethod]<RouteGeneric, ContextConfigType>('/', { config: { foo: 'bar', bar: 100 } }, (req, res) => { expectType<BodyInterface>(req.body) expectType<QuerystringInterface>(req.query) expectType<ParamsInterface>(req.params) expectType<http.IncomingHttpHeaders & HeadersInterface>(req.headers) expectType<string>(res.context.config.foo) expectType<number>(res.context.config.bar) })
test('adds additional levels', async ({ is }) => { const stream = sink() const logger = pino({ customLevels: { foo: 35, bar: 45 } }, stream) logger.foo('test') const { level } = await once(stream, 'data') is(level, 35) })
test("Task.constructor (plugins)", co(function * (t) { const taskr = new Taskr({ tasks: { *a(){} }, plugins: [{ name: "foo", *func(){} }] }) const task = new Task(taskr) t.true(task.hasOwnProperty("foo"), "inherits the `foo()` plugin") t.equal(typeof task.foo, "function", "mounts correctly as a function") t.end() }))
test('parse object', async () => { const transformer = new YamlTransformer() const res = transformer.parse('foo: bar') expect(res.foo).toEqual('bar') })
test('customLevels property child bindings does not get logged', async ({ is }) => { const stream = sink() const logger = pino(stream).child({ customLevels: { foo: 35 }, childMsg: 'ok' }) logger.foo('test') const { customLevels } = await once(stream, 'data') is(customLevels, undefined) })
test('custom level below level threshold will not log', async ({ is }) => { const stream = sink() const instance = pino({ customLevels: { foo: 15 } }, stream) instance.level = 'info' instance.info('bar') instance.foo('nope') const { msg } = await once(stream, 'data') is(msg, 'bar') })
it('nested containedIn string with single quote', async () => { const obj = new TestObject({ nested: { foo: ["single'quote"] } }); await obj.save(); const query = new Parse.Query(TestObject); query.containedIn('nested.foo', ["single'quote"]); const result = await query.get(obj.id); equal(result.get('nested').foo[0], "single'quote"); });
lab.test('it makes a PUT request with the put function', (done) => { const makeRequest = Actions.makeRequest; Actions.makeRequest = function (request) { Code.expect(request.method).to.equal('PUT'); Code.expect(request.data.foo).to.equal('put'); Actions.makeRequest = makeRequest; done(); }; Actions.put('/', { foo: 'put' }, stub.Store, typeReq, typeRes); });
test('parse object', async () => { const transformer = new JSONTransformer() const res = transformer.parse('{ "foo": "bar" }') expect(res.foo).toEqual('bar') })