Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tap15.0.1 support #2986

Merged
merged 11 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .taprc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
esm: false
ts: false
jsx: false
flow: false
veritem marked this conversation as resolved.
Show resolved Hide resolved
check-coverage: false
coverage: true
8 changes: 4 additions & 4 deletions docs/Hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,22 +434,22 @@ Note that the Fastify context in each hook is the same as the plugin where the r
```js
fastify.addHook('onRequest', async function (req, reply) {
if (req.raw.url === '/nested') {
assert.strictEqual(this.foo, 'bar')
assert.equal(this.foo, 'bar')
veritem marked this conversation as resolved.
Show resolved Hide resolved
} else {
assert.strictEqual(this.foo, undefined)
assert.equal(this.foo, undefined)
veritem marked this conversation as resolved.
Show resolved Hide resolved
}
})

fastify.get('/', async function (req, reply) {
assert.strictEqual(this.foo, undefined)
assert.equal(this.foo, undefined)
veritem marked this conversation as resolved.
Show resolved Hide resolved
return { hello: 'world' }
})

fastify.register(async function plugin (fastify, opts) {
fastify.decorate('foo', 'bar')

fastify.get('/nested', async function (req, reply) {
assert.strictEqual(this.foo, 'bar')
assert.equal(this.foo, 'bar')
veritem marked this conversation as resolved.
Show resolved Hide resolved
return { hello: 'world' }
})
})
Expand Down
42 changes: 21 additions & 21 deletions docs/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const test = async () => {
test()
```

First, our code will run inside an asynchronous function, giving us access to async/await.
First, our code will run inside an asynchronous function, giving us access to async/await.

`.inject` insures all registered plugins have booted up and our application is ready to test. Finally, we pass the request method we want to use and a route. Using await we can store the response without a callback.

Expand Down Expand Up @@ -116,7 +116,7 @@ test('requests the "/" route', async t => {
method: 'GET',
url: '/'
})
t.strictEqual(response.statusCode, 200, 'returns a status code of 200')
t.equal(response.statusCode, 200, 'returns a status code of 200')
})
```

Expand Down Expand Up @@ -191,7 +191,7 @@ function buildFastify () {
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})

return fastify
}

Expand All @@ -205,21 +205,21 @@ const buildFastify = require('./app')

tap.test('GET `/` route', t => {
t.plan(4)

const fastify = buildFastify()

// At the end of your tests it is highly recommended to call `.close()`
// to ensure that all connections to external services get closed.
t.tearDown(() => fastify.close())
t.teardown(() => fastify.close())

fastify.inject({
method: 'GET',
url: '/'
}, (err, response) => {
t.error(err)
t.strictEqual(response.statusCode, 200)
t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
t.deepEqual(response.json(), { hello: 'world' })
t.equal(response.statusCode, 200)
t.equal(response.headers['content-type'], 'application/json; charset=utf-8')
t.same(response.json(), { hello: 'world' })
})
})
```
Expand All @@ -239,22 +239,22 @@ const buildFastify = require('./app')

tap.test('GET `/` route', t => {
t.plan(5)

const fastify = buildFastify()
t.tearDown(() => fastify.close())

t.teardown(() => fastify.close())

fastify.listen(0, (err) => {
t.error(err)

request({
method: 'GET',
url: 'http://localhost:' + fastify.server.address().port
}, (err, response, body) => {
t.error(err)
t.strictEqual(response.statusCode, 200)
t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8')
t.deepEqual(JSON.parse(body), { hello: 'world' })
t.equal(response.statusCode, 200)
t.equal(response.headers['content-type'], 'application/json; charset=utf-8')
t.same(JSON.parse(body), { hello: 'world' })
})
})
})
Expand All @@ -269,15 +269,15 @@ const buildFastify = require('./app')
tap.test('GET `/` route', async (t) => {
const fastify = buildFastify()

t.tearDown(() => fastify.close())
t.teardown(() => fastify.close())

await fastify.ready()

const response = await supertest(fastify.server)
.get('/')
.expect(200)
.expect('Content-Type', 'application/json; charset=utf-8')
t.deepEqual(response.body, { hello: 'world' })
t.same(response.body, { hello: 'world' })
})
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"snazzy": "^9.0.0",
"split2": "^3.1.1",
"standard": "^16.0.1",
"tap": "^14.4.1",
"tap": "^15.0.1",
"tap-mocha-reporter": "^5.0.0",
"then-sleep": "^1.0.1",
"tsd": "^0.14.0",
Expand Down
Loading