diff --git a/.taprc b/.taprc index d278ed1fb2..dbcb8f058b 100644 --- a/.taprc +++ b/.taprc @@ -1,5 +1,5 @@ -esm: false ts: false jsx: false flow: false +check-coverage: false coverage: true diff --git a/docs/Testing.md b/docs/Testing.md index b598a10c3d..0130dd3580 100644 --- a/docs/Testing.md +++ b/docs/Testing.md @@ -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. @@ -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') }) ``` @@ -191,7 +191,7 @@ function buildFastify () { fastify.get('/', function (request, reply) { reply.send({ hello: 'world' }) }) - + return fastify } @@ -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' }) }) }) ``` @@ -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' }) }) }) }) @@ -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' }) }) ``` diff --git a/package.json b/package.json index fde7dd688c..213401c2cb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/404s.test.js b/test/404s.test.js index d2c50ec039..f3f44c3d6c 100644 --- a/test/404s.test.js +++ b/test/404s.test.js @@ -19,7 +19,7 @@ test('default 404', t => { reply.send({ hello: 'world' }) }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -33,8 +33,8 @@ test('default 404', t => { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8') + t.equal(response.statusCode, 404) + t.equal(response.headers['content-type'], 'application/json; charset=utf-8') }) }) @@ -47,8 +47,8 @@ test('default 404', t => { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8') + t.equal(response.statusCode, 404) + t.equal(response.headers['content-type'], 'application/json; charset=utf-8') }) }) }) @@ -78,7 +78,7 @@ test('customized 404', t => { reply.code(404).send('this was not found') }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -92,8 +92,8 @@ test('customized 404', t => { headers: { 'Content-Type': 'application/json' } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found') }) }) @@ -104,8 +104,8 @@ test('customized 404', t => { url: 'http://localhost:' + fastify.server.address().port + '/notSupported' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found') }) }) @@ -116,8 +116,8 @@ test('customized 404', t => { url: 'http://localhost:' + fastify.server.address().port + '/with-error' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 404) + t.same(JSON.parse(body), { error: 'Not Found', message: 'Not Found', statusCode: 404 @@ -132,9 +132,9 @@ test('customized 404', t => { url: 'http://localhost:' + fastify.server.address().port + '/with-error-custom-header' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(response.headers['x-foo'], 'bar') - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 404) + t.equal(response.headers['x-foo'], 'bar') + t.same(JSON.parse(body), { error: 'Not Found', message: 'Not Found', statusCode: 404 @@ -154,7 +154,7 @@ test('custom header in notFound handler', t => { reply.code(404).header('x-foo', 'bar').send('this was not found') }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -166,9 +166,9 @@ test('custom header in notFound handler', t => { url: 'http://localhost:' + fastify.server.address().port + '/notSupported' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(response.headers['x-foo'], 'bar') - t.strictEqual(body.toString(), 'this was not found') + t.equal(response.statusCode, 404) + t.equal(response.headers['x-foo'], 'bar') + t.equal(body.toString(), 'this was not found') }) }) }) @@ -189,7 +189,7 @@ test('setting a custom 404 handler multiple times is an error', t => { t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw') } catch (err) { t.type(err, Error) - t.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/\'') + t.equal(err.message, 'Not found handler already set for Fastify instance with prefix: \'/\'') } }) @@ -206,7 +206,7 @@ test('setting a custom 404 handler multiple times is an error', t => { t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw') } catch (err) { t.type(err, Error) - t.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/prefix\'') + t.equal(err.message, 'Not found handler already set for Fastify instance with prefix: \'/prefix\'') } done() @@ -229,7 +229,7 @@ test('setting a custom 404 handler multiple times is an error', t => { t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw') } catch (err) { t.type(err, Error) - t.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/\'') + t.equal(err.message, 'Not found handler already set for Fastify instance with prefix: \'/\'') } done() }) @@ -256,7 +256,7 @@ test('setting a custom 404 handler multiple times is an error', t => { t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw') } catch (err) { t.type(err, Error) - t.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/prefix\'') + t.equal(err.message, 'Not found handler already set for Fastify instance with prefix: \'/prefix\'') } done() }) @@ -289,7 +289,7 @@ test('setting a custom 404 handler multiple times is an error', t => { t.fail('setting multiple 404 handlers at the same prefix encapsulation level should throw') } catch (err) { t.type(err, Error) - t.strictEqual(err.message, 'Not found handler already set for Fastify instance with prefix: \'/prefix\'') + t.equal(err.message, 'Not found handler already set for Fastify instance with prefix: \'/prefix\'') } done() }) @@ -341,7 +341,7 @@ test('encapsulated 404', t => { done() }, { prefix: '/test3/' }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -355,8 +355,8 @@ test('encapsulated 404', t => { headers: { 'Content-Type': 'application/json' } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found') }) }) @@ -367,8 +367,8 @@ test('encapsulated 404', t => { url: 'http://localhost:' + fastify.server.address().port + '/notSupported' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found') }) }) @@ -381,8 +381,8 @@ test('encapsulated 404', t => { headers: { 'Content-Type': 'application/json' } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found 2') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found 2') }) }) @@ -393,8 +393,8 @@ test('encapsulated 404', t => { url: 'http://localhost:' + fastify.server.address().port + '/test/notSupported' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found 2') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found 2') }) }) @@ -407,8 +407,8 @@ test('encapsulated 404', t => { headers: { 'Content-Type': 'application/json' } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found 3') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found 3') }) }) @@ -419,8 +419,8 @@ test('encapsulated 404', t => { url: 'http://localhost:' + fastify.server.address().port + '/test2/notSupported' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found 3') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found 3') }) }) @@ -433,8 +433,8 @@ test('encapsulated 404', t => { headers: { 'Content-Type': 'application/json' } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found 4') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found 4') }) }) @@ -445,8 +445,8 @@ test('encapsulated 404', t => { url: 'http://localhost:' + fastify.server.address().port + '/test3/notSupported' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(body.toString(), 'this was not found 4') + t.equal(response.statusCode, 404) + t.equal(body.toString(), 'this was not found 4') }) }) }) @@ -460,24 +460,24 @@ test('custom 404 hook and handler context', t => { fastify.decorate('foo', 42) fastify.addHook('onRequest', function (req, res, done) { - t.strictEqual(this.foo, 42) + t.equal(this.foo, 42) done() }) fastify.addHook('preHandler', function (request, reply, done) { - t.strictEqual(this.foo, 42) + t.equal(this.foo, 42) done() }) fastify.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(this.foo, 42) + t.equal(this.foo, 42) done() }) fastify.addHook('onResponse', function (request, reply, done) { - t.strictEqual(this.foo, 42) + t.equal(this.foo, 42) done() }) fastify.setNotFoundHandler(function (req, reply) { - t.strictEqual(this.foo, 42) + t.equal(this.foo, 42) reply.code(404).send('this was not found') }) @@ -485,25 +485,25 @@ test('custom 404 hook and handler context', t => { instance.decorate('bar', 84) instance.addHook('onRequest', function (req, res, done) { - t.strictEqual(this.bar, 84) + t.equal(this.bar, 84) done() }) instance.addHook('preHandler', function (request, reply, done) { - t.strictEqual(this.bar, 84) + t.equal(this.bar, 84) done() }) instance.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(this.bar, 84) + t.equal(this.bar, 84) done() }) instance.addHook('onResponse', function (request, reply, done) { - t.strictEqual(this.bar, 84) + t.equal(this.bar, 84) done() }) instance.setNotFoundHandler(function (req, reply) { - t.strictEqual(this.foo, 42) - t.strictEqual(this.bar, 84) + t.equal(this.foo, 42) + t.equal(this.bar, 84) reply.code(404).send('encapsulated was not found') }) @@ -512,14 +512,14 @@ test('custom 404 hook and handler context', t => { fastify.inject('/not-found', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.strictEqual(res.payload, 'this was not found') + t.equal(res.statusCode, 404) + t.equal(res.payload, 'this was not found') }) fastify.inject('/encapsulated/not-found', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.strictEqual(res.payload, 'encapsulated was not found') + t.equal(res.statusCode, 404) + t.equal(res.payload, 'encapsulated was not found') }) }) @@ -534,29 +534,29 @@ test('encapsulated custom 404 without - prefix hook and handler context', t => { instance.decorate('bar', 84) instance.addHook('onRequest', function (req, res, done) { - t.strictEqual(this.foo, 42) - t.strictEqual(this.bar, 84) + t.equal(this.foo, 42) + t.equal(this.bar, 84) done() }) instance.addHook('preHandler', function (request, reply, done) { - t.strictEqual(this.foo, 42) - t.strictEqual(this.bar, 84) + t.equal(this.foo, 42) + t.equal(this.bar, 84) done() }) instance.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(this.foo, 42) - t.strictEqual(this.bar, 84) + t.equal(this.foo, 42) + t.equal(this.bar, 84) done() }) instance.addHook('onResponse', function (request, reply, done) { - t.strictEqual(this.foo, 42) - t.strictEqual(this.bar, 84) + t.equal(this.foo, 42) + t.equal(this.bar, 84) done() }) instance.setNotFoundHandler(function (request, reply) { - t.strictEqual(this.foo, 42) - t.strictEqual(this.bar, 84) + t.equal(this.foo, 42) + t.equal(this.bar, 84) reply.code(404).send('custom not found') }) @@ -565,8 +565,8 @@ test('encapsulated custom 404 without - prefix hook and handler context', t => { fastify.inject('/not-found', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.strictEqual(res.payload, 'custom not found') + t.equal(res.statusCode, 404) + t.equal(res.payload, 'custom not found') }) }) @@ -599,7 +599,7 @@ test('run hooks on default 404', t => { reply.send({ hello: 'world' }) }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -611,7 +611,7 @@ test('run hooks on default 404', t => { headers: { 'Content-Type': 'application/json' } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) }) @@ -655,7 +655,7 @@ test('run non-encapsulated plugin hooks on default 404', t => { payload: { hello: 'world' } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -702,8 +702,8 @@ test('run non-encapsulated plugin hooks on custom 404', t => { fastify.inject({ url: '/not-found' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.strictEqual(res.payload, 'this was not found') + t.equal(res.statusCode, 404) + t.equal(res.payload, 'this was not found') }) }) @@ -760,7 +760,7 @@ test('run hook with encapsulated 404', t => { done() }, { prefix: '/test' }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -772,7 +772,7 @@ test('run hook with encapsulated 404', t => { headers: { 'Content-Type': 'application/json' } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) }) @@ -787,7 +787,7 @@ test('hooks check 404', t => { }) fastify.addHook('onSend', (req, reply, payload, done) => { - t.deepEqual(req.query, { foo: 'asd' }) + t.same(req.query, { foo: 'asd' }) t.ok('called', 'onSend') done() }) @@ -800,7 +800,7 @@ test('hooks check 404', t => { done() }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -812,7 +812,7 @@ test('hooks check 404', t => { headers: { 'Content-Type': 'application/json' } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) sget({ @@ -820,7 +820,7 @@ test('hooks check 404', t => { url: 'http://localhost:' + fastify.server.address().port + '/notSupported?foo=asd' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) }) @@ -870,7 +870,7 @@ test('log debug for 404', t => { reply.send({ hello: 'world' }) }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) t.test('log debug', t => { t.plan(7) @@ -879,14 +879,14 @@ test('log debug for 404', t => { url: '/not-found' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) const INFO_LEVEL = 30 - t.strictEqual(JSON.parse(logStream.logs[0]).msg, 'incoming request') - t.strictEqual(JSON.parse(logStream.logs[1]).msg, 'Route GET:/not-found not found') - t.strictEqual(JSON.parse(logStream.logs[1]).level, INFO_LEVEL) - t.strictEqual(JSON.parse(logStream.logs[2]).msg, 'request completed') - t.strictEqual(logStream.logs.length, 3) + t.equal(JSON.parse(logStream.logs[0]).msg, 'incoming request') + t.equal(JSON.parse(logStream.logs[1]).msg, 'Route GET:/not-found not found') + t.equal(JSON.parse(logStream.logs[1]).level, INFO_LEVEL) + t.equal(JSON.parse(logStream.logs[2]).msg, 'request completed') + t.equal(logStream.logs.length, 3) }) }) }) @@ -900,7 +900,7 @@ test('Unknown method', t => { reply.send({ hello: 'world' }) }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -917,8 +917,8 @@ test('Unknown method', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.strictDeepEqual(JSON.parse(body), { + t.equal(response.statusCode, 400) + t.strictSame(JSON.parse(body), { error: 'Bad Request', message: 'Client Error', statusCode: 400 @@ -936,7 +936,7 @@ test('recognizes errors from the http-errors module', t => { reply.send(httpErrors.NotFound()) }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -946,12 +946,12 @@ test('recognizes errors from the http-errors module', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) sget('http://localhost:' + fastify.server.address().port, (err, response, body) => { t.error(err) const obj = JSON.parse(body.toString()) - t.strictDeepEqual(obj, { + t.strictSame(obj, { error: 'Not Found', message: 'Not Found', statusCode: 404 @@ -976,8 +976,8 @@ test('the default 404 handler can be invoked inside a prefixed plugin', t => { fastify.inject('/v1/path', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.strictDeepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 404) + t.strictSame(JSON.parse(res.payload), { error: 'Not Found', message: 'Not Found', statusCode: 404 @@ -1004,8 +1004,8 @@ test('an inherited custom 404 handler can be invoked inside a prefixed plugin', fastify.inject('/v1/path', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 404) + t.same(JSON.parse(res.payload), { error: 'Not Found', message: 'Not Found', statusCode: 404 @@ -1039,14 +1039,14 @@ test('encapsulated custom 404 handler without a prefix is the handler for the en fastify.inject('/not-found', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.strictEqual(res.payload, 'custom handler') + t.equal(res.statusCode, 404) + t.equal(res.payload, 'custom handler') }) fastify.inject('/prefixed/not-found', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.strictEqual(res.payload, 'custom handler 2') + t.equal(res.statusCode, 404) + t.equal(res.payload, 'custom handler 2') }) }) @@ -1054,7 +1054,7 @@ test('cannot set notFoundHandler after binding', t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -1088,7 +1088,7 @@ test('404 inside onSend', t => { } }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -1098,7 +1098,7 @@ test('404 inside onSend', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) }) @@ -1112,7 +1112,7 @@ test('Not found on supported method (should return a 404)', t => { reply.send({ hello: 'world' }) }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -1122,14 +1122,14 @@ test('Not found on supported method (should return a 404)', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) sget({ method: 'POST', url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) }) @@ -1145,7 +1145,7 @@ test('Not found on unsupported method (should return a 404)', t => { reply.send({ hello: 'world' }) }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) @@ -1155,14 +1155,14 @@ test('Not found on unsupported method (should return a 404)', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) sget({ method: 'PROPFIND', url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) }) @@ -1188,7 +1188,7 @@ test('onSend hooks run when an encapsulated route invokes the notFound handler', fastify.inject('/', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -1216,7 +1216,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { preHandler: true, hello: 'world' }) + t.same(payload, { preHandler: true, hello: 'world' }) }) }) @@ -1245,7 +1245,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { preHandler: true, hello: 'world' }) + t.same(payload, { preHandler: true, hello: 'world' }) }) }) @@ -1279,7 +1279,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { preHandler1: true, preHandler2: true, hello: 'world' }) + t.same(payload, { preHandler1: true, preHandler2: true, hello: 'world' }) }) }) @@ -1308,7 +1308,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { check: 'ab', hello: 'world' }) + t.same(payload, { check: 'ab', hello: 'world' }) }) }) @@ -1340,7 +1340,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'earth' }) + t.same(payload, { hello: 'earth' }) }) fastify.inject({ @@ -1350,7 +1350,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -1374,7 +1374,7 @@ test('preHandler option for setNotFoundHandler', t => { t.error(err) const payload = JSON.parse(res.payload) t.equal(res.statusCode, 500) - t.deepEqual(payload, { + t.same(payload, { message: 'kaboom', error: 'Internal Server Error', statusCode: 500 @@ -1403,7 +1403,7 @@ test('preHandler option for setNotFoundHandler', t => { t.error(err) const payload = JSON.parse(res.payload) t.equal(res.statusCode, 401) - t.deepEqual(payload, { + t.same(payload, { message: 'go away', error: 'Unauthorized', statusCode: 401 @@ -1437,7 +1437,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { preHandler: 'ab', hello: 'world' }) + t.same(payload, { preHandler: 'ab', hello: 'world' }) }) }) @@ -1474,7 +1474,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { check: 'ab', hello: 'world' }) + t.same(payload, { check: 'ab', hello: 'world' }) }) fastify.inject({ @@ -1484,7 +1484,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { check: 'a', hello: 'world' }) + t.same(payload, { check: 'a', hello: 'world' }) }) }) @@ -1496,7 +1496,7 @@ test('preHandler option for setNotFoundHandler', t => { fastify.setNotFoundHandler({ preHandler: function (req, reply, done) { - t.strictEqual(this.foo, 42) + t.equal(this.foo, 42) this.foo += 1 req.body.foo = this.foo done() @@ -1512,7 +1512,7 @@ test('preHandler option for setNotFoundHandler', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { foo: 43, hello: 'world' }) + t.same(payload, { foo: 43, hello: 'world' }) }) }) }) @@ -1535,8 +1535,8 @@ test('reply.notFound invoked the notFound handler', t => { method: 'GET' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 404) + t.same(JSON.parse(res.payload), { error: 'Not Found', message: 'kaboom', statusCode: 404 @@ -1551,13 +1551,13 @@ test('The custom error handler should be invoked after the custom not found hand const order = [1, 2] fastify.setErrorHandler((err, req, reply) => { - t.is(order.shift(), 2) + t.equal(order.shift(), 2) t.type(err, Error) reply.send(err) }) fastify.setNotFoundHandler((req, reply) => { - t.is(order.shift(), 1) + t.equal(order.shift(), 1) reply.code(404).send(new Error('kaboom')) }) @@ -1570,8 +1570,8 @@ test('The custom error handler should be invoked after the custom not found hand method: 'GET' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 404) + t.same(JSON.parse(res.payload), { error: 'Not Found', message: 'kaboom', statusCode: 404 @@ -1601,8 +1601,8 @@ test('If the custom not found handler does not use an Error, the custom error ha method: 'GET' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) - t.strictEqual(res.payload, 'kaboom') + t.equal(res.statusCode, 404) + t.equal(res.payload, 'kaboom') }) }) @@ -1614,7 +1614,7 @@ test('preValidation option', t => { fastify.setNotFoundHandler({ preValidation: function (req, reply, done) { - t.true(this.foo) + t.ok(this.foo) done() } }, function (req, reply) { @@ -1628,7 +1628,7 @@ test('preValidation option', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -1658,7 +1658,7 @@ t.test('preValidation option could accept an array of functions', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -1687,8 +1687,8 @@ test('Should fail to invoke callNotFound inside a 404 handler', t => { }) logStream.once('data', line => { - t.is(line.msg, 'Trying to send a NotFound error inside a 404 handler. Sending basic 404 response.') - t.is(line.level, 40) + t.equal(line.msg, 'Trying to send a NotFound error inside a 404 handler. Sending basic 404 response.') + t.equal(line.level, 40) }) fastify.inject({ @@ -1696,8 +1696,8 @@ test('Should fail to invoke callNotFound inside a 404 handler', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 404) - t.is(res.payload, '404 Not Found') + t.equal(res.statusCode, 404) + t.equal(res.payload, '404 Not Found') }) }) @@ -1711,8 +1711,8 @@ test('400 in case of bad url (pre find-my-way v2.2.0 was a 404)', t => { method: 'GET' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(JSON.parse(response.payload), { + t.equal(response.statusCode, 400) + t.same(JSON.parse(response.payload), { error: 'Bad Request', message: "'%world' is not a valid url component", statusCode: 400 @@ -1729,8 +1729,8 @@ test('400 in case of bad url (pre find-my-way v2.2.0 was a 404)', t => { method: 'GET' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(JSON.parse(response.payload), { + t.equal(response.statusCode, 400) + t.same(JSON.parse(response.payload), { error: 'Bad Request', message: "'/hello/%world' is not a valid url component", statusCode: 400 @@ -1756,8 +1756,8 @@ test('setNotFoundHandler should be chaining fastify instance', t => { method: 'GET' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(response.payload, 'this was not found') + t.equal(response.statusCode, 404) + t.equal(response.payload, 'this was not found') }) fastify.inject({ @@ -1765,8 +1765,8 @@ test('setNotFoundHandler should be chaining fastify instance', t => { method: 'GET' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.payload, 'valid route') + t.equal(response.statusCode, 200) + t.equal(response.payload, 'valid route') }) }) diff --git a/test/500s.test.js b/test/500s.test.js index 8df69c27d1..fee974adad 100644 --- a/test/500s.test.js +++ b/test/500s.test.js @@ -19,9 +19,9 @@ test('default 500', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 500) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(res.payload), { error: 'Internal Server Error', message: 'kaboom', statusCode: 500 @@ -52,9 +52,9 @@ test('custom 500', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) - t.strictEqual(res.headers['content-type'], 'text/plain') - t.deepEqual(res.payload.toString(), 'an error happened: kaboom') + t.equal(res.statusCode, 500) + t.equal(res.headers['content-type'], 'text/plain') + t.same(res.payload.toString(), 'an error happened: kaboom') }) }) @@ -89,9 +89,9 @@ test('encapsulated 500', t => { url: '/test' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) - t.strictEqual(res.headers['content-type'], 'text/plain') - t.deepEqual(res.payload.toString(), 'an error happened: kaboom') + t.equal(res.statusCode, 500) + t.equal(res.headers['content-type'], 'text/plain') + t.same(res.payload.toString(), 'an error happened: kaboom') }) fastify.inject({ @@ -99,9 +99,9 @@ test('encapsulated 500', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 500) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(res.payload), { error: 'Internal Server Error', message: 'kaboom', statusCode: 500 @@ -143,9 +143,9 @@ test('custom 500 with hooks', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) - t.strictEqual(res.headers['content-type'], 'text/plain') - t.deepEqual(res.payload.toString(), 'an error happened: kaboom') + t.equal(res.statusCode, 500) + t.equal(res.headers['content-type'], 'text/plain') + t.same(res.payload.toString(), 'an error happened: kaboom') }) }) @@ -153,7 +153,7 @@ test('cannot set errorHandler after binding', t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) diff --git a/test/async-await.test.js b/test/async-await.test.js index 39c4f31121..edf74c7f54 100644 --- a/test/async-await.test.js +++ b/test/async-await.test.js @@ -55,9 +55,9 @@ test('async await', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -65,9 +65,9 @@ test('async await', t => { url: 'http://localhost:' + fastify.server.address().port + '/no-await' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -82,7 +82,7 @@ test('ignore the result of the promise if reply.send is called beforehand (undef reply.send(payload) }) - t.tearDown(server.close.bind(server)) + t.teardown(server.close.bind(server)) server.listen(0, (err) => { t.error(err) @@ -91,8 +91,8 @@ test('ignore the result of the promise if reply.send is called beforehand (undef url: 'http://localhost:' + server.server.address().port + '/' }, (err, res, body) => { t.error(err) - t.deepEqual(payload, JSON.parse(body)) - t.strictEqual(res.statusCode, 200) + t.same(payload, JSON.parse(body)) + t.equal(res.statusCode, 200) }) }) }) @@ -108,7 +108,7 @@ test('ignore the result of the promise if reply.send is called beforehand (objec return { hello: 'world' } }) - t.tearDown(server.close.bind(server)) + t.teardown(server.close.bind(server)) server.listen(0, (err) => { t.error(err) @@ -117,8 +117,8 @@ test('ignore the result of the promise if reply.send is called beforehand (objec url: 'http://localhost:' + server.server.address().port + '/' }, (err, res, body) => { t.error(err) - t.deepEqual(payload, JSON.parse(body)) - t.strictEqual(res.statusCode, 200) + t.same(payload, JSON.parse(body)) + t.equal(res.statusCode, 200) }) }) }) @@ -129,7 +129,7 @@ test('server logs an error if reply.send is called and a value is returned via a const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, lines.shift()) + t.equal(line.msg, lines.shift()) }) const logger = pino(splitStream) @@ -149,7 +149,7 @@ test('server logs an error if reply.send is called and a value is returned via a }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -163,7 +163,7 @@ test('ignore the result of the promise if reply.send is called beforehand (undef reply.send(payload) }) - t.tearDown(server.close.bind(server)) + t.teardown(server.close.bind(server)) server.listen(0, (err) => { t.error(err) @@ -172,8 +172,8 @@ test('ignore the result of the promise if reply.send is called beforehand (undef url: 'http://localhost:' + server.server.address().port + '/' }, (err, res, body) => { t.error(err) - t.deepEqual(payload, JSON.parse(body)) - t.strictEqual(res.statusCode, 200) + t.same(payload, JSON.parse(body)) + t.equal(res.statusCode, 200) }) }) }) @@ -189,7 +189,7 @@ test('ignore the result of the promise if reply.send is called beforehand (objec return { hello: 'world' } }) - t.tearDown(server.close.bind(server)) + t.teardown(server.close.bind(server)) server.listen(0, (err) => { t.error(err) @@ -198,8 +198,8 @@ test('ignore the result of the promise if reply.send is called beforehand (objec url: 'http://localhost:' + server.server.address().port + '/' }, (err, res, body) => { t.error(err) - t.deepEqual(payload, JSON.parse(body)) - t.strictEqual(res.statusCode, 200) + t.same(payload, JSON.parse(body)) + t.equal(res.statusCode, 200) }) }) }) @@ -210,7 +210,7 @@ test('await reply if we will be calling reply.send in the future', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, lines.shift()) + t.equal(line.msg, lines.shift()) }) const server = Fastify({ @@ -234,7 +234,7 @@ test('await reply if we will be calling reply.send in the future', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -244,7 +244,7 @@ test('await reply if we will be calling reply.send in the future (error case)', const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, lines.shift()) + t.equal(line.msg, lines.shift()) }) const server = Fastify({ @@ -292,7 +292,7 @@ test('support reply decorators with await', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -325,13 +325,13 @@ test('inject async await', async t => { try { const res = await fastify.inject({ method: 'GET', url: '/' }) - t.deepEqual({ hello: 'world' }, JSON.parse(res.payload)) + t.same({ hello: 'world' }, JSON.parse(res.payload)) } catch (err) { t.fail(err) } }) -test('inject async await - when the server is up', async t => { +test('inject async await - when the server equal up', async t => { t.plan(2) const fastify = Fastify() @@ -342,7 +342,7 @@ test('inject async await - when the server is up', async t => { try { const res = await fastify.inject({ method: 'GET', url: '/' }) - t.deepEqual({ hello: 'world' }, JSON.parse(res.payload)) + t.same({ hello: 'world' }, JSON.parse(res.payload)) } catch (err) { t.fail(err) } @@ -351,7 +351,7 @@ test('inject async await - when the server is up', async t => { try { const res2 = await fastify.inject({ method: 'GET', url: '/' }) - t.deepEqual({ hello: 'world' }, JSON.parse(res2.payload)) + t.same({ hello: 'world' }, JSON.parse(res2.payload)) } catch (err) { t.fail(err) } @@ -372,13 +372,13 @@ test('async await plugin', async t => { try { const res = await fastify.inject({ method: 'GET', url: '/' }) - t.deepEqual({ hello: 'world' }, JSON.parse(res.payload)) + t.same({ hello: 'world' }, JSON.parse(res.payload)) } catch (err) { t.fail(err) } }) -test('does not call reply.send() twice if 204 response is already sent', t => { +test('does not call reply.send() twice if 204 response equal already sent', t => { t.plan(2) const fastify = Fastify() @@ -415,14 +415,14 @@ test('error is logged because promise was fulfilled with undefined', t => { t.fail() } - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.get('/', async (req, reply) => { reply.code(200) }) stream.once('data', line => { - t.strictEqual(line.msg, 'Promise may not be fulfilled with \'undefined\' when statusCode is not 204') + t.equal(line.msg, 'Promise may not be fulfilled with \'undefined\' when statusCode is not 204') }) fastify.listen(0, (err) => { @@ -434,7 +434,7 @@ test('error is logged because promise was fulfilled with undefined', t => { url: 'http://localhost:' + fastify.server.address().port + '/', timeout: 500 }, (err, res, body) => { - t.is(err.message, 'Request timed out') + t.equal(err.message, 'Request timed out') }) }) }) @@ -455,7 +455,7 @@ test('error is not logged because promise was fulfilled with undefined but statu t.fail() } - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.get('/', async (req, reply) => { reply.code(204) @@ -474,7 +474,7 @@ test('error is not logged because promise was fulfilled with undefined but statu url: 'http://localhost:' + fastify.server.address().port + '/' }, (err, res, body) => { t.error(err) - t.strictEqual(res.statusCode, 204) + t.equal(res.statusCode, 204) }) }) }) @@ -496,7 +496,7 @@ test('error is not logged because promise was fulfilled with undefined but respo t.fail() } - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.get('/', async (req, reply) => { reply.send(payload) @@ -515,8 +515,8 @@ test('error is not logged because promise was fulfilled with undefined but respo url: 'http://localhost:' + fastify.server.address().port + '/' }, (err, res, body) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual( + t.equal(res.statusCode, 200) + t.same( payload, JSON.parse(body) ) @@ -541,8 +541,8 @@ test('Thrown Error instance sets HTTP status code', t => { url: '/' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 418) - t.deepEqual( + t.equal(res.statusCode, 418) + t.same( { error: statusCodes['418'], message: err.message, @@ -565,7 +565,7 @@ test('customErrorHandler support', t => { }) fastify.setErrorHandler(async err => { - t.is(err.message, 'ouch') + t.equal(err.message, 'ouch') const error = new Error('kaboom') error.statusCode = 401 throw error @@ -576,8 +576,8 @@ test('customErrorHandler support', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 401) - t.deepEqual( + t.equal(res.statusCode, 401) + t.same( { error: statusCodes['401'], message: 'kaboom', @@ -600,7 +600,7 @@ test('customErrorHandler support without throwing', t => { }) fastify.setErrorHandler(async (err, req, reply) => { - t.is(err.message, 'ouch') + t.equal(err.message, 'ouch') reply.code(401).send('kaboom') reply.send = t.fail.bind(t, 'should not be called') }) @@ -610,8 +610,8 @@ test('customErrorHandler support without throwing', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 401) - t.deepEqual( + t.equal(res.statusCode, 401) + t.same( 'kaboom', res.payload ) @@ -638,8 +638,8 @@ test('customErrorHandler only called if reply not already sent', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual( + t.equal(res.statusCode, 200) + t.same( 'success', res.payload ) @@ -648,5 +648,5 @@ test('customErrorHandler only called if reply not already sent', t => { test('await self', async t => { const app = Fastify() - t.is(await app, app) + t.equal(await app, app) }) diff --git a/test/bodyLimit.test.js b/test/bodyLimit.test.js index a6fbaeaf2f..81b265ea3e 100644 --- a/test/bodyLimit.test.js +++ b/test/bodyLimit.test.js @@ -40,7 +40,7 @@ test('bodyLimit', t => { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 413) + t.equal(response.statusCode, 413) }) }) }) diff --git a/test/case-insensitive.test.js b/test/case-insensitive.test.js index c5623e80a2..97dc7270cd 100644 --- a/test/case-insensitive.test.js +++ b/test/case-insensitive.test.js @@ -11,7 +11,7 @@ test('case insensitive', t => { const fastify = Fastify({ caseSensitive: false }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.get('/foo', (req, reply) => { reply.send({ hello: 'world' }) @@ -25,8 +25,8 @@ test('case insensitive', t => { url: 'http://localhost:' + fastify.server.address().port + '/FOO' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) @@ -39,7 +39,7 @@ test('case insensitive inject', t => { const fastify = Fastify({ caseSensitive: false }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.get('/foo', (req, reply) => { reply.send({ hello: 'world' }) @@ -53,8 +53,8 @@ test('case insensitive inject', t => { url: 'http://localhost:' + fastify.server.address().port + '/FOO' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(response.payload), { + t.equal(response.statusCode, 200) + t.same(JSON.parse(response.payload), { hello: 'world' }) }) @@ -67,10 +67,10 @@ test('case insensitive (parametric)', t => { const fastify = Fastify({ caseSensitive: false }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.get('/foo/:param', (req, reply) => { - t.strictEqual(req.params.param, 'bAr') + t.equal(req.params.param, 'bAr') reply.send({ hello: 'world' }) }) @@ -82,8 +82,8 @@ test('case insensitive (parametric)', t => { url: 'http://localhost:' + fastify.server.address().port + '/FoO/bAr' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) @@ -96,10 +96,10 @@ test('case insensitive (wildcard)', t => { const fastify = Fastify({ caseSensitive: false }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.get('/foo/*', (req, reply) => { - t.strictEqual(req.params['*'], 'bAr/baZ') + t.equal(req.params['*'], 'bAr/baZ') reply.send({ hello: 'world' }) }) @@ -111,8 +111,8 @@ test('case insensitive (wildcard)', t => { url: 'http://localhost:' + fastify.server.address().port + '/FoO/bAr/baZ' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) diff --git a/test/close-pipelining.test.js b/test/close-pipelining.test.js index a9193367d6..1567d73c0e 100644 --- a/test/close-pipelining.test.js +++ b/test/close-pipelining.test.js @@ -27,7 +27,7 @@ test('Should return 503 while closing - pipelining', t => { instance.request( { path: '/', method: 'GET' } ).then(data => { - t.strictEqual(data.statusCode, code) + t.equal(data.statusCode, code) }).catch((e) => { t.fail(e) }) @@ -60,7 +60,7 @@ test('Should not return 503 while closing - pipelining - return503OnClosing', t instance.request( { path: '/', method: 'GET' } ).then(data => { - t.strictEqual(data.statusCode, code) + t.equal(data.statusCode, code) }).catch((e) => { t.fail(e) }) diff --git a/test/close.test.js b/test/close.test.js index a4ac934fdb..6b1bc34430 100644 --- a/test/close.test.js +++ b/test/close.test.js @@ -31,7 +31,7 @@ test('inside register', t => { f.addHook('onClose', onClose) function onClose (instance, done) { t.ok(instance.prototype === fastify.prototype) - t.strictEqual(instance, f) + t.equal(instance, f) done() } @@ -55,7 +55,7 @@ test('close order', t => { fastify.register(function (f, opts, done) { f.addHook('onClose', (instance, done) => { - t.is(order.shift(), 1) + t.equal(order.shift(), 1) done() }) @@ -63,7 +63,7 @@ test('close order', t => { }) fastify.addHook('onClose', (instance, done) => { - t.is(order.shift(), 2) + t.equal(order.shift(), 2) done() }) @@ -72,7 +72,7 @@ test('close order', t => { fastify.close((err) => { t.error(err) - t.is(order.shift(), 3) + t.equal(order.shift(), 3) }) }) }) @@ -84,20 +84,20 @@ test('close order - async', async t => { fastify.register(function (f, opts, done) { f.addHook('onClose', async instance => { - t.is(order.shift(), 1) + t.equal(order.shift(), 1) }) done() }) fastify.addHook('onClose', () => { - t.is(order.shift(), 2) + t.equal(order.shift(), 2) }) await fastify.listen(0) await fastify.close() - t.is(order.shift(), 3) + t.equal(order.shift(), 3) }) test('should not throw an error if the server is not listening', t => { @@ -126,7 +126,7 @@ test('onClose should keep the context', t => { function onClose (i, done) { t.ok(i.test) - t.strictEqual(i, instance) + t.equal(i, instance) done() } @@ -153,7 +153,7 @@ test('Should return error while closing (promise) - injection', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) fastify.close() process.nextTick(() => { @@ -185,7 +185,7 @@ test('Should return error while closing (callback) - injection', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) fastify.close() setTimeout(() => { @@ -274,7 +274,7 @@ test('Cannot be reopened the closed server without listen callback', async t => await fastify.listen(0) } catch (err) { t.ok(err) - t.is(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER') + t.equal(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER') } }) @@ -290,7 +290,7 @@ test('Cannot be reopened the closed server has listen callback', async t => { reject(err) }) }).catch(err => { - t.is(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER') + t.equal(err.code, 'FST_ERR_REOPENED_CLOSE_SERVER') t.ok(err) }) }) diff --git a/test/constrained-routes.test.js b/test/constrained-routes.test.js index 3a8a6aeca3..9f2ae88eab 100644 --- a/test/constrained-routes.test.js +++ b/test/constrained-routes.test.js @@ -25,8 +25,8 @@ test('Should register a host constrained route', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -37,7 +37,7 @@ test('Should register a host constrained route', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) fastify.inject({ @@ -45,7 +45,7 @@ test('Should register a host constrained route', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -79,8 +79,8 @@ test('Should register the same route with host constraints', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.payload, 'fastify.io') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'fastify.io') }) fastify.inject({ @@ -91,8 +91,8 @@ test('Should register the same route with host constraints', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.payload, 'example.com') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'example.com') }) fastify.inject({ @@ -103,7 +103,7 @@ test('Should register the same route with host constraints', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -155,8 +155,8 @@ test('Should allow registering custom constrained routes', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'from alpha' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'from alpha' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -167,8 +167,8 @@ test('Should allow registering custom constrained routes', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'from beta' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'from beta' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -179,6 +179,6 @@ test('Should allow registering custom constrained routes', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) diff --git a/test/content-length.test.js b/test/content-length.test.js index 4fce950fcc..c59293495d 100644 --- a/test/content-length.test.js +++ b/test/content-length.test.js @@ -23,9 +23,9 @@ test('default 413 with bodyLimit option', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 413) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 413) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(res.payload), { error: 'Payload Too Large', code: 'FST_ERR_CTP_BODY_TOO_LARGE', message: 'Request body is too large', @@ -54,9 +54,9 @@ test('default 400 with wrong content-length', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 400) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(res.payload), { error: 'Bad Request', code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH', message: 'Request body size did not match Content-Length', @@ -91,9 +91,9 @@ test('custom 413 with bodyLimit option', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 413) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 413) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(res.payload), { error: 'Payload Too Large', code: 'FST_ERR_CTP_BODY_TOO_LARGE', message: 'Request body is too large', @@ -129,9 +129,9 @@ test('custom 400 with wrong content-length', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 400) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(res.payload), { error: 'Bad Request', code: 'FST_ERR_CTP_INVALID_CONTENT_LENGTH', message: 'Request body size did not match Content-Length', @@ -156,7 +156,7 @@ test('#2214 - wrong content-length', t => { path: '/' }) .then(response => { - t.strictEqual(response.headers['content-length'], '' + response.rawPayload.length) + t.equal(response.headers['content-length'], '' + response.rawPayload.length) t.end() }) }) @@ -181,9 +181,9 @@ test('#2543 - wrong content-length with errorHandler', t => { path: '/' }) .then(res => { - t.strictEqual(res.statusCode, 500) - t.strictEqual(res.headers['content-length'], '' + res.rawPayload.length) - t.deepEqual(JSON.parse(res.payload), { message: 'longer than 2 bytes' }) + t.equal(res.statusCode, 500) + t.equal(res.headers['content-length'], '' + res.rawPayload.length) + t.same(JSON.parse(res.payload), { message: 'longer than 2 bytes' }) t.end() }) }) diff --git a/test/content-parser.test.js b/test/content-parser.test.js index 76dee9767e..93c4095994 100644 --- a/test/content-parser.test.js +++ b/test/content-parser.test.js @@ -53,9 +53,9 @@ test('getParser', t => { fastify.addContentTypeParser(/^application\/.+\+xml/, second) fastify.addContentTypeParser('text/html', third) - t.strictEqual(fastify[keys.kContentTypeParser].getParser('application/t+xml').fn, second) - t.strictEqual(fastify[keys.kContentTypeParser].getParser('image/png').fn, first) - t.strictEqual(fastify[keys.kContentTypeParser].getParser('text/html').fn, third) + t.equal(fastify[keys.kContentTypeParser].getParser('application/t+xml').fn, second) + t.equal(fastify[keys.kContentTypeParser].getParser('image/png').fn, first) + t.equal(fastify[keys.kContentTypeParser].getParser('text/html').fn, third) }) test('should prefer content type parser with string value', t => { @@ -66,8 +66,8 @@ test('getParser', t => { fastify.addContentTypeParser(/^image\/.*/, first) fastify.addContentTypeParser('image/gif', second) - t.strictEqual(fastify[keys.kContentTypeParser].getParser('image/gif').fn, second) - t.strictEqual(fastify[keys.kContentTypeParser].getParser('image/png').fn, first) + t.equal(fastify[keys.kContentTypeParser].getParser('image/gif').fn, second) + t.equal(fastify[keys.kContentTypeParser].getParser('image/png').fn, first) }) test('should return parser that catches all if no other is set', t => { @@ -78,9 +78,9 @@ test('getParser', t => { fastify.addContentTypeParser('*', first) fastify.addContentTypeParser(/^text\/.*/, second) - t.strictEqual(fastify[keys.kContentTypeParser].getParser('image/gif').fn, first) - t.strictEqual(fastify[keys.kContentTypeParser].getParser('text/html').fn, second) - t.strictEqual(fastify[keys.kContentTypeParser].getParser('text').fn, first) + t.equal(fastify[keys.kContentTypeParser].getParser('image/gif').fn, first) + t.equal(fastify[keys.kContentTypeParser].getParser('text/html').fn, second) + t.equal(fastify[keys.kContentTypeParser].getParser('text').fn, first) }) test('should return undefined if no matching parser exist', t => { @@ -181,7 +181,7 @@ test('add', t => { const contentTypeParser = fastify[keys.kContentTypeParser] contentTypeParser.add('*', {}, first) - t.strictEqual(contentTypeParser.customParsers[''].fn, first) + t.equal(contentTypeParser.customParsers[''].fn, first) }) t.end() diff --git a/test/context-config.test.js b/test/context-config.test.js index a49fa4cb0b..eda0e22f08 100644 --- a/test/context-config.test.js +++ b/test/context-config.test.js @@ -45,8 +45,8 @@ test('config', t => { url: '/get' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEquals(JSON.parse(response.payload), Object.assign({ url: '/get', method: 'GET' }, schema.config)) + t.equal(response.statusCode, 200) + t.same(JSON.parse(response.payload), Object.assign({ url: '/get', method: 'GET' }, schema.config)) }) fastify.inject({ @@ -54,8 +54,8 @@ test('config', t => { url: '/route' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEquals(JSON.parse(response.payload), Object.assign({ url: '/route', method: 'GET' }, schema.config)) + t.equal(response.statusCode, 200) + t.same(JSON.parse(response.payload), Object.assign({ url: '/route', method: 'GET' }, schema.config)) }) fastify.inject({ @@ -63,8 +63,8 @@ test('config', t => { url: '/no-config' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEquals(JSON.parse(response.payload), { url: '/no-config', method: 'GET' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(response.payload), { url: '/no-config', method: 'GET' }) }) }) @@ -97,8 +97,8 @@ test('config with exposeHeadRoutes', t => { url: '/get' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEquals(JSON.parse(response.payload), Object.assign({ url: '/get', method: 'GET' }, schema.config)) + t.equal(response.statusCode, 200) + t.same(JSON.parse(response.payload), Object.assign({ url: '/get', method: 'GET' }, schema.config)) }) fastify.inject({ @@ -106,8 +106,8 @@ test('config with exposeHeadRoutes', t => { url: '/route' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEquals(JSON.parse(response.payload), Object.assign({ url: '/route', method: 'GET' }, schema.config)) + t.equal(response.statusCode, 200) + t.same(JSON.parse(response.payload), Object.assign({ url: '/route', method: 'GET' }, schema.config)) }) fastify.inject({ @@ -115,7 +115,7 @@ test('config with exposeHeadRoutes', t => { url: '/no-config' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEquals(JSON.parse(response.payload), { url: '/no-config', method: 'GET' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(response.payload), { url: '/no-config', method: 'GET' }) }) }) diff --git a/test/custom-http-server.test.js b/test/custom-http-server.test.js index d41c8f7c16..a22260c9ea 100644 --- a/test/custom-http-server.test.js +++ b/test/custom-http-server.test.js @@ -37,8 +37,8 @@ test('Should support a custom http server', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) diff --git a/test/custom-parser-async.test.js b/test/custom-parser-async.test.js index 503a26a52d..1d4cf1327d 100644 --- a/test/custom-parser-async.test.js +++ b/test/custom-parser-async.test.js @@ -27,7 +27,7 @@ test('contentTypeParser should add a custom async parser', t => { fastify.listen(0, err => { t.error(err) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) t.test('in POST', t => { t.plan(3) @@ -41,8 +41,8 @@ test('contentTypeParser should add a custom async parser', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) @@ -58,8 +58,8 @@ test('contentTypeParser should add a custom async parser', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) }) @@ -71,8 +71,8 @@ test('contentTypeParser should add a custom async parser - deprecated syntax', t process.on('warning', onWarning) function onWarning (warning) { - t.strictEqual(warning.name, 'FastifyDeprecation') - t.strictEqual(warning.code, 'FSTDEP003') + t.equal(warning.name, 'FastifyDeprecation') + t.equal(warning.code, 'FSTDEP003') } fastify.post('/', (req, reply) => { @@ -91,7 +91,7 @@ test('contentTypeParser should add a custom async parser - deprecated syntax', t fastify.listen(0, err => { t.error(err) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) t.test('in POST', t => { t.plan(3) @@ -105,8 +105,8 @@ test('contentTypeParser should add a custom async parser - deprecated syntax', t } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) @@ -122,8 +122,8 @@ test('contentTypeParser should add a custom async parser - deprecated syntax', t } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) process.removeListener('warning', onWarning) }) }) diff --git a/test/custom-parser.test.js b/test/custom-parser.test.js index a3c4efd8ef..f71edcba65 100644 --- a/test/custom-parser.test.js +++ b/test/custom-parser.test.js @@ -54,7 +54,7 @@ test('contentTypeParser should add a custom parser', t => { fastify.listen(0, err => { t.error(err) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) t.test('in POST', t => { t.plan(3) @@ -68,8 +68,8 @@ test('contentTypeParser should add a custom parser', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) @@ -85,8 +85,8 @@ test('contentTypeParser should add a custom parser', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) }) @@ -98,8 +98,8 @@ test('contentTypeParser should add a custom parser - deprecated syntax', t => { process.on('warning', onWarning) function onWarning (warning) { - t.strictEqual(warning.name, 'FastifyDeprecation') - t.strictEqual(warning.code, 'FSTDEP003') + t.equal(warning.name, 'FastifyDeprecation') + t.equal(warning.code, 'FSTDEP003') } fastify.post('/', (req, reply) => { @@ -119,7 +119,7 @@ test('contentTypeParser should add a custom parser - deprecated syntax', t => { fastify.listen(0, err => { t.error(err) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) t.test('in POST', t => { t.plan(3) @@ -133,8 +133,8 @@ test('contentTypeParser should add a custom parser - deprecated syntax', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) @@ -150,8 +150,8 @@ test('contentTypeParser should add a custom parser - deprecated syntax', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) process.removeListener('warning', onWarning) @@ -193,8 +193,8 @@ test('contentTypeParser should handle multiple custom parsers', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) sget({ @@ -206,8 +206,8 @@ test('contentTypeParser should handle multiple custom parsers', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) }) @@ -245,8 +245,8 @@ test('contentTypeParser should handle an array of custom contentTypes', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) sget({ @@ -258,8 +258,8 @@ test('contentTypeParser should handle an array of custom contentTypes', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) }) @@ -288,7 +288,7 @@ test('contentTypeParser should handle errors', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) fastify.close() }) }) @@ -349,8 +349,8 @@ test('contentTypeParser should support encapsulation, second try', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) fastify.close() }) }) @@ -382,7 +382,7 @@ test('contentTypeParser shouldn\'t support request with undefined "Content-Type" } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 415) + t.equal(response.statusCode, 415) fastify.close() }) }) @@ -396,8 +396,8 @@ test('the content type should be a string or RegExp', t => { fastify.addContentTypeParser(null, () => {}) t.fail() } catch (err) { - t.is(err.code, 'FST_ERR_CTP_INVALID_TYPE') - t.is(err.message, 'The content type should be a string or a RegExp') + t.equal(err.code, 'FST_ERR_CTP_INVALID_TYPE') + t.equal(err.message, 'The content type should be a string or a RegExp') } }) @@ -409,8 +409,8 @@ test('the content type cannot be an empty string', t => { fastify.addContentTypeParser('', () => {}) t.fail() } catch (err) { - t.is(err.code, 'FST_ERR_CTP_EMPTY_TYPE') - t.is(err.message, 'The content type cannot be an empty string') + t.equal(err.code, 'FST_ERR_CTP_EMPTY_TYPE') + t.equal(err.message, 'The content type cannot be an empty string') } }) @@ -422,8 +422,8 @@ test('the content type handler should be a function', t => { fastify.addContentTypeParser('aaa', null) t.fail() } catch (err) { - t.is(err.code, 'FST_ERR_CTP_INVALID_HANDLER') - t.is(err.message, 'The content type handler should be a function') + t.equal(err.code, 'FST_ERR_CTP_INVALID_HANDLER') + t.equal(err.message, 'The content type handler should be a function') } }) @@ -455,8 +455,8 @@ test('catch all content type parser', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'hello') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'hello') sget({ method: 'POST', @@ -467,8 +467,8 @@ test('catch all content type parser', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'hello') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'hello') fastify.close() }) }) @@ -509,8 +509,8 @@ test('catch all content type parser should not interfere with other conte type p } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) sget({ method: 'POST', @@ -521,8 +521,8 @@ test('catch all content type parser should not interfere with other conte type p } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'hello') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'hello') fastify.close() }) }) @@ -535,7 +535,7 @@ test('\'*\' catch undefined Content-Type requests', t => { const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.addContentTypeParser('*', function (req, payload, done) { let data = '' @@ -561,8 +561,8 @@ test('\'*\' catch undefined Content-Type requests', t => { body: fileStream }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body + '', fs.readFileSync(__filename).toString()) + t.equal(response.statusCode, 200) + t.equal(body + '', fs.readFileSync(__filename).toString()) }) }) }) @@ -572,7 +572,7 @@ test('cannot add custom parser after binding', t => { const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.post('/', (req, res) => { res.type('text/plain').send(req.body) @@ -617,8 +617,8 @@ test('Can override the default json parser', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), '{"hello":"world"}') + t.equal(response.statusCode, 200) + t.equal(body.toString(), '{"hello":"world"}') fastify.close() }) }) @@ -651,8 +651,8 @@ test('Can override the default plain text parser', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), 'hello world') + t.equal(response.statusCode, 200) + t.equal(body.toString(), 'hello world') fastify.close() }) }) @@ -689,8 +689,8 @@ test('Can override the default json parser in a plugin', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), '{"hello":"world"}') + t.equal(response.statusCode, 200) + t.equal(body.toString(), '{"hello":"world"}') fastify.close() }) }) @@ -714,8 +714,8 @@ test('Can\'t override the json parser multiple times', t => { }) }) } catch (err) { - t.is(err.code, 'FST_ERR_CTP_ALREADY_PRESENT') - t.is(err.message, 'Content type parser \'application/json\' already present.') + t.equal(err.code, 'FST_ERR_CTP_ALREADY_PRESENT') + t.equal(err.message, 'Content type parser \'application/json\' already present.') } }) @@ -737,8 +737,8 @@ test('Can\'t override the plain text parser multiple times', t => { }) }) } catch (err) { - t.is(err.code, 'FST_ERR_CTP_ALREADY_PRESENT') - t.is(err.message, 'Content type parser \'text/plain\' already present.') + t.equal(err.code, 'FST_ERR_CTP_ALREADY_PRESENT') + t.equal(err.message, 'Content type parser \'text/plain\' already present.') } }) @@ -774,8 +774,8 @@ test('Should get the body as string', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), '{"hello":"world"}') + t.equal(response.statusCode, 200) + t.equal(body.toString(), '{"hello":"world"}') fastify.close() }) }) @@ -801,8 +801,8 @@ test('Should return defined body with no custom parser defined and content type } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), 'hello world') + t.equal(response.statusCode, 200) + t.equal(body.toString(), 'hello world') fastify.close() }) }) @@ -827,8 +827,8 @@ test('Should have typeof body object with no custom parser defined, no body defi } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(typeof body, 'object') + t.equal(response.statusCode, 200) + t.equal(typeof body, 'object') fastify.close() }) }) @@ -854,8 +854,8 @@ test('Should have typeof body object with no custom parser defined, null body an } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(typeof body, 'object') + t.equal(response.statusCode, 200) + t.equal(typeof body, 'object') fastify.close() }) }) @@ -881,8 +881,8 @@ test('Should have typeof body object with no custom parser defined, undefined bo } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(typeof body, 'object') + t.equal(response.statusCode, 200) + t.equal(typeof body, 'object') fastify.close() }) }) @@ -920,8 +920,8 @@ test('Should get the body as string', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), 'hello world') + t.equal(response.statusCode, 200) + t.equal(body.toString(), 'hello world') fastify.close() }) }) @@ -959,8 +959,8 @@ test('Should get the body as buffer', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), '{"hello":"world"}') + t.equal(response.statusCode, 200) + t.equal(body.toString(), '{"hello":"world"}') fastify.close() }) }) @@ -998,8 +998,8 @@ test('Should get the body as buffer', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), 'hello world') + t.equal(response.statusCode, 200) + t.equal(body.toString(), 'hello world') fastify.close() }) }) @@ -1010,7 +1010,7 @@ test('Should parse empty bodies as a string', t => { const fastify = Fastify() fastify.addContentTypeParser('text/plain', { parseAs: 'string' }, (req, body, done) => { - t.strictEqual(body, '') + t.equal(body, '') done(null, body) }) @@ -1035,8 +1035,8 @@ test('Should parse empty bodies as a string', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), '') + t.equal(response.statusCode, 200) + t.equal(body.toString(), '') }) sget({ @@ -1049,8 +1049,8 @@ test('Should parse empty bodies as a string', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), '') + t.equal(response.statusCode, 200) + t.equal(body.toString(), '') }) }) }) @@ -1065,7 +1065,7 @@ test('Should parse empty bodies as a buffer', t => { fastify.addContentTypeParser('text/plain', { parseAs: 'buffer' }, function (req, body, done) { t.ok(body instanceof Buffer) - t.strictEqual(body.length, 0) + t.equal(body.length, 0) done(null, body) }) @@ -1081,8 +1081,8 @@ test('Should parse empty bodies as a buffer', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.length, 0) + t.equal(response.statusCode, 200) + t.equal(body.length, 0) fastify.close() }) }) @@ -1115,8 +1115,8 @@ test('The charset should not interfere with the content type handling', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), '{"hello":"world"}') + t.equal(response.statusCode, 200) + t.equal(body.toString(), '{"hello":"world"}') fastify.close() }) }) @@ -1130,15 +1130,15 @@ test('Wrong parseAs parameter', t => { fastify.addContentTypeParser('application/json', { parseAs: 'fireworks' }, () => {}) t.fail('should throw') } catch (err) { - t.is(err.code, 'FST_ERR_CTP_INVALID_PARSE_TYPE') - t.is(err.message, "The body parser can only parse your data as 'string' or 'buffer', you asked 'fireworks' which is not supported.") + t.equal(err.code, 'FST_ERR_CTP_INVALID_PARSE_TYPE') + t.equal(err.message, "The body parser can only parse your data as 'string' or 'buffer', you asked 'fireworks' which is not supported.") } }) test('Should allow defining the bodyLimit per parser', t => { t.plan(3) const fastify = Fastify() - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) fastify.post('/', (req, reply) => { reply.send(req.body) @@ -1165,7 +1165,7 @@ test('Should allow defining the bodyLimit per parser', t => { } }, (err, response, body) => { t.error(err) - t.strictDeepEqual(JSON.parse(body.toString()), { + t.strictSame(JSON.parse(body.toString()), { statusCode: 413, code: 'FST_ERR_CTP_BODY_TOO_LARGE', error: 'Payload Too Large', @@ -1179,7 +1179,7 @@ test('Should allow defining the bodyLimit per parser', t => { test('route bodyLimit should take precedence over a custom parser bodyLimit', t => { t.plan(3) const fastify = Fastify() - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) fastify.post('/', { bodyLimit: 5 }, (request, reply) => { reply.send(request.body) @@ -1204,7 +1204,7 @@ test('route bodyLimit should take precedence over a custom parser bodyLimit', t headers: { 'Content-Type': 'x/foo' } }, (err, response, body) => { t.error(err) - t.strictDeepEqual(JSON.parse(body.toString()), { + t.strictSame(JSON.parse(body.toString()), { statusCode: 413, code: 'FST_ERR_CTP_BODY_TOO_LARGE', error: 'Payload Too Large', @@ -1218,7 +1218,7 @@ test('route bodyLimit should take precedence over a custom parser bodyLimit', t test('should be able to use default parser for extra content type', t => { t.plan(4) const fastify = Fastify() - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) fastify.post('/', (request, reply) => { reply.send(request.body) @@ -1238,8 +1238,8 @@ test('should be able to use default parser for extra content type', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictDeepEqual(JSON.parse(body.toString()), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.strictSame(JSON.parse(body.toString()), { hello: 'world' }) fastify.close() }) }) @@ -1267,7 +1267,7 @@ test('contentTypeParser should add a custom parser with RegExp value', t => { fastify.listen(0, err => { t.error(err) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) t.test('in POST', t => { t.plan(3) @@ -1281,8 +1281,8 @@ test('contentTypeParser should add a custom parser with RegExp value', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) @@ -1298,8 +1298,8 @@ test('contentTypeParser should add a custom parser with RegExp value', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) }) @@ -1343,8 +1343,8 @@ test('contentTypeParser should add multiple custom parsers with RegExp values', } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) sget({ @@ -1356,8 +1356,8 @@ test('contentTypeParser should add multiple custom parsers with RegExp values', } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'xml') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'xml') }) sget({ @@ -1369,8 +1369,8 @@ test('contentTypeParser should add multiple custom parsers with RegExp values', } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'abcdefgmyExtension') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'abcdefgmyExtension') fastify.close() }) }) @@ -1418,8 +1418,8 @@ test('catch all content type parser should not interfere with content type parse } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ myKey: 'myValue' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ myKey: 'myValue' })) }) sget({ @@ -1431,8 +1431,8 @@ test('catch all content type parser should not interfere with content type parse } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'body') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'body') }) sget({ @@ -1444,8 +1444,8 @@ test('catch all content type parser should not interfere with content type parse } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'my texthtml') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'my texthtml') fastify.close() }) }) @@ -1485,8 +1485,8 @@ test('should prefer string content types over RegExp ones', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ k1: 'myValue', k2: 'myValue' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ k1: 'myValue', k2: 'myValue' })) }) sget({ @@ -1498,8 +1498,8 @@ test('should prefer string content types over RegExp ones', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'javascript') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'javascript') fastify.close() }) }) diff --git a/test/custom-querystring-parser.test.js b/test/custom-querystring-parser.test.js index 9cf21ed5b5..3563680076 100644 --- a/test/custom-querystring-parser.test.js +++ b/test/custom-querystring-parser.test.js @@ -11,13 +11,13 @@ test('Custom querystring parser', t => { const fastify = Fastify({ querystringParser: function (str) { - t.strictEqual(str, 'foo=bar&baz=faz') + t.equal(str, 'foo=bar&baz=faz') return querystring.parse(str) } }) fastify.get('/', (req, reply) => { - t.deepEqual(req.query, { + t.same(req.query, { foo: 'bar', baz: 'faz' }) @@ -26,14 +26,14 @@ test('Custom querystring parser', t => { fastify.listen(0, (err, address) => { t.error(err) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) sget({ method: 'GET', url: `${address}?foo=bar&baz=faz` }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) fastify.inject({ @@ -41,7 +41,7 @@ test('Custom querystring parser', t => { url: `${address}?foo=bar&baz=faz` }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) }) @@ -51,26 +51,26 @@ test('Custom querystring parser should be called also if there is nothing to par const fastify = Fastify({ querystringParser: function (str) { - t.strictEqual(str, '') + t.equal(str, '') return querystring.parse(str) } }) fastify.get('/', (req, reply) => { - t.deepEqual(req.query, {}) + t.same(req.query, {}) reply.send({ hello: 'world' }) }) fastify.listen(0, (err, address) => { t.error(err) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) sget({ method: 'GET', url: address }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) fastify.inject({ @@ -78,7 +78,7 @@ test('Custom querystring parser should be called also if there is nothing to par url: address }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) }) @@ -88,26 +88,26 @@ test('Querystring without value', t => { const fastify = Fastify({ querystringParser: function (str) { - t.strictEqual(str, 'foo') + t.equal(str, 'foo') return querystring.parse(str) } }) fastify.get('/', (req, reply) => { - t.deepEqual(req.query, { foo: '' }) + t.same(req.query, { foo: '' }) reply.send({ hello: 'world' }) }) fastify.listen(0, (err, address) => { t.error(err) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) sget({ method: 'GET', url: `${address}?foo` }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) fastify.inject({ @@ -115,7 +115,7 @@ test('Querystring without value', t => { url: `${address}?foo` }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) }) @@ -129,7 +129,7 @@ test('Custom querystring parser should be a function', t => { }) t.fail('Should throw') } catch (err) { - t.strictEqual( + t.equal( err.message, "querystringParser option should be a function, instead got 'number'" ) diff --git a/test/decorator.test.js b/test/decorator.test.js index 50846f5ab6..10f585a570 100644 --- a/test/decorator.test.js +++ b/test/decorator.test.js @@ -56,8 +56,8 @@ test('decorate should throw if a declared dependency is not present', t => { instance.decorate('test', () => {}, ['dependency']) t.fail() } catch (e) { - t.is(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') - t.is(e.message, 'The decorator is missing dependency \'dependency\'.') + t.ok(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') + t.ok(e.message, 'The decorator is missing dependency \'dependency\'.') } done() }) @@ -115,9 +115,9 @@ test('decorateReply inside register', t => { url: 'http://localhost:' + fastify.server.address().port + '/yes' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -125,9 +125,9 @@ test('decorateReply inside register', t => { url: 'http://localhost:' + fastify.server.address().port + '/no' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -163,9 +163,9 @@ test('decorateReply as plugin (inside .after)', t => { url: 'http://localhost:' + fastify.server.address().port + '/yes' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -173,9 +173,9 @@ test('decorateReply as plugin (inside .after)', t => { url: 'http://localhost:' + fastify.server.address().port + '/no' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -211,9 +211,9 @@ test('decorateReply as plugin (outside .after)', t => { url: 'http://localhost:' + fastify.server.address().port + '/yes' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -221,9 +221,9 @@ test('decorateReply as plugin (outside .after)', t => { url: 'http://localhost:' + fastify.server.address().port + '/no' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -258,9 +258,9 @@ test('decorateRequest inside register', t => { url: 'http://localhost:' + fastify.server.address().port + '/yes' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -268,9 +268,9 @@ test('decorateRequest inside register', t => { url: 'http://localhost:' + fastify.server.address().port + '/no' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -306,9 +306,9 @@ test('decorateRequest as plugin (inside .after)', t => { url: 'http://localhost:' + fastify.server.address().port + '/yes' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -316,9 +316,9 @@ test('decorateRequest as plugin (inside .after)', t => { url: 'http://localhost:' + fastify.server.address().port + '/no' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -354,9 +354,9 @@ test('decorateRequest as plugin (outside .after)', t => { url: 'http://localhost:' + fastify.server.address().port + '/yes' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -364,9 +364,9 @@ test('decorateRequest as plugin (outside .after)', t => { url: 'http://localhost:' + fastify.server.address().port + '/no' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -512,7 +512,7 @@ test('should register properties via getter/setter objects', t => { } }) t.ok(instance.test) - t.is(instance.test, 'a getter') + t.ok(instance.test, 'a getter') done() }) @@ -547,7 +547,7 @@ test('decorateRequest should work with getter/setter', t => { fastify.ready(() => { fastify.inject({ url: '/req-decorated-get-set' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { test: 'a getter' }) + t.same(JSON.parse(res.payload), { test: 'a getter' }) }) fastify.inject({ url: '/not-decorated' }, (err, res) => { @@ -583,7 +583,7 @@ test('decorateReply should work with getter/setter', t => { fastify.ready(() => { fastify.inject({ url: '/res-decorated-get-set' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { test: 'a getter' }) + t.same(JSON.parse(res.payload), { test: 'a getter' }) }) fastify.inject({ url: '/not-decorated' }, (err, res) => { @@ -599,7 +599,7 @@ test('should register empty values', t => { fastify.register((instance, opts, done) => { instance.decorate('test', null) - t.true(instance.hasOwnProperty('test')) + t.ok(instance.hasOwnProperty('test')) done() }) @@ -726,22 +726,22 @@ test('decorate* should throw if called after ready', async t => { fastify.decorate('test', true) t.fail('should not decorate') } catch (err) { - t.is(err.code, 'FST_ERR_DEC_AFTER_START') - t.is(err.message, "The decorator 'test' has been added after start!") + t.ok(err.code, 'FST_ERR_DEC_AFTER_START') + t.ok(err.message, "The decorator 'test' has been added after start!") } try { fastify.decorateRequest('test', true) t.fail('should not decorate') } catch (e) { - t.is(e.code, 'FST_ERR_DEC_AFTER_START') - t.is(e.message, "The decorator 'test' has been added after start!") + t.ok(e.code, 'FST_ERR_DEC_AFTER_START') + t.ok(e.message, "The decorator 'test' has been added after start!") } try { fastify.decorateReply('test', true) t.fail('should not decorate') } catch (e) { - t.is(e.code, 'FST_ERR_DEC_AFTER_START') - t.is(e.message, "The decorator 'test' has been added after start!") + t.ok(e.code, 'FST_ERR_DEC_AFTER_START') + t.ok(e.message, "The decorator 'test' has been added after start!") } await fastify.close() }) @@ -749,8 +749,8 @@ test('decorate* should throw if called after ready', async t => { test('decorate* should emit warning if an array is passed', t => { t.plan(2) function onWarning (code, name) { - t.strictEqual(name, 'test_array') - t.strictEqual(code, 'FSTDEP006') + t.equal(name, 'test_array') + t.equal(code, 'FSTDEP006') } const warning = { emit: onWarning @@ -764,8 +764,8 @@ test('decorate* should emit warning if an array is passed', t => { test('decorate* should emit warning if object type is passed', t => { t.plan(2) function onWarning (code, name) { - t.strictEqual(name, 'test_object') - t.strictEqual(code, 'FSTDEP006') + t.equal(name, 'test_object') + t.equal(code, 'FSTDEP006') } const warning = { emit: onWarning diff --git a/test/delete.test.js b/test/delete.test.js index 8b28c33c45..12aad254db 100644 --- a/test/delete.test.js +++ b/test/delete.test.js @@ -168,9 +168,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -181,9 +181,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/params/world/123' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { foo: 'world', test: 123 }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { foo: 'world', test: 123 }) }) }) @@ -194,8 +194,8 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/params/world/string' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 400) + t.same(JSON.parse(body), { error: 'Bad Request', message: 'params.test should be integer', statusCode: 400 @@ -213,9 +213,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/headers' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.strictEqual(JSON.parse(body)['x-test'], 1) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.equal(JSON.parse(body)['x-test'], 1) }) }) @@ -229,8 +229,8 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/headers' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 400) + t.same(JSON.parse(body), { error: 'Bad Request', message: "headers['x-test'] should be number", statusCode: 400 @@ -245,9 +245,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/query?hello=123' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 123 }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 123 }) }) }) @@ -258,8 +258,8 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/query?hello=world' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 400) + t.same(JSON.parse(body), { error: 'Bad Request', message: 'querystring.hello should be integer', statusCode: 400 @@ -274,9 +274,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/missing' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -291,8 +291,8 @@ fastify.listen(0, err => { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(body, { hello: 'world' }) }) }) }) @@ -312,7 +312,7 @@ test('shorthand - delete with application/json Content-Type header and without b body: null }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(response.payload), null) + t.equal(response.statusCode, 200) + t.same(JSON.parse(response.payload), null) }) }) diff --git a/test/emit-warning.test.js b/test/emit-warning.test.js index 4d44b04a50..64ace1464a 100644 --- a/test/emit-warning.test.js +++ b/test/emit-warning.test.js @@ -12,9 +12,9 @@ test('Should emit a warning when accessing request.req instead of request.raw', process.on('warning', onWarning) function onWarning (warning) { - t.strictEqual(warning.name, 'FastifyDeprecation') - t.strictEqual(warning.code, 'FSTDEP001') - t.strictEqual(warning.message, 'You are accessing the Node.js core request object via "request.req", Use "request.raw" instead.') + t.equal(warning.name, 'FastifyDeprecation') + t.equal(warning.code, 'FSTDEP001') + t.equal(warning.message, 'You are accessing the Node.js core request object via "request.req", Use "request.raw" instead.') } const fastify = Fastify() @@ -37,9 +37,9 @@ test('Should emit a warning when accessing reply.res instead of reply.raw', t => process.on('warning', onWarning) function onWarning (warning) { - t.strictEqual(warning.name, 'FastifyDeprecation') - t.strictEqual(warning.code, 'FSTDEP002') - t.strictEqual(warning.message, 'You are accessing the Node.js core response object via "reply.res", Use "reply.raw" instead.') + t.equal(warning.name, 'FastifyDeprecation') + t.equal(warning.code, 'FSTDEP002') + t.equal(warning.message, 'You are accessing the Node.js core response object via "reply.res", Use "reply.raw" instead.') } const fastify = Fastify() @@ -62,9 +62,9 @@ test('Should emit a warning when using two arguments Content Type Parser instead process.on('warning', onWarning) function onWarning (warning) { - t.strictEqual(warning.name, 'FastifyDeprecation') - t.strictEqual(warning.code, 'FSTDEP003') - t.strictEqual(warning.message, 'You are using the legacy Content Type Parser function signature. Use the one suggested in the documentation instead.') + t.equal(warning.name, 'FastifyDeprecation') + t.equal(warning.code, 'FSTDEP003') + t.equal(warning.message, 'You are using the legacy Content Type Parser function signature. Use the one suggested in the documentation instead.') } const fastify = Fastify() @@ -87,8 +87,8 @@ test('Should emit a warning when using two arguments Content Type Parser instead body: '{"hello":"world"}' }, (err, response, body) => { t.error(err) - t.is(response.statusCode, 200) - t.is(body.toString(), 'OK') + t.equal(response.statusCode, 200) + t.equal(body.toString(), 'OK') process.removeListener('warning', onWarning) fastify.close() }) @@ -100,9 +100,9 @@ test('Should emit a warning when using payload less preParsing hook', t => { process.on('warning', onWarning) function onWarning (warning) { - t.strictEqual(warning.name, 'FastifyDeprecation') - t.strictEqual(warning.code, 'FSTDEP004') - t.strictEqual(warning.message, 'You are using the legacy preParsing hook signature. Use the one suggested in the documentation instead.') + t.equal(warning.name, 'FastifyDeprecation') + t.equal(warning.code, 'FSTDEP004') + t.equal(warning.message, 'You are using the legacy preParsing hook signature. Use the one suggested in the documentation instead.') } const fastify = Fastify() @@ -123,8 +123,8 @@ test('Should emit a warning when using payload less preParsing hook', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.is(response.statusCode, 200) - t.is(body.toString(), 'OK') + t.equal(response.statusCode, 200) + t.equal(body.toString(), 'OK') process.removeListener('warning', onWarning) fastify.close() }) @@ -137,9 +137,9 @@ if (semver.gte(process.versions.node, '13.0.0')) { process.on('warning', onWarning) function onWarning (warning) { - t.strictEqual(warning.name, 'FastifyDeprecation') - t.strictEqual(warning.code, 'FSTDEP005') - t.strictEqual(warning.message, 'You are accessing the deprecated "request.connection" property. Use "request.socket" instead.') + t.equal(warning.name, 'FastifyDeprecation') + t.equal(warning.code, 'FSTDEP005') + t.equal(warning.message, 'You are accessing the deprecated "request.connection" property. Use "request.socket" instead.') // removed listener before light-my-request emit second warning process.removeListener('warning', onWarning) diff --git a/test/esm/esm.mjs b/test/esm/esm.mjs index f7a29f687c..aab4b614ac 100644 --- a/test/esm/esm.mjs +++ b/test/esm/esm.mjs @@ -9,5 +9,5 @@ t.test('esm support', async t => { await fastify.ready() - t.strictEqual(fastify.foo, 'bar') + t.equal(fastify.foo, 'bar') }) diff --git a/test/esm/named-exports.mjs b/test/esm/named-exports.mjs index c92e6681de..3f540849ff 100644 --- a/test/esm/named-exports.mjs +++ b/test/esm/named-exports.mjs @@ -9,5 +9,5 @@ t.test('named exports support', async t => { await app.ready() - t.strictEqual(app.foo, 'bar') + t.equal(app.foo, 'bar') }) diff --git a/test/esm/other.mjs b/test/esm/other.mjs index ed187338e4..5d42b4b2a8 100644 --- a/test/esm/other.mjs +++ b/test/esm/other.mjs @@ -1,7 +1,7 @@ import t from 'tap' async function other (fastify, opts) { - t.strictEqual(fastify.foo, 'bar') + t.equal(fastify.foo, 'bar') } export default other diff --git a/test/fastify-instance.test.js b/test/fastify-instance.test.js index c7361174b0..d53865be1e 100644 --- a/test/fastify-instance.test.js +++ b/test/fastify-instance.test.js @@ -50,7 +50,7 @@ test('fastify instance should contains ajv options.plugins nested arrays', t => test('fastify instance get invalid ajv options', t => { t.plan(1) - t.throw(() => Fastify({ + t.throws(() => Fastify({ ajv: { customOptions: 8 } @@ -59,7 +59,7 @@ test('fastify instance get invalid ajv options', t => { test('fastify instance get invalid ajv options.plugins', t => { t.plan(1) - t.throw(() => Fastify({ + t.throws(() => Fastify({ ajv: { customOptions: {}, plugins: 8 diff --git a/test/fluent-schema.test.js b/test/fluent-schema.test.js index 70da74b5bc..803999e9ff 100644 --- a/test/fluent-schema.test.js +++ b/test/fluent-schema.test.js @@ -33,8 +33,8 @@ test('use fluent-json-schema object', t => { payload: { name: 'foo' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) - t.deepEquals(res.json(), { statusCode: 400, error: 'Bad Request', message: 'params.id should be >= 42' }) + t.equal(res.statusCode, 400) + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'params.id should be >= 42' }) }) // check header @@ -46,8 +46,8 @@ test('use fluent-json-schema object', t => { payload: { name: 'foo' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) - t.deepEquals(res.json(), { statusCode: 400, error: 'Bad Request', message: 'headers[\'x-custom\'] should match format "email"' }) + t.equal(res.statusCode, 400) + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'headers[\'x-custom\'] should match format "email"' }) }) // check query @@ -59,8 +59,8 @@ test('use fluent-json-schema object', t => { payload: { name: 'foo' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) - t.deepEquals(res.json(), { statusCode: 400, error: 'Bad Request', message: 'querystring should have required property \'surname\'' }) + t.equal(res.statusCode, 400) + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'querystring should have required property \'surname\'' }) }) // check body @@ -72,8 +72,8 @@ test('use fluent-json-schema object', t => { payload: { name: [1, 2, 3] } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) - t.deepEquals(res.json(), { statusCode: 400, error: 'Bad Request', message: 'body.name should be string' }) + t.equal(res.statusCode, 400) + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'body.name should be string' }) }) // check response @@ -85,8 +85,8 @@ test('use fluent-json-schema object', t => { payload: { name: 'foo' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { name: 'a', surname: 'b' }) + t.equal(res.statusCode, 200) + t.same(res.json(), { name: 'a', surname: 'b' }) }) }) diff --git a/test/get.test.js b/test/get.test.js index 854090e8f7..248aa6d899 100644 --- a/test/get.test.js +++ b/test/get.test.js @@ -214,9 +214,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -227,9 +227,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/params/world/123' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { foo: 'world', test: 123 }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { foo: 'world', test: 123 }) }) }) @@ -240,8 +240,8 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/params/world/string' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 400) + t.same(JSON.parse(body), { error: 'Bad Request', message: 'params.test should be integer', statusCode: 400 @@ -261,9 +261,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/headers' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body['x-test'], 1) - t.strictEqual(body['y-test'], 3) + t.equal(response.statusCode, 200) + t.equal(body['x-test'], 1) + t.equal(body['y-test'], 3) }) }) @@ -277,8 +277,8 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/headers' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 400) + t.same(JSON.parse(body), { error: 'Bad Request', message: "headers['x-test'] should be number", statusCode: 400 @@ -293,9 +293,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/query?hello=123' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 123 }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 123 }) }) }) @@ -306,8 +306,8 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/query?hello=world' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 400) + t.same(JSON.parse(body), { error: 'Bad Request', message: 'querystring.hello should be integer', statusCode: 400 @@ -322,9 +322,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/missing' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -335,9 +335,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/custom-serializer' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -348,9 +348,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/empty' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '0') - t.deepEqual(body.toString(), '') + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '0') + t.same(body.toString(), '') }) }) @@ -361,8 +361,8 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/boolean' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'false') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'false') }) }) @@ -373,8 +373,8 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/null' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'null') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'null') }) }) }) diff --git a/test/handler-context.test.js b/test/handler-context.test.js index 7542dcb580..c220c2e6f1 100644 --- a/test/handler-context.test.js +++ b/test/handler-context.test.js @@ -19,7 +19,7 @@ test('handlers receive correct `this` context', (t) => { instance.get('/', function (req, reply) { t.ok(this.foo) - t.is(this.foo, 'foo') + t.equal(this.foo, 'foo') reply.send() }) @@ -27,7 +27,7 @@ test('handlers receive correct `this` context', (t) => { instance.server.unref() if (err) t.threw(err) t.ok(instance.foo) - t.is(instance.foo, 'foo') + t.equal(instance.foo, 'foo') const address = `http://127.0.0.1:${instance.server.address().port}/` http.get(address, () => {}).on('error', t.threw) @@ -43,7 +43,7 @@ test('handlers have access to the internal context', (t) => { t.ok(reply.context.config) t.type(reply.context.config, Object) t.ok(reply.context.config.foo) - t.is(reply.context.config.foo, 'bar') + t.equal(reply.context.config.foo, 'bar') reply.send() }) diff --git a/test/head.test.js b/test/head.test.js index 2da3d96512..29bbe1f9a6 100644 --- a/test/head.test.js +++ b/test/head.test.js @@ -103,7 +103,7 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) @@ -114,7 +114,7 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/params/world/123' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) @@ -125,7 +125,7 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/params/world/string' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 400) + t.equal(response.statusCode, 400) }) }) @@ -136,7 +136,7 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/query?hello=123' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) @@ -147,7 +147,7 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/query?hello=world' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 400) + t.equal(response.statusCode, 400) }) }) @@ -158,7 +158,7 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/missing' }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) }) diff --git a/test/helper.js b/test/helper.js index c0e7dc5556..d9c00928c1 100644 --- a/test/helper.js +++ b/test/helper.js @@ -110,8 +110,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(body, { hello: 'world' }) }) }) @@ -126,8 +126,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: largeString }) + t.equal(response.statusCode, 200) + t.same(body, { hello: largeString }) }) }) @@ -142,8 +142,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) @@ -158,8 +158,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(body, { hello: 'world' }) }) }) @@ -174,8 +174,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: 'worldhello' }) + t.equal(response.statusCode, 200) + t.same(body, { hello: 'worldhello' }) }) }) @@ -188,8 +188,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { headers: { 'Content-Length': '0' } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(JSON.parse(body.toString()), null) + t.equal(response.statusCode, 200) + t.equal(JSON.parse(body.toString()), null) }) // Must use inject to make a request without a Content-Length header @@ -198,8 +198,8 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { url: '/missing' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.strictEqual(JSON.parse(res.payload), null) + t.equal(res.statusCode, 200) + t.equal(JSON.parse(res.payload), null) }) }) @@ -213,9 +213,9 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { }, (err, response, body) => { t.error(err) if (upMethod === 'OPTIONS') { - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) } else { - t.strictEqual(response.statusCode, 415) + t.equal(response.statusCode, 415) } }) }) @@ -232,7 +232,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 415) + t.equal(response.statusCode, 415) }) }) } @@ -249,7 +249,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) + t.equal(response.statusCode, 400) }) sget({ @@ -261,7 +261,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) + t.equal(response.statusCode, 400) }) }) @@ -277,7 +277,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 413) + t.equal(response.statusCode, 413) }) // Node errors for OPTIONS requests with a stream body and no Content-Length header @@ -296,7 +296,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { body: largeStream }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 413) + t.equal(response.statusCode, 413) }) } @@ -308,7 +308,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 413) + t.equal(response.statusCode, 413) }) }) @@ -325,7 +325,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { } }, (err, res) => { t.error(err) - t.strictDeepEqual(JSON.parse(res.payload), { + t.same(JSON.parse(res.payload), { error: 'Bad Request', code: 'FST_ERR_CTP_EMPTY_JSON_BODY', message: 'Body cannot be empty when content-type is set to \'application/json\'', @@ -341,7 +341,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { } }, (err, res, body) => { t.error(err) - t.strictDeepEqual(JSON.parse(body.toString()), { + t.same(JSON.parse(body.toString()), { error: 'Bad Request', code: 'FST_ERR_CTP_EMPTY_JSON_BODY', message: 'Body cannot be empty when content-type is set to \'application/json\'', @@ -358,7 +358,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { payload: null }, (err, res) => { t.error(err) - t.strictDeepEqual(JSON.parse(res.payload), { + t.same(JSON.parse(res.payload), { error: 'Bad Request', code: 'FST_ERR_CTP_EMPTY_JSON_BODY', message: 'Body cannot be empty when content-type is set to \'application/json\'', @@ -375,7 +375,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { payload: null }, (err, res, body) => { t.error(err) - t.strictDeepEqual(JSON.parse(body.toString()), { + t.same(JSON.parse(body.toString()), { error: 'Bad Request', code: 'FST_ERR_CTP_EMPTY_JSON_BODY', message: 'Body cannot be empty when content-type is set to \'application/json\'', @@ -392,7 +392,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { payload: undefined }, (err, res) => { t.error(err) - t.strictDeepEqual(JSON.parse(res.payload), { + t.same(JSON.parse(res.payload), { error: 'Bad Request', code: 'FST_ERR_CTP_EMPTY_JSON_BODY', message: 'Body cannot be empty when content-type is set to \'application/json\'', @@ -409,7 +409,7 @@ module.exports.payloadMethod = function (method, t, isSetErrorHandler = false) { payload: undefined }, (err, res, body) => { t.error(err) - t.strictDeepEqual(JSON.parse(body.toString()), { + t.same(JSON.parse(body.toString()), { error: 'Bad Request', code: 'FST_ERR_CTP_EMPTY_JSON_BODY', message: 'Body cannot be empty when content-type is set to \'application/json\'', diff --git a/test/hooks-async.test.js b/test/hooks-async.test.js index 444f7d2526..f57e6aa857 100644 --- a/test/hooks-async.test.js +++ b/test/hooks-async.test.js @@ -25,8 +25,8 @@ test('async hooks', t => { fastify.addHook('preHandler', async function (request, reply) { await sleep(1) - t.is(request.test, 'the request is coming') - t.is(reply.test, 'the reply has come') + t.equal(request.test, 'the request is coming') + t.equal(reply.test, 'the reply has come') if (request.raw.method === 'HEAD') { throw new Error('some error') } @@ -43,8 +43,8 @@ test('async hooks', t => { }) fastify.get('/', function (request, reply) { - t.is(request.test, 'the request is coming') - t.is(reply.test, 'the reply has come') + t.equal(request.test, 'the request is coming') + t.equal(reply.test, 'the reply has come') reply.code(200).send({ hello: 'world' }) }) @@ -65,9 +65,9 @@ test('async hooks', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -75,7 +75,7 @@ test('async hooks', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) sget({ @@ -83,7 +83,7 @@ test('async hooks', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) }) }) @@ -97,19 +97,19 @@ test('modify payload', t => { fastify.addHook('onSend', async function (request, reply, thePayload) { t.ok('onSend called') - t.deepEqual(JSON.parse(thePayload), payload) + t.same(JSON.parse(thePayload), payload) return thePayload.replace('world', 'modified') }) fastify.addHook('onSend', async function (request, reply, thePayload) { t.ok('onSend called') - t.deepEqual(JSON.parse(thePayload), modifiedPayload) + t.same(JSON.parse(thePayload), modifiedPayload) return anotherPayload }) fastify.addHook('onSend', async function (request, reply, thePayload) { t.ok('onSend called') - t.strictEqual(thePayload, anotherPayload) + t.equal(thePayload, anotherPayload) }) fastify.get('/', (req, reply) => { @@ -121,9 +121,9 @@ test('modify payload', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, anotherPayload) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '18') + t.equal(res.payload, anotherPayload) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '18') }) }) @@ -160,8 +160,8 @@ test('onRequest hooks should be able to block a request', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -190,7 +190,7 @@ test('preParsing hooks should be able to modify the payload', t => { }, (err, res) => { t.error(err) t.equal(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'another world' }) + t.same(JSON.parse(res.payload), { hello: 'another world' }) }) }) @@ -200,8 +200,8 @@ test('preParsing hooks can completely ignore the payload - deprecated syntax', t process.on('warning', onWarning) function onWarning (warning) { - t.strictEqual(warning.name, 'FastifyDeprecation') - t.strictEqual(warning.code, 'FSTDEP004') + t.equal(warning.name, 'FastifyDeprecation') + t.equal(warning.code, 'FSTDEP004') } fastify.addHook('preParsing', async (req, reply) => { @@ -219,7 +219,7 @@ test('preParsing hooks can completely ignore the payload - deprecated syntax', t }, (err, res) => { t.error(err) t.equal(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.same(JSON.parse(res.payload), { hello: 'world' }) process.removeListener('warning', onWarning) }) @@ -245,8 +245,8 @@ test('preParsing hooks should handle errors', t => { payload: { hello: 'world' } }, (err, res) => { t.error(err) - t.is(res.statusCode, 501) - t.deepEqual(JSON.parse(res.payload), { error: 'Not Implemented', message: 'kaboom', statusCode: 501 }) + t.equal(res.statusCode, 501) + t.same(JSON.parse(res.payload), { error: 'Not Implemented', message: 'kaboom', statusCode: 501 }) }) }) @@ -279,8 +279,8 @@ test('preHandler hooks should be able to block a request', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -313,8 +313,8 @@ test('preValidation hooks should be able to block a request', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -359,8 +359,8 @@ test('preValidation hooks should be able to change request body before validatio } }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -381,8 +381,8 @@ test('preSerialization hooks should be able to modify the payload', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'another world' }) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'another world' }) }) }) @@ -403,8 +403,8 @@ test('preSerialization hooks should handle errors', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 500) - t.deepEqual(JSON.parse(res.payload), { error: 'Internal Server Error', message: 'kaboom', statusCode: 500 }) + t.equal(res.statusCode, 500) + t.same(JSON.parse(res.payload), { error: 'Internal Server Error', message: 'kaboom', statusCode: 500 }) }) }) @@ -429,8 +429,8 @@ test('preValidation hooks should handle throwing null', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 500) - t.deepEqual(res.json(), { + t.equal(res.statusCode, 500) + t.same(res.json(), { error: 'Internal Server Error', code: 'FST_ERR_SEND_UNDEFINED_ERR', message: 'Undefined error has occured', @@ -455,7 +455,7 @@ test('preValidation hooks should handle throwing a string', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 500) + t.equal(res.statusCode, 500) t.equal(res.payload, 'this is an error') }) }) @@ -489,8 +489,8 @@ test('onRequest hooks should be able to block a request (last hook)', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -519,8 +519,8 @@ test('preHandler hooks should be able to block a request (last hook)', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -563,7 +563,7 @@ test('onRequest respond with a stream', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -584,7 +584,7 @@ test('preHandler respond with a stream', t => { const stream = fs.createReadStream(process.cwd() + '/test/stream.test.js', 'utf8') reply.send(stream) reply.raw.once('finish', () => { - t.is(order.shift(), 2) + t.equal(order.shift(), 2) resolve() }) }) @@ -595,8 +595,8 @@ test('preHandler respond with a stream', t => { }) fastify.addHook('onSend', async (req, reply, payload) => { - t.is(order.shift(), 1) - t.is(typeof payload.pipe, 'function') + t.equal(order.shift(), 1) + t.equal(typeof payload.pipe, 'function') }) fastify.addHook('onResponse', async (request, reply) => { @@ -612,7 +612,7 @@ test('preHandler respond with a stream', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -624,7 +624,7 @@ test('Should log a warning if is an async function with `done`', t => { try { fastify.addHook('onRequest', async (req, reply, done) => {}) } catch (e) { - t.true(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') + t.ok(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') } }) @@ -635,17 +635,17 @@ test('Should log a warning if is an async function with `done`', t => { try { fastify.addHook('onSend', async (req, reply, payload, done) => {}) } catch (e) { - t.true(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') + t.ok(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') } try { fastify.addHook('preSerialization', async (req, reply, payload, done) => {}) } catch (e) { - t.true(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') + t.ok(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') } try { fastify.addHook('onError', async (req, reply, payload, done) => {}) } catch (e) { - t.true(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') + t.ok(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') } }) @@ -667,8 +667,8 @@ test('early termination, onRequest async', async t => { }) const res = await app.inject('/') - t.is(res.statusCode, 200) - t.is(res.body.toString(), 'hello world') + t.equal(res.statusCode, 200) + t.equal(res.body.toString(), 'hello world') }) test('The this should be the same of the encapsulation level', async t => { @@ -676,9 +676,9 @@ test('The this should be the same of the encapsulation level', async t => { fastify.addHook('onRequest', async function (req, reply) { if (req.raw.url === '/nested') { - t.strictEqual(this.foo, 'bar') + t.equal(this.foo, 'bar') } else { - t.strictEqual(this.foo, undefined) + t.equal(this.foo, undefined) } }) @@ -715,7 +715,7 @@ test('preSerializationEnd should handle errors if the serialize method throws', url: '/' }, (err, res) => { t.error(err) - t.notEqual(res.statusCode, 200) + t.not(res.statusCode, 200) }) }) @@ -737,7 +737,7 @@ test('preSerializationEnd should handle errors if the serialize method throws', url: '/' }, (err, res) => { t.error(err) - t.notEqual(res.statusCode, 200) + t.not(res.statusCode, 200) }) }) diff --git a/test/hooks.on-ready.test.js b/test/hooks.on-ready.test.js index 5b2f32a5e9..dee663018e 100644 --- a/test/hooks.on-ready.test.js +++ b/test/hooks.on-ready.test.js @@ -11,23 +11,23 @@ t.test('onReady should be called in order', t => { let order = 0 fastify.addHook('onReady', function (done) { - t.equals(order++, 0, 'called in root') - t.equals(this.pluginName, fastify.pluginName, 'the this binding is the right instance') + t.equal(order++, 0, 'called in root') + t.equal(this.pluginName, fastify.pluginName, 'the this binding is the right instance') done() }) fastify.register(async (childOne, o) => { childOne.addHook('onReady', function (done) { - t.equals(order++, 1, 'called in childOne') - t.equals(this.pluginName, childOne.pluginName, 'the this binding is the right instance') + t.equal(order++, 1, 'called in childOne') + t.equal(this.pluginName, childOne.pluginName, 'the this binding is the right instance') done() }) childOne.register(async (childTwo, o) => { childTwo.addHook('onReady', async function () { await immediate() - t.equals(order++, 2, 'called in childTwo') - t.equals(this.pluginName, childTwo.pluginName, 'the this binding is the right instance') + t.equal(order++, 2, 'called in childTwo') + t.equal(this.pluginName, childTwo.pluginName, 'the this binding is the right instance') }) }) }) @@ -43,22 +43,22 @@ t.test('async onReady should be called in order', async t => { fastify.addHook('onReady', async function () { await immediate() - t.equals(order++, 0, 'called in root') - t.equals(this.pluginName, fastify.pluginName, 'the this binding is the right instance') + t.equal(order++, 0, 'called in root') + t.equal(this.pluginName, fastify.pluginName, 'the this binding is the right instance') }) fastify.register(async (childOne, o) => { childOne.addHook('onReady', async function () { await immediate() - t.equals(order++, 1, 'called in childOne') - t.equals(this.pluginName, childOne.pluginName, 'the this binding is the right instance') + t.equal(order++, 1, 'called in childOne') + t.equal(this.pluginName, childOne.pluginName, 'the this binding is the right instance') }) childOne.register(async (childTwo, o) => { childTwo.addHook('onReady', async function () { await immediate() - t.equals(order++, 2, 'called in childTwo') - t.equals(this.pluginName, childTwo.pluginName, 'the this binding is the right instance') + t.equal(order++, 2, 'called in childTwo') + t.equal(this.pluginName, childTwo.pluginName, 'the this binding is the right instance') }) }) }) @@ -78,10 +78,10 @@ t.test('mix ready and onReady', async t => { }) await fastify.ready() - t.equals(order, 1) + t.equal(order, 1) await fastify.ready() - t.equals(order, 1, 'ready hooks execute once') + t.equal(order, 1, 'ready hooks execute once') }) t.test('listen and onReady order', async t => { @@ -118,7 +118,7 @@ t.test('listen and onReady order', async t => { await fastify.close() function checkOrder (shouldbe) { - t.equals(order, shouldbe) + t.equal(order, shouldbe) order++ } }) @@ -138,7 +138,7 @@ t.test('multiple ready calls', async t => { subinstance.addHook('onReady', checkOrder.bind(null, 7)) }) - t.equals(order, 0, 'ready and hooks not triggered yet') + t.equal(order, 0, 'ready and hooks not triggered yet') order++ }) @@ -156,7 +156,7 @@ t.test('multiple ready calls', async t => { t.pass('do not trigger the onReady') function checkOrder (shouldbe) { - t.equals(order, shouldbe) + t.equal(order, shouldbe) order++ } }) @@ -185,7 +185,7 @@ t.test('onReady should manage error in sync', t => { fastify.ready(err => { t.ok(err) - t.equals(err.message, 'FAIL ON READY') + t.equal(err.message, 'FAIL ON READY') }) }) @@ -213,7 +213,7 @@ t.test('onReady should manage error in async', t => { fastify.ready(err => { t.ok(err) - t.equals(err.message, 'FAIL ON READY') + t.equal(err.message, 'FAIL ON READY') }) }) @@ -241,7 +241,7 @@ t.test('onReady should manage sync error', t => { fastify.ready(err => { t.ok(err) - t.equals(err.message, 'FAIL UNWANTED SYNC EXCEPTION') + t.equal(err.message, 'FAIL UNWANTED SYNC EXCEPTION') }) }) @@ -277,7 +277,7 @@ t.test('onReady cannot add lifecycle hooks', t => { fastify.addHook('onRequest', (request, reply, done) => {}) } catch (error) { t.ok(error) - t.equals(error.message, 'root plugin has already booted') + t.equal(error.message, 'root plugin has already booted') done(error) } }) @@ -295,7 +295,7 @@ t.test('onReady throw loading error', t => { try { fastify.addHook('onReady', async function (done) {}) } catch (e) { - t.true(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') + t.ok(e.message === 'Async function has too many arguments. Async hooks should not use the \'done\' argument.') } }) @@ -319,9 +319,9 @@ t.test('onReady execution order', t => { const fastify = Fastify({ }) let i = 0 - fastify.ready(() => { i++; t.equals(i, 1) }) - fastify.ready(() => { i++; t.equals(i, 2) }) - fastify.ready(() => { i++; t.equals(i, 3) }) + fastify.ready(() => { i++; t.equal(i, 1) }) + fastify.ready(() => { i++; t.equal(i, 2) }) + fastify.ready(() => { i++; t.equal(i, 3) }) }) t.test('ready return the server with callback', t => { @@ -330,7 +330,7 @@ t.test('ready return the server with callback', t => { fastify.ready((err, instance) => { t.error(err) - t.deepEquals(instance, fastify) + t.same(instance, fastify) }) }) @@ -339,7 +339,7 @@ t.test('ready return the server with Promise', t => { const fastify = Fastify() fastify.ready() - .then(instance => { t.deepEquals(instance, fastify) }) + .then(instance => { t.same(instance, fastify) }) .catch(err => { t.fail(err) }) }) @@ -348,21 +348,21 @@ t.test('ready return registered', t => { const fastify = Fastify() fastify.register((one, opts, done) => { - one.ready().then(itself => { t.deepEquals(itself, one) }) + one.ready().then(itself => { t.same(itself, one) }) done() }) fastify.register((two, opts, done) => { - two.ready().then(itself => { t.deepEquals(itself, two) }) + two.ready().then(itself => { t.same(itself, two) }) two.register((twoDotOne, opts, done) => { - twoDotOne.ready().then(itself => { t.deepEquals(itself, twoDotOne) }) + twoDotOne.ready().then(itself => { t.same(itself, twoDotOne) }) done() }) done() }) fastify.ready() - .then(instance => { t.deepEquals(instance, fastify) }) + .then(instance => { t.same(instance, fastify) }) .catch(err => { t.fail(err) }) }) diff --git a/test/hooks.test.js b/test/hooks.test.js index dc89e88694..ea83da990d 100644 --- a/test/hooks.test.js +++ b/test/hooks.test.js @@ -20,8 +20,8 @@ test('hooks', t => { try { fastify.addHook('preHandler', function (request, reply, done) { - t.is(request.test, 'the request is coming') - t.is(reply.test, 'the reply has come') + t.equal(request.test, 'the request is coming') + t.equal(reply.test, 'the reply has come') if (request.raw.method === 'HEAD') { done(new Error('some error')) } else { @@ -36,8 +36,8 @@ test('hooks', t => { try { fastify.addHook('preParsing', function (request, reply, payload, done) { request.preParsing = true - t.is(request.test, 'the request is coming') - t.is(reply.test, 'the reply has come') + t.equal(request.test, 'the request is coming') + t.equal(reply.test, 'the reply has come') done() }) t.pass() @@ -48,8 +48,8 @@ test('hooks', t => { try { fastify.addHook('preParsing', function (request, reply, done) { request.preParsing = true - t.is(request.test, 'the request is coming') - t.is(reply.test, 'the reply has come') + t.equal(request.test, 'the request is coming') + t.equal(reply.test, 'the reply has come') done() }) t.pass() @@ -59,9 +59,9 @@ test('hooks', t => { try { fastify.addHook('preValidation', function (request, reply, done) { - t.is(request.preParsing, true) - t.is(request.test, 'the request is coming') - t.is(reply.test, 'the reply has come') + t.equal(request.preParsing, true) + t.equal(request.test, 'the request is coming') + t.equal(reply.test, 'the reply has come') done() }) t.pass() @@ -108,8 +108,8 @@ test('hooks', t => { method: 'GET', url: '/', handler: function (req, reply) { - t.is(req.test, 'the request is coming') - t.is(reply.test, 'the reply has come') + t.equal(req.test, 'the request is coming') + t.equal(reply.test, 'the reply has come') reply.code(200).send(payload) }, onResponse: function (req, reply, done) { @@ -139,9 +139,9 @@ test('hooks', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -149,7 +149,7 @@ test('hooks', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) sget({ @@ -157,7 +157,7 @@ test('hooks', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) }) }) @@ -168,7 +168,7 @@ test('onRequest hook should support encapsulation / 1', t => { fastify.register((instance, opts, done) => { instance.addHook('onRequest', (req, reply, done) => { - t.strictEqual(req.raw.url, '/plugin') + t.equal(req.raw.url, '/plugin') done() }) @@ -185,12 +185,12 @@ test('onRequest hook should support encapsulation / 1', t => { fastify.inject('/root', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) fastify.inject('/plugin', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -209,8 +209,8 @@ test('onRequest hook should support encapsulation / 2', t => { fastify.ready(err => { t.error(err) - t.is(fastify[symbols.kHooks].onRequest.length, 1) - t.is(pluginInstance[symbols.kHooks].onRequest.length, 2) + t.equal(fastify[symbols.kHooks].onRequest.length, 1) + t.equal(pluginInstance[symbols.kHooks].onRequest.length, 2) }) }) @@ -262,9 +262,9 @@ test('onRequest hook should support encapsulation / 3', t => { url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -272,9 +272,9 @@ test('onRequest hook should support encapsulation / 3', t => { url: 'http://localhost:' + fastify.server.address().port + '/second' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -323,9 +323,9 @@ test('preHandler hook should support encapsulation / 5', t => { url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -333,9 +333,9 @@ test('preHandler hook should support encapsulation / 5', t => { url: 'http://localhost:' + fastify.server.address().port + '/second' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -380,8 +380,8 @@ test('onRoute hook should be called / 2', t => { done() }) .after(() => { - t.strictEqual(firstHandler, 1) - t.strictEqual(secondHandler, 1) + t.equal(firstHandler, 1) + t.equal(secondHandler, 1) }) fastify.ready(err => { @@ -502,7 +502,7 @@ test('onRoute should keep the context', t => { function onRoute (route) { t.ok(this.test) - t.strictEqual(this, instance) + t.equal(this, instance) } instance.get('/', opts, function (req, reply) { @@ -521,18 +521,18 @@ test('onRoute hook should pass correct route', t => { t.plan(9) const fastify = Fastify() fastify.addHook('onRoute', (route) => { - t.strictEqual(route.method, 'GET') - t.strictEqual(route.url, '/') - t.strictEqual(route.path, '/') - t.strictEqual(route.routePath, '/') + t.equal(route.method, 'GET') + t.equal(route.url, '/') + t.equal(route.path, '/') + t.equal(route.routePath, '/') }) fastify.register((instance, opts, done) => { instance.addHook('onRoute', (route) => { - t.strictEqual(route.method, 'GET') - t.strictEqual(route.url, '/') - t.strictEqual(route.path, '/') - t.strictEqual(route.routePath, '/') + t.equal(route.method, 'GET') + t.equal(route.url, '/') + t.equal(route.path, '/') + t.equal(route.routePath, '/') }) instance.get('/', opts, function (req, reply) { reply.send() @@ -549,20 +549,20 @@ test('onRoute hook should pass correct route with custom prefix', t => { t.plan(11) const fastify = Fastify() fastify.addHook('onRoute', function (route) { - t.strictEqual(route.method, 'GET') - t.strictEqual(route.url, '/v1/foo') - t.strictEqual(route.path, '/v1/foo') - t.strictEqual(route.routePath, '/foo') - t.strictEqual(route.prefix, '/v1') + t.equal(route.method, 'GET') + t.equal(route.url, '/v1/foo') + t.equal(route.path, '/v1/foo') + t.equal(route.routePath, '/foo') + t.equal(route.prefix, '/v1') }) fastify.register((instance, opts, done) => { instance.addHook('onRoute', function (route) { - t.strictEqual(route.method, 'GET') - t.strictEqual(route.url, '/v1/foo') - t.strictEqual(route.path, '/v1/foo') - t.strictEqual(route.routePath, '/foo') - t.strictEqual(route.prefix, '/v1') + t.equal(route.method, 'GET') + t.equal(route.url, '/v1/foo') + t.equal(route.path, '/v1/foo') + t.equal(route.routePath, '/foo') + t.equal(route.prefix, '/v1') }) instance.get('/foo', opts, function (req, reply) { reply.send() @@ -580,10 +580,10 @@ test('onRoute hook should pass correct route with custom options', t => { const fastify = Fastify() fastify.register((instance, opts, done) => { instance.addHook('onRoute', function (route) { - t.strictEqual(route.method, 'GET') - t.strictEqual(route.url, '/foo') - t.strictEqual(route.logLevel, 'info') - t.strictEqual(route.bodyLimit, 100) + t.equal(route.method, 'GET') + t.equal(route.url, '/foo') + t.equal(route.logLevel, 'info') + t.equal(route.bodyLimit, 100) t.type(route.logSerializers.test, 'function') }) instance.get('/foo', { @@ -608,10 +608,10 @@ test('onRoute hook should receive any route option', t => { const fastify = Fastify() fastify.register((instance, opts, done) => { instance.addHook('onRoute', function (route) { - t.strictEqual(route.method, 'GET') - t.strictEqual(route.url, '/foo') - t.strictEqual(route.routePath, '/foo') - t.strictEqual(route.auth, 'basic') + t.equal(route.method, 'GET') + t.equal(route.url, '/foo') + t.equal(route.routePath, '/foo') + t.equal(route.auth, 'basic') }) instance.get('/foo', { auth: 'basic' }, function (req, reply) { reply.send() @@ -629,10 +629,10 @@ test('onRoute hook should preserve system route configuration', t => { const fastify = Fastify() fastify.register((instance, opts, done) => { instance.addHook('onRoute', function (route) { - t.strictEqual(route.method, 'GET') - t.strictEqual(route.url, '/foo') - t.strictEqual(route.routePath, '/foo') - t.strictEqual(route.handler.length, 2) + t.equal(route.method, 'GET') + t.equal(route.url, '/foo') + t.equal(route.routePath, '/foo') + t.equal(route.handler.length, 2) }) instance.get('/foo', { url: '/bar', method: 'POST' }, function (req, reply) { reply.send() @@ -653,7 +653,7 @@ test('onRoute hook should preserve handler function in options of shorthand rout const fastify = Fastify() fastify.register((instance, opts, done) => { instance.addHook('onRoute', function (route) { - t.strictEqual(route.handler, handler) + t.equal(route.handler, handler) }) instance.get('/foo', { handler }) done() @@ -702,8 +702,8 @@ test('onRoute hook should be called once when prefixTrailingSlash', t => { fastify.ready(err => { t.error(err) - t.is(onRouteCalled, 1) // onRoute hook was called once - t.is(routePatched, 1) // and plugin acted once and avoided redundaunt route patching + t.equal(onRouteCalled, 1) // onRoute hook was called once + t.equal(routePatched, 1) // and plugin acted once and avoided redundaunt route patching }) }) @@ -714,7 +714,7 @@ test('onRoute hook should able to change the route url', t => { fastify.register((instance, opts, done) => { instance.addHook('onRoute', (route) => { - t.strictEqual(route.url, '/föö') + t.equal(route.url, '/föö') route.url = encodeURI(route.url) }) @@ -734,8 +734,8 @@ test('onRoute hook should able to change the route url', t => { url: 'http://localhost:' + fastify.server.address().port + encodeURI('/föö') }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(body.toString(), 'here /föö') + t.equal(response.statusCode, 200) + t.equal(body.toString(), 'here /föö') }) }) }) @@ -771,7 +771,7 @@ test('onRoute hook with many prefix', t => { fastify.register((instance, opts, done) => { instance.addHook('onRoute', (route) => { - t.like(route, onRouteChecks.pop()) + t.match(route, onRouteChecks.pop()) }) instance.route({ method: 'GET', url: '/aPath', handler }) @@ -816,7 +816,7 @@ test('onResponse hook should log request error', t => { fastify.inject('/root', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -826,7 +826,7 @@ test('onResponse hook should support encapsulation / 1', t => { fastify.register((instance, opts, done) => { instance.addHook('onResponse', (request, reply, done) => { - t.strictEqual(reply.plugin, true) + t.equal(reply.plugin, true) done() }) @@ -844,12 +844,12 @@ test('onResponse hook should support encapsulation / 1', t => { fastify.inject('/root', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) fastify.inject('/plugin', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -868,8 +868,8 @@ test('onResponse hook should support encapsulation / 2', t => { fastify.ready(err => { t.error(err) - t.is(fastify[symbols.kHooks].onResponse.length, 1) - t.is(pluginInstance[symbols.kHooks].onResponse.length, 2) + t.equal(fastify[symbols.kHooks].onResponse.length, 1) + t.equal(pluginInstance[symbols.kHooks].onResponse.length, 2) }) }) @@ -913,9 +913,9 @@ test('onResponse hook should support encapsulation / 3', t => { url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -923,9 +923,9 @@ test('onResponse hook should support encapsulation / 3', t => { url: 'http://localhost:' + fastify.server.address().port + '/second' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -945,8 +945,8 @@ test('onSend hook should support encapsulation / 1', t => { fastify.ready(err => { t.error(err) - t.is(fastify[symbols.kHooks].onSend.length, 1) - t.is(pluginInstance[symbols.kHooks].onSend.length, 2) + t.equal(fastify[symbols.kHooks].onSend.length, 1) + t.equal(pluginInstance[symbols.kHooks].onSend.length, 2) }) }) @@ -990,9 +990,9 @@ test('onSend hook should support encapsulation / 2', t => { url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -1000,9 +1000,9 @@ test('onSend hook should support encapsulation / 2', t => { url: 'http://localhost:' + fastify.server.address().port + '/second' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -1015,8 +1015,8 @@ test('onSend hook is called after payload is serialized and headers are set', t const thePayload = { hello: 'world' } instance.addHook('onSend', function (request, reply, payload, done) { - t.deepEqual(JSON.parse(payload), thePayload) - t.strictEqual(reply[symbols.kReplyHeaders]['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(payload), thePayload) + t.equal(reply[symbols.kReplyHeaders]['content-type'], 'application/json; charset=utf-8') done() }) @@ -1029,8 +1029,8 @@ test('onSend hook is called after payload is serialized and headers are set', t fastify.register((instance, opts, done) => { instance.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(payload, 'some text') - t.strictEqual(reply[symbols.kReplyHeaders]['content-type'], 'text/plain; charset=utf-8') + t.equal(payload, 'some text') + t.equal(reply[symbols.kReplyHeaders]['content-type'], 'text/plain; charset=utf-8') done() }) @@ -1045,8 +1045,8 @@ test('onSend hook is called after payload is serialized and headers are set', t const thePayload = Buffer.from('buffer payload') instance.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(payload, thePayload) - t.strictEqual(reply[symbols.kReplyHeaders]['content-type'], 'application/octet-stream') + t.equal(payload, thePayload) + t.equal(reply[symbols.kReplyHeaders]['content-type'], 'application/octet-stream') done() }) @@ -1067,8 +1067,8 @@ test('onSend hook is called after payload is serialized and headers are set', t }) instance.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(payload, thePayload) - t.strictEqual(reply[symbols.kReplyHeaders]['content-type'], 'application/octet-stream') + t.equal(payload, thePayload) + t.equal(reply[symbols.kReplyHeaders]['content-type'], 'application/octet-stream') done() }) @@ -1083,8 +1083,8 @@ test('onSend hook is called after payload is serialized and headers are set', t const serializedPayload = 'serialized' instance.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(payload, serializedPayload) - t.strictEqual(reply[symbols.kReplyHeaders]['content-type'], 'text/custom') + t.equal(payload, serializedPayload) + t.equal(reply[symbols.kReplyHeaders]['content-type'], 'text/custom') done() }) @@ -1103,9 +1103,9 @@ test('onSend hook is called after payload is serialized and headers are set', t url: '/json' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.headers['content-length'], '17') + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.headers['content-length'], '17') }) fastify.inject({ @@ -1113,9 +1113,9 @@ test('onSend hook is called after payload is serialized and headers are set', t url: '/text' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(res.payload, 'some text') - t.strictEqual(res.headers['content-length'], '9') + t.equal(res.statusCode, 200) + t.same(res.payload, 'some text') + t.equal(res.headers['content-length'], '9') }) fastify.inject({ @@ -1123,9 +1123,9 @@ test('onSend hook is called after payload is serialized and headers are set', t url: '/buffer' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(res.payload, 'buffer payload') - t.strictEqual(res.headers['content-length'], '14') + t.equal(res.statusCode, 200) + t.same(res.payload, 'buffer payload') + t.equal(res.headers['content-length'], '14') }) fastify.inject({ @@ -1133,9 +1133,9 @@ test('onSend hook is called after payload is serialized and headers are set', t url: '/stream' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(res.payload, 'stream payload') - t.strictEqual(res.headers['transfer-encoding'], 'chunked') + t.equal(res.statusCode, 200) + t.same(res.payload, 'stream payload') + t.equal(res.headers['transfer-encoding'], 'chunked') }) fastify.inject({ @@ -1143,9 +1143,9 @@ test('onSend hook is called after payload is serialized and headers are set', t url: '/custom-serializer' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(res.payload, 'serialized') - t.strictEqual(res.headers['content-type'], 'text/custom') + t.equal(res.statusCode, 200) + t.same(res.payload, 'serialized') + t.equal(res.headers['content-type'], 'text/custom') }) }) @@ -1158,20 +1158,20 @@ test('modify payload', t => { fastify.addHook('onSend', function (request, reply, thePayload, done) { t.ok('onSend called') - t.deepEqual(JSON.parse(thePayload), payload) + t.same(JSON.parse(thePayload), payload) thePayload = thePayload.replace('world', 'modified') done(null, thePayload) }) fastify.addHook('onSend', function (request, reply, thePayload, done) { t.ok('onSend called') - t.deepEqual(JSON.parse(thePayload), modifiedPayload) + t.same(JSON.parse(thePayload), modifiedPayload) done(null, anotherPayload) }) fastify.addHook('onSend', function (request, reply, thePayload, done) { t.ok('onSend called') - t.strictEqual(thePayload, anotherPayload) + t.equal(thePayload, anotherPayload) done() }) @@ -1184,9 +1184,9 @@ test('modify payload', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, anotherPayload) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '18') + t.equal(res.payload, anotherPayload) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '18') }) }) @@ -1209,10 +1209,10 @@ test('clear payload', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 304) - t.strictEqual(res.payload, '') - t.strictEqual(res.headers['content-length'], undefined) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') + t.equal(res.statusCode, 304) + t.equal(res.payload, '') + t.equal(res.headers['content-length'], undefined) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') }) }) @@ -1252,23 +1252,23 @@ test('onSend hook throws', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ method: 'DELETE', url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) sget({ method: 'PUT', url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) }) }) @@ -1285,8 +1285,8 @@ test('onSend hook should receive valid request and reply objects if onRequest ho }) fastify.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(request.testDecorator, 'testDecoratorVal') - t.strictEqual(reply.testDecorator, 'testDecoratorVal') + t.equal(request.testDecorator, 'testDecoratorVal') + t.equal(reply.testDecorator, 'testDecoratorVal') done() }) @@ -1299,7 +1299,7 @@ test('onSend hook should receive valid request and reply objects if onRequest ho url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) + t.equal(res.statusCode, 500) }) }) @@ -1315,8 +1315,8 @@ test('onSend hook should receive valid request and reply objects if a custom con }) fastify.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(request.testDecorator, 'testDecoratorVal') - t.strictEqual(reply.testDecorator, 'testDecoratorVal') + t.equal(request.testDecorator, 'testDecoratorVal') + t.equal(reply.testDecorator, 'testDecoratorVal') done() }) @@ -1330,7 +1330,7 @@ test('onSend hook should receive valid request and reply objects if a custom con payload: 'body' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) + t.equal(res.statusCode, 500) }) }) @@ -1344,7 +1344,7 @@ test('cannot add hook after binding', t => { instance.listen(0, err => { t.error(err) - t.tearDown(instance.server.close.bind(instance.server)) + t.teardown(instance.server.close.bind(instance.server)) try { instance.addHook('onRequest', () => {}) @@ -1391,8 +1391,8 @@ test('onRequest hooks should be able to block a request', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -1432,8 +1432,8 @@ test('preValidation hooks should be able to block a request', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -1479,8 +1479,8 @@ test('preValidation hooks should be able to change request body before validatio } }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -1520,8 +1520,8 @@ test('preParsing hooks should be able to block a request', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -1557,8 +1557,8 @@ test('preHandler hooks should be able to block a request', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -1594,8 +1594,8 @@ test('onRequest hooks should be able to block a request (last hook)', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -1627,8 +1627,8 @@ test('preHandler hooks should be able to block a request (last hook)', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.is(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -1652,8 +1652,8 @@ test('preParsing hooks should handle errors', t => { payload: { hello: 'world' } }, (err, res) => { t.error(err) - t.is(res.statusCode, 501) - t.deepEqual(JSON.parse(res.payload), { error: 'Not Implemented', message: 'kaboom', statusCode: 501 }) + t.equal(res.statusCode, 501) + t.same(JSON.parse(res.payload), { error: 'Not Implemented', message: 'kaboom', statusCode: 501 }) }) }) @@ -1695,7 +1695,7 @@ test('onRequest respond with a stream', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -1716,7 +1716,7 @@ test('preHandler respond with a stream', t => { const stream = fs.createReadStream(process.cwd() + '/test/stream.test.js', 'utf8') reply.send(stream) reply.raw.once('finish', () => { - t.is(order.shift(), 2) + t.equal(order.shift(), 2) done() }) }) @@ -1726,8 +1726,8 @@ test('preHandler respond with a stream', t => { }) fastify.addHook('onSend', (req, reply, payload, done) => { - t.is(order.shift(), 1) - t.is(typeof payload.pipe, 'function') + t.equal(order.shift(), 1) + t.equal(typeof payload.pipe, 'function') done() }) @@ -1745,7 +1745,7 @@ test('preHandler respond with a stream', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -1785,8 +1785,8 @@ test('Register an hook after a plugin inside a plugin', t => { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) }) }) @@ -1831,8 +1831,8 @@ test('Register an hook after a plugin inside a plugin (with preHandler option)', method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) }) }) @@ -1874,8 +1874,8 @@ test('Register hooks inside a plugin after an encapsulated plugin', t => { fastify.inject('/', (err, res) => { t.error(err) - t.is(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) }) }) @@ -1885,19 +1885,19 @@ test('onRequest hooks should run in the order in which they are defined', t => { fastify.register(function (instance, opts, done) { instance.addHook('onRequest', function (req, reply, done) { - t.strictEqual(req.previous, undefined) + t.equal(req.previous, undefined) req.previous = 1 done() }) instance.get('/', function (request, reply) { - t.strictEqual(request.previous, 5) + t.equal(request.previous, 5) reply.send({ hello: 'world' }) }) instance.register(fp(function (i, opts, done) { i.addHook('onRequest', function (req, reply, done) { - t.strictEqual(req.previous, 1) + t.equal(req.previous, 1) req.previous = 2 done() }) @@ -1909,14 +1909,14 @@ test('onRequest hooks should run in the order in which they are defined', t => { fastify.register(fp(function (instance, opts, done) { instance.addHook('onRequest', function (req, reply, done) { - t.strictEqual(req.previous, 2) + t.equal(req.previous, 2) req.previous = 3 done() }) instance.register(fp(function (i, opts, done) { i.addHook('onRequest', function (req, reply, done) { - t.strictEqual(req.previous, 3) + t.equal(req.previous, 3) req.previous = 4 done() }) @@ -1924,7 +1924,7 @@ test('onRequest hooks should run in the order in which they are defined', t => { })) instance.addHook('onRequest', function (req, reply, done) { - t.strictEqual(req.previous, 4) + t.equal(req.previous, 4) req.previous = 5 done() }) @@ -1934,8 +1934,8 @@ test('onRequest hooks should run in the order in which they are defined', t => { fastify.inject('/', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) }) }) @@ -1945,19 +1945,19 @@ test('preHandler hooks should run in the order in which they are defined', t => fastify.register(function (instance, opts, done) { instance.addHook('preHandler', function (request, reply, done) { - t.strictEqual(request.previous, undefined) + t.equal(request.previous, undefined) request.previous = 1 done() }) instance.get('/', function (request, reply) { - t.strictEqual(request.previous, 5) + t.equal(request.previous, 5) reply.send({ hello: 'world' }) }) instance.register(fp(function (i, opts, done) { i.addHook('preHandler', function (request, reply, done) { - t.strictEqual(request.previous, 1) + t.equal(request.previous, 1) request.previous = 2 done() }) @@ -1969,14 +1969,14 @@ test('preHandler hooks should run in the order in which they are defined', t => fastify.register(fp(function (instance, opts, done) { instance.addHook('preHandler', function (request, reply, done) { - t.strictEqual(request.previous, 2) + t.equal(request.previous, 2) request.previous = 3 done() }) instance.register(fp(function (i, opts, done) { i.addHook('preHandler', function (request, reply, done) { - t.strictEqual(request.previous, 3) + t.equal(request.previous, 3) request.previous = 4 done() }) @@ -1984,7 +1984,7 @@ test('preHandler hooks should run in the order in which they are defined', t => })) instance.addHook('preHandler', function (request, reply, done) { - t.strictEqual(request.previous, 4) + t.equal(request.previous, 4) request.previous = 5 done() }) @@ -1994,8 +1994,8 @@ test('preHandler hooks should run in the order in which they are defined', t => fastify.inject('/', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) }) }) @@ -2005,7 +2005,7 @@ test('onSend hooks should run in the order in which they are defined', t => { fastify.register(function (instance, opts, done) { instance.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(request.previous, undefined) + t.equal(request.previous, undefined) request.previous = 1 done() }) @@ -2016,7 +2016,7 @@ test('onSend hooks should run in the order in which they are defined', t => { instance.register(fp(function (i, opts, done) { i.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(request.previous, 1) + t.equal(request.previous, 1) request.previous = 2 done() }) @@ -2028,14 +2028,14 @@ test('onSend hooks should run in the order in which they are defined', t => { fastify.register(fp(function (instance, opts, done) { instance.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(request.previous, 2) + t.equal(request.previous, 2) request.previous = 3 done() }) instance.register(fp(function (i, opts, done) { i.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(request.previous, 3) + t.equal(request.previous, 3) request.previous = 4 done() }) @@ -2043,7 +2043,7 @@ test('onSend hooks should run in the order in which they are defined', t => { })) instance.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(request.previous, 4) + t.equal(request.previous, 4) done(null, '5') }) @@ -2052,8 +2052,8 @@ test('onSend hooks should run in the order in which they are defined', t => { fastify.inject('/', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), 5) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), 5) }) }) @@ -2063,7 +2063,7 @@ test('onResponse hooks should run in the order in which they are defined', t => fastify.register(function (instance, opts, done) { instance.addHook('onResponse', function (request, reply, done) { - t.strictEqual(reply.previous, undefined) + t.equal(reply.previous, undefined) reply.previous = 1 done() }) @@ -2074,7 +2074,7 @@ test('onResponse hooks should run in the order in which they are defined', t => instance.register(fp(function (i, opts, done) { i.addHook('onResponse', function (request, reply, done) { - t.strictEqual(reply.previous, 1) + t.equal(reply.previous, 1) reply.previous = 2 done() }) @@ -2086,14 +2086,14 @@ test('onResponse hooks should run in the order in which they are defined', t => fastify.register(fp(function (instance, opts, done) { instance.addHook('onResponse', function (request, reply, done) { - t.strictEqual(reply.previous, 2) + t.equal(reply.previous, 2) reply.previous = 3 done() }) instance.register(fp(function (i, opts, done) { i.addHook('onResponse', function (request, reply, done) { - t.strictEqual(reply.previous, 3) + t.equal(reply.previous, 3) reply.previous = 4 done() }) @@ -2101,7 +2101,7 @@ test('onResponse hooks should run in the order in which they are defined', t => })) instance.addHook('onResponse', function (request, reply, done) { - t.strictEqual(reply.previous, 4) + t.equal(reply.previous, 4) done() }) @@ -2110,8 +2110,8 @@ test('onResponse hooks should run in the order in which they are defined', t => fastify.inject('/', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) }) }) @@ -2135,8 +2135,8 @@ test('onRequest, preHandler, and onResponse hooks that resolve to a value do not fastify.inject('/', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.payload, 'hello') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -2155,10 +2155,10 @@ test('If a response header has been set inside an hook it shoulod not be overwri fastify.inject('/', (err, res) => { t.error(err) - t.strictEqual(res.headers['x-custom-header'], 'hello') - t.strictEqual(res.headers['content-type'], 'text/plain; charset=utf-8') - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.payload, 'hello') + t.equal(res.headers['x-custom-header'], 'hello') + t.equal(res.headers['content-type'], 'text/plain; charset=utf-8') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -2178,9 +2178,9 @@ test('If the content type has been set inside an hook it should not be changed', fastify.inject('/', (err, res) => { t.error(err) - t.strictEqual(res.headers['content-type'], 'text/html') - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.payload, 'hello') + t.equal(res.headers['content-type'], 'text/html') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'hello') }) }) @@ -2189,10 +2189,10 @@ test('request in onRequest, preParsing, preValidation and onResponse', t => { const fastify = Fastify() fastify.addHook('onRequest', function (request, reply, done) { - t.deepEqual(request.body, null) - t.deepEqual(request.query, { key: 'value' }) - t.deepEqual(request.params, { greeting: 'hello' }) - t.deepEqual(request.headers, { + t.same(request.body, null) + t.same(request.query, { key: 'value' }) + t.same(request.params, { greeting: 'hello' }) + t.same(request.headers, { 'content-length': '17', 'content-type': 'application/json', host: 'localhost:80', @@ -2203,10 +2203,10 @@ test('request in onRequest, preParsing, preValidation and onResponse', t => { }) fastify.addHook('preParsing', function (request, reply, payload, done) { - t.deepEqual(request.body, null) - t.deepEqual(request.query, { key: 'value' }) - t.deepEqual(request.params, { greeting: 'hello' }) - t.deepEqual(request.headers, { + t.same(request.body, null) + t.same(request.query, { key: 'value' }) + t.same(request.params, { greeting: 'hello' }) + t.same(request.headers, { 'content-length': '17', 'content-type': 'application/json', host: 'localhost:80', @@ -2217,10 +2217,10 @@ test('request in onRequest, preParsing, preValidation and onResponse', t => { }) fastify.addHook('preValidation', function (request, reply, done) { - t.deepEqual(request.body, { hello: 'world' }) - t.deepEqual(request.query, { key: 'value' }) - t.deepEqual(request.params, { greeting: 'hello' }) - t.deepEqual(request.headers, { + t.same(request.body, { hello: 'world' }) + t.same(request.query, { key: 'value' }) + t.same(request.params, { greeting: 'hello' }) + t.same(request.headers, { 'content-length': '17', 'content-type': 'application/json', host: 'localhost:80', @@ -2231,10 +2231,10 @@ test('request in onRequest, preParsing, preValidation and onResponse', t => { }) fastify.addHook('onResponse', function (request, reply, done) { - t.deepEqual(request.body, { hello: 'world' }) - t.deepEqual(request.query, { key: 'value' }) - t.deepEqual(request.params, { greeting: 'hello' }) - t.deepEqual(request.headers, { + t.same(request.body, { hello: 'world' }) + t.same(request.query, { key: 'value' }) + t.same(request.params, { greeting: 'hello' }) + t.same(request.headers, { 'content-length': '17', 'content-type': 'application/json', host: 'localhost:80', @@ -2255,7 +2255,7 @@ test('request in onRequest, preParsing, preValidation and onResponse', t => { payload: { hello: 'world' } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -2265,7 +2265,7 @@ test('preValidation hook should support encapsulation / 1', t => { fastify.register((instance, opts, done) => { instance.addHook('preValidation', (req, reply, done) => { - t.strictEqual(req.raw.url, '/plugin') + t.equal(req.raw.url, '/plugin') done() }) @@ -2282,12 +2282,12 @@ test('preValidation hook should support encapsulation / 1', t => { fastify.inject('/root', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) fastify.inject('/plugin', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -2306,8 +2306,8 @@ test('preValidation hook should support encapsulation / 2', t => { fastify.ready(err => { t.error(err) - t.is(fastify[symbols.kHooks].preValidation.length, 1) - t.is(pluginInstance[symbols.kHooks].preValidation.length, 2) + t.equal(fastify[symbols.kHooks].preValidation.length, 1) + t.equal(pluginInstance[symbols.kHooks].preValidation.length, 2) }) }) @@ -2359,9 +2359,9 @@ test('preValidation hook should support encapsulation / 3', t => { url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -2369,9 +2369,9 @@ test('preValidation hook should support encapsulation / 3', t => { url: 'http://localhost:' + fastify.server.address().port + '/second' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -2397,7 +2397,7 @@ test('onError hook', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { + t.same(JSON.parse(res.payload), { error: 'Internal Server Error', message: 'kaboom', statusCode: 500 @@ -2417,7 +2417,7 @@ test('reply.send should throw if called inside the onError hook', t => { reply.send() t.fail('Should throw') } catch (err) { - t.is(err.code, 'FST_ERR_SEND_INSIDE_ONERR') + t.equal(err.code, 'FST_ERR_SEND_INSIDE_ONERR') } done() }) @@ -2431,7 +2431,7 @@ test('reply.send should throw if called inside the onError hook', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { + t.same(JSON.parse(res.payload), { error: 'Internal Server Error', message: 'kaboom', statusCode: 500 @@ -2465,7 +2465,7 @@ test('onError hook with setErrorHandler', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { + t.same(JSON.parse(res.payload), { error: 'Internal Server Error', message: 'ouch', statusCode: 500 @@ -2495,7 +2495,7 @@ test('onError hook with setErrorHandler', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual( + t.same( JSON.parse(res.payload), { hello: 'world' } ) @@ -2535,9 +2535,9 @@ test('preParsing hook should run before parsing and be able to modify the payloa json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + JSON.stringify(body).length) - t.deepEqual(body, { hello: 'another world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + JSON.stringify(body).length) + t.same(body, { hello: 'another world' }) }) }) }) @@ -2550,8 +2550,8 @@ test('preParsing hooks can completely ignore the payload - deprecated syntax', t warning.emitted.delete('FSTDEP004') function onWarning (warning) { - t.strictEqual(warning.name, 'FastifyDeprecation') - t.strictEqual(warning.code, 'FSTDEP004') + t.equal(warning.name, 'FastifyDeprecation') + t.equal(warning.code, 'FSTDEP004') } fastify.addHook('preParsing', (req, reply, done) => { @@ -2569,7 +2569,7 @@ test('preParsing hooks can completely ignore the payload - deprecated syntax', t }, (err, res) => { t.error(err) t.equal(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.same(JSON.parse(res.payload), { hello: 'world' }) }) }) @@ -2609,9 +2609,9 @@ test('preParsing hooks should run in the order in which they are defined', t => json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + JSON.stringify(body).length) - t.deepEqual(body, { hello: 'another world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + JSON.stringify(body).length) + t.same(body, { hello: 'another world' }) }) }) }) @@ -2659,9 +2659,9 @@ test('preParsing hooks should support encapsulation', t => { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + JSON.stringify(body).length) - t.deepEqual(body, { hello: 'another world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + JSON.stringify(body).length) + t.same(body, { hello: 'another world' }) }) sget({ @@ -2671,9 +2671,9 @@ test('preParsing hooks should support encapsulation', t => { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + JSON.stringify(body).length) - t.deepEqual(body, { hello: 'encapsulated world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + JSON.stringify(body).length) + t.same(body, { hello: 'encapsulated world' }) }) }) }) @@ -2684,7 +2684,7 @@ test('preParsing hook should support encapsulation / 1', t => { fastify.register((instance, opts, done) => { instance.addHook('preParsing', (req, reply, payload, done) => { - t.strictEqual(req.raw.url, '/plugin') + t.equal(req.raw.url, '/plugin') done() }) @@ -2701,12 +2701,12 @@ test('preParsing hook should support encapsulation / 1', t => { fastify.inject('/root', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) fastify.inject('/plugin', (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -2725,8 +2725,8 @@ test('preParsing hook should support encapsulation / 2', t => { fastify.ready(err => { t.error(err) - t.is(fastify[symbols.kHooks].preParsing.length, 1) - t.is(pluginInstance[symbols.kHooks].preParsing.length, 2) + t.equal(fastify[symbols.kHooks].preParsing.length, 1) + t.equal(pluginInstance[symbols.kHooks].preParsing.length, 2) }) }) @@ -2778,9 +2778,9 @@ test('preParsing hook should support encapsulation / 3', t => { url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -2788,9 +2788,9 @@ test('preParsing hook should support encapsulation / 3', t => { url: 'http://localhost:' + fastify.server.address().port + '/second' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -2840,9 +2840,9 @@ test('preSerialization hook should run before serialization and be able to modif url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world1', world: 'ok' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world1', world: 'ok' }) }) }) }) @@ -2855,7 +2855,7 @@ test('preSerialization hook should be able to throw errors which are validated a }) fastify.setErrorHandler((err, request, reply) => { - t.equals(err.message, 'preSerialization aborted') + t.equal(err.message, 'preSerialization aborted') err.world = 'error' reply.send(err) }) @@ -2891,9 +2891,9 @@ test('preSerialization hook should be able to throw errors which are validated a url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { world: 'error' }) + t.equal(response.statusCode, 500) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { world: 'error' }) t.end() }) }) @@ -2925,7 +2925,7 @@ test('preSerialization hook which returned error should still run onError hooks' url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) }) }) @@ -2959,9 +2959,9 @@ test('preSerialization hooks should run in the order in which they are defined', url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world21' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world21' }) }) }) }) @@ -3003,9 +3003,9 @@ test('preSerialization hooks should support encapsulation', t => { url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world1' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world1' }) }) sget({ @@ -3013,9 +3013,9 @@ test('preSerialization hooks should support encapsulation', t => { url: 'http://localhost:' + fastify.server.address().port + '/second' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world12' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world12' }) }) }) }) @@ -3027,7 +3027,7 @@ test('onRegister hook should be called / 1', t => { fastify.addHook('onRegister', (instance, opts) => { // duck typing for the win! t.ok(instance.addHook) - t.deepEquals(opts, pluginOpts) + t.same(opts, pluginOpts) }) const pluginOpts = { prefix: 'hello', custom: 'world' } @@ -3077,15 +3077,15 @@ test('onRegister hook should be called / 3', t => { instance.data.push(1) instance.register((instance, opts, done) => { instance.data.push(2) - t.deepEqual(instance.data, [1, 2]) + t.same(instance.data, [1, 2]) done() }) - t.deepEqual(instance.data, [1]) + t.same(instance.data, [1]) done() }) fastify.register((instance, opts, done) => { - t.deepEqual(instance.data, []) + t.same(instance.data, []) done() }) @@ -3130,8 +3130,8 @@ test('early termination, onRequest', t => { app.inject('/', function (err, res) { t.error(err) - t.is(res.statusCode, 200) - t.is(res.body.toString(), 'hello world') + t.equal(res.statusCode, 200) + t.equal(res.body.toString(), 'hello world') }) }) @@ -3154,8 +3154,8 @@ test('reply.send should throw if undefined error is thrown', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 500) + t.same(JSON.parse(res.payload), { error: 'Internal Server Error', code: 'FST_ERR_SEND_UNDEFINED_ERR', message: 'Undefined error has occured', @@ -3182,21 +3182,21 @@ test('onTimeout should be triggered', t => { fastify.listen(0, (err, address) => { t.error(err) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) sget({ method: 'GET', url: address }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) sget({ method: 'GET', url: `${address}/timeout` }, (err, response, body) => { t.type(err, Error) - t.strictEqual(err.message, 'socket hang up') + t.equal(err.message, 'socket hang up') }) }) }) diff --git a/test/http2/closing.test.js b/test/http2/closing.test.js index cac8b2041f..24511f85eb 100644 --- a/test/http2/closing.test.js +++ b/test/http2/closing.test.js @@ -35,7 +35,7 @@ t.test('http/2 request while fastify closing', t => { ':method': 'GET', ':path': '/' }).on('response', headers => { - t.strictEqual(headers[':status'], 503) + t.equal(headers[':status'], 503) t.end() this.destroy() }).on('error', () => { @@ -83,7 +83,7 @@ t.test('http/2 request while fastify closing - return503OnClosing: false', t => ':method': 'GET', ':path': '/' }).on('response', headers => { - t.strictEqual(headers[':status'], 200) + t.equal(headers[':status'], 200) t.end() this.destroy() }).on('error', () => { @@ -166,7 +166,7 @@ t.test('http/2 server side session emits a timeout event', { skip: semver.lt(pro }).end() const [headers] = await once(req, 'response') - t.strictEqual(headers[':status'], 200) + t.equal(headers[':status'], 200) req.resume() // An error might or might not happen, as it's OS dependent. diff --git a/test/http2/head.test.js b/test/http2/head.test.js index 42804d538d..1461a48759 100644 --- a/test/http2/head.test.js +++ b/test/http2/head.test.js @@ -30,6 +30,6 @@ fastify.listen(0, err => { const url = `http://localhost:${fastify.server.address().port}` const res = await h2url.concat({ url, method: 'HEAD' }) - t.strictEqual(res.headers[':status'], 200) + t.equal(res.headers[':status'], 200) }) }) diff --git a/test/http2/missing-http2-module.test.js b/test/http2/missing-http2-module.test.js index d2575ea4ce..ab9a5caf77 100644 --- a/test/http2/missing-http2-module.test.js +++ b/test/http2/missing-http2-module.test.js @@ -12,7 +12,7 @@ test('should throw when http2 module cannot be found', t => { Fastify({ http2: true }) t.fail('fastify did not throw expected error') } catch (err) { - t.is(err.code, 'FST_ERR_HTTP2_INVALID_VERSION') + t.equal(err.code, 'FST_ERR_HTTP2_INVALID_VERSION') t.equal(err.message, 'HTTP2 is available only from node >= 8.8.1') } }) diff --git a/test/http2/plain.test.js b/test/http2/plain.test.js index 79102a7b52..bf7afc90ea 100644 --- a/test/http2/plain.test.js +++ b/test/http2/plain.test.js @@ -34,10 +34,10 @@ fastify.listen(0, err => { const url = `http://localhost:${fastify.server.address().port}` const res = await h2url.concat({ url }) - t.strictEqual(res.headers[':status'], 200) - t.strictEqual(res.headers['content-length'], '' + JSON.stringify(msg).length) + t.equal(res.headers[':status'], 200) + t.equal(res.headers['content-length'], '' + JSON.stringify(msg).length) - t.deepEqual(JSON.parse(res.body), msg) + t.same(JSON.parse(res.body), msg) }) test('http hostname', async (t) => { @@ -48,6 +48,6 @@ fastify.listen(0, err => { const url = `http://${hostname}/hostname` const res = await h2url.concat({ url }) - t.strictEqual(res.body, hostname) + t.equal(res.body, hostname) }) }) diff --git a/test/http2/secure-with-fallback.test.js b/test/http2/secure-with-fallback.test.js index 32a0b15efd..46c04d67ee 100644 --- a/test/http2/secure-with-fallback.test.js +++ b/test/http2/secure-with-fallback.test.js @@ -46,7 +46,7 @@ fastify.listen(0, err => { const url = `https://localhost:${fastify.server.address().port}/error` const res = await h2url.concat({ url }) - t.strictEqual(res.headers[':status'], 500) + t.equal(res.headers[':status'], 500) }) test('https post', async (t) => { @@ -62,8 +62,8 @@ fastify.listen(0, err => { } }) - t.strictEqual(res.headers[':status'], 200) - t.deepEqual(JSON.parse(res.body), { hello: 'http2' }) + t.equal(res.headers[':status'], 200) + t.same(JSON.parse(res.body), { hello: 'http2' }) }) test('https get request', async (t) => { @@ -72,9 +72,9 @@ fastify.listen(0, err => { const url = `https://localhost:${fastify.server.address().port}` const res = await h2url.concat({ url }) - t.strictEqual(res.headers[':status'], 200) - t.strictEqual(res.headers['content-length'], '' + JSON.stringify(msg).length) - t.deepEqual(JSON.parse(res.body), msg) + t.equal(res.headers[':status'], 200) + t.equal(res.headers['content-length'], '' + JSON.stringify(msg).length) + t.same(JSON.parse(res.body), msg) }) test('http1 get request', t => { @@ -85,9 +85,9 @@ fastify.listen(0, err => { rejectUnauthorized: false }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -99,7 +99,7 @@ fastify.listen(0, err => { rejectUnauthorized: false }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) }) }) diff --git a/test/http2/secure.test.js b/test/http2/secure.test.js index 8e3a20b34c..75621f28a8 100644 --- a/test/http2/secure.test.js +++ b/test/http2/secure.test.js @@ -39,16 +39,16 @@ fastify.listen(0, err => { const url = `https://localhost:${fastify.server.address().port}` const res = await h2url.concat({ url }) - t.strictEqual(res.headers[':status'], 200) - t.strictEqual(res.headers['content-length'], '' + JSON.stringify(msg).length) - t.deepEqual(JSON.parse(res.body), msg) + t.equal(res.headers[':status'], 200) + t.equal(res.headers['content-length'], '' + JSON.stringify(msg).length) + t.same(JSON.parse(res.body), msg) }) test('https get request without trust proxy - protocol', async (t) => { t.plan(2) const url = `https://localhost:${fastify.server.address().port}/proto` - t.deepEqual(JSON.parse((await h2url.concat({ url })).body), { proto: 'https' }) - t.deepEqual(JSON.parse((await h2url.concat({ url, headers: { 'X-Forwarded-Proto': 'lorem' } })).body), { proto: 'https' }) + t.same(JSON.parse((await h2url.concat({ url })).body), { proto: 'https' }) + t.same(JSON.parse((await h2url.concat({ url, headers: { 'X-Forwarded-Proto': 'lorem' } })).body), { proto: 'https' }) }) }) diff --git a/test/http2/unknown-http-method.test.js b/test/http2/unknown-http-method.test.js index 6c96a6832e..b6b11d9dc0 100644 --- a/test/http2/unknown-http-method.test.js +++ b/test/http2/unknown-http-method.test.js @@ -30,8 +30,8 @@ fastify.listen(0, err => { const url = `http://localhost:${fastify.server.address().port}` const res = await h2url.concat({ url, method: 'UNKNOWN_METHOD' }) - t.strictEqual(res.headers[':status'], 404) - t.deepEqual(JSON.parse(res.body), { + t.equal(res.headers[':status'], 404) + t.same(JSON.parse(res.body), { statusCode: 404, error: 'Not Found', message: 'Not Found' diff --git a/test/https/custom-https-server.test.js b/test/https/custom-https-server.test.js index a16e5a2c6b..8c916e0622 100644 --- a/test/https/custom-https-server.test.js +++ b/test/https/custom-https-server.test.js @@ -45,8 +45,8 @@ test('Should support a custom https server', t => { rejectUnauthorized: false }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) diff --git a/test/https/https.test.js b/test/https/https.test.js index 1b4dce8ade..34042a0290 100644 --- a/test/https/https.test.js +++ b/test/https/https.test.js @@ -47,9 +47,9 @@ fastify.listen(0, err => { rejectUnauthorized: false }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -61,7 +61,7 @@ fastify.listen(0, err => { rejectUnauthorized: false }, (err, response, body) => { t.error(err) - t.deepEqual(JSON.parse(body), { proto: 'https' }) + t.same(JSON.parse(body), { proto: 'https' }) }) sget({ method: 'GET', @@ -72,7 +72,7 @@ fastify.listen(0, err => { } }, (err, response, body) => { t.error(err) - t.deepEqual(JSON.parse(body), { proto: 'https' }) + t.same(JSON.parse(body), { proto: 'https' }) }) }) }) diff --git a/test/imports.test.js b/test/imports.test.js index 73a47cad16..791cc7117f 100644 --- a/test/imports.test.js +++ b/test/imports.test.js @@ -7,12 +7,12 @@ test('should import as default', t => { t.plan(2) const fastify = require('..') t.ok(fastify) - t.is(typeof fastify, 'function') + t.equal(typeof fastify, 'function') }) test('should import as esm', t => { t.plan(2) const { fastify } = require('..') t.ok(fastify) - t.is(typeof fastify, 'function') + t.equal(typeof fastify, 'function') }) diff --git a/test/inject.test.js b/test/inject.test.js index 972b1d672d..b05ed4531c 100644 --- a/test/inject.test.js +++ b/test/inject.test.js @@ -11,7 +11,7 @@ test('inject should exist', t => { t.plan(2) const fastify = Fastify() t.ok(fastify.inject) - t.is(typeof fastify.inject, 'function') + t.equal(typeof fastify.inject, 'function') }) test('should wait for the ready event', t => { @@ -32,9 +32,9 @@ test('should wait for the ready event', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(payload, JSON.parse(res.payload)) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '17') + t.same(payload, JSON.parse(res.payload)) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '17') }) }) @@ -52,9 +52,9 @@ test('inject get request', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(payload, JSON.parse(res.payload)) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '17') + t.same(payload, JSON.parse(res.payload)) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '17') }) }) @@ -72,9 +72,9 @@ test('inject get request - code check', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(payload, JSON.parse(res.payload)) - t.strictEqual(res.statusCode, 201) - t.strictEqual(res.headers['content-length'], '17') + t.same(payload, JSON.parse(res.payload)) + t.equal(res.statusCode, 201) + t.equal(res.headers['content-length'], '17') }) }) @@ -91,9 +91,9 @@ test('inject get request - headers check', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual('', res.payload) - t.strictEqual(res.headers['content-type'], 'text/plain') - t.strictEqual(res.headers['content-length'], '0') + t.equal('', res.payload) + t.equal(res.headers['content-type'], 'text/plain') + t.equal(res.headers['content-length'], '0') }) }) @@ -110,9 +110,9 @@ test('inject get request - querystring', t => { url: '/?hello=world' }, (err, res) => { t.error(err) - t.deepEqual({ hello: 'world' }, JSON.parse(res.payload)) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '17') + t.same({ hello: 'world' }, JSON.parse(res.payload)) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '17') }) }) @@ -129,9 +129,9 @@ test('inject get request - params', t => { url: '/world' }, (err, res) => { t.error(err) - t.deepEqual({ hello: 'world' }, JSON.parse(res.payload)) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '17') + t.same({ hello: 'world' }, JSON.parse(res.payload)) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '17') }) }) @@ -148,9 +148,9 @@ test('inject get request - wildcard', t => { url: '/test/wildcard' }, (err, res) => { t.error(err) - t.deepEqual({ '*': 'wildcard' }, JSON.parse(res.payload)) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '16') + t.same({ '*': 'wildcard' }, JSON.parse(res.payload)) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '16') }) }) @@ -168,9 +168,9 @@ test('inject get request - headers', t => { headers: { hello: 'world' } }, (err, res) => { t.error(err) - t.strictEqual('world', JSON.parse(res.payload).hello) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '69') + t.equal('world', JSON.parse(res.payload).hello) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '69') }) }) @@ -189,9 +189,9 @@ test('inject post request', t => { payload: payload }, (err, res) => { t.error(err) - t.deepEqual(payload, JSON.parse(res.payload)) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '17') + t.same(payload, JSON.parse(res.payload)) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '17') }) }) @@ -210,9 +210,9 @@ test('inject post request - send stream', t => { payload: getStream() }, (err, res) => { t.error(err) - t.deepEqual('{"hello":"world"}', res.payload) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '17') + t.same('{"hello":"world"}', res.payload) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '17') }) }) @@ -229,8 +229,8 @@ test('inject get request - reply stream', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual('{"hello":"world"}', res.payload) - t.strictEqual(res.statusCode, 200) + t.same('{"hello":"world"}', res.payload) + t.equal(res.statusCode, 200) }) }) @@ -249,7 +249,7 @@ test('inject promisify - waiting for ready event', t => { } fastify.inject(injectParams) .then(res => { - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) .catch(t.fail) }) @@ -272,7 +272,7 @@ test('inject promisify - after the ready event', t => { } fastify.inject(injectParams) .then(res => { - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) .catch(t.fail) }) @@ -299,7 +299,7 @@ test('inject promisify - when the server is up', t => { } fastify.inject(injectParams) .then(res => { - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) .catch(t.fail) }, 10) @@ -320,7 +320,7 @@ test('should reject in error case', t => { url: '/' }) .catch(e => { - t.strictEqual(e, error) + t.equal(e, error) }) }) @@ -388,7 +388,7 @@ test('should error the promise if ready errors', t => { t.fail('this should not be called') }).catch(err => { t.ok(err) - t.strictequal(err.message, 'kaboom') + t.equal(err.message, 'kaboom') }) }) @@ -406,7 +406,7 @@ test('should throw error if callback specified and if ready errors', t => { url: '/' }, err => { t.ok(err) - t.strictEqual(err, error) + t.equal(err, error) }) }) @@ -421,9 +421,9 @@ test('should support builder-style injection with ready app', async (t) => { await fastify.ready() const res = await fastify.inject().get('/').end() - t.deepEqual(payload, JSON.parse(res.payload)) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '17') + t.same(payload, JSON.parse(res.payload)) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '17') }) test('should support builder-style injection with non-ready app', async (t) => { @@ -436,9 +436,9 @@ test('should support builder-style injection with non-ready app', async (t) => { }) const res = await fastify.inject().get('/').end() - t.deepEqual(payload, JSON.parse(res.payload)) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-length'], '17') + t.same(payload, JSON.parse(res.payload)) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-length'], '17') }) test('should handle errors in builder-style injection correctly', async (t) => { @@ -452,6 +452,6 @@ test('should handle errors in builder-style injection correctly', async (t) => { await fastify.inject().get('/') } catch (err) { t.ok(err) - t.strictEqual(err.message, 'Kaboom') + t.equal(err.message, 'Kaboom') } }) diff --git a/test/input-validation.js b/test/input-validation.js index 204f1e3631..d7e63e5226 100644 --- a/test/input-validation.js +++ b/test/input-validation.js @@ -1,3 +1,4 @@ + 'use strict' const sget = require('simple-get').concat @@ -148,7 +149,7 @@ module.exports.payloadMethod = function (method, t) { url: 'http://localhost:' + fastify.server.address().port }, (err, response) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) } else { t.plan(3) @@ -161,8 +162,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: 42 }) + t.equal(response.statusCode, 200) + t.same(body, { hello: 42 }) }) } }) @@ -178,8 +179,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(body, { + t.equal(response.statusCode, 400) + t.same(body, { error: 'Bad Request', message: 'body.hello should be integer', statusCode: 400 @@ -198,8 +199,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: 42 }) + t.equal(response.statusCode, 200) + t.same(body, { hello: 42 }) }) }) @@ -215,8 +216,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: 42 }) + t.equal(response.statusCode, 200) + t.same(body, { hello: 42 }) }) }) @@ -231,8 +232,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: 42 }) + t.equal(response.statusCode, 200) + t.same(body, { hello: 42 }) }) }) @@ -247,8 +248,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(body, { + t.equal(response.statusCode, 400) + t.same(body, { error: 'Bad Request', message: '"hello" must be a string', statusCode: 400 @@ -267,8 +268,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body, { hello: 42 }) + t.equal(response.statusCode, 200) + t.same(body, { hello: 42 }) }) }) @@ -283,8 +284,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(body, { + t.equal(response.statusCode, 400) + t.same(body, { error: 'Bad Request', message: 'hello must be a `string` type, but the final value was: `44`.', statusCode: 400 @@ -301,8 +302,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(body, { + t.equal(response.statusCode, 400) + t.same(body, { error: 'Bad Request', message: 'From custom schema compiler!', statusCode: '400' @@ -319,8 +320,8 @@ module.exports.payloadMethod = function (method, t) { json: true }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.deepEqual(body, { + t.equal(response.statusCode, 400) + t.same(body, { error: 'Bad Request', message: 'Always fail!', statusCode: '400' diff --git a/test/internals/all.test.js b/test/internals/all.test.js index 30102dd598..f27c95ddde 100644 --- a/test/internals/all.test.js +++ b/test/internals/all.test.js @@ -29,7 +29,7 @@ test('fastify.all should add all the methods to the same url', t => { fastify.inject(options, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { method: method }) + t.same(payload, { method: method }) }) } }) diff --git a/test/internals/contentTypeParser.test.js b/test/internals/contentTypeParser.test.js index 97b912783b..f4acbff9cb 100644 --- a/test/internals/contentTypeParser.test.js +++ b/test/internals/contentTypeParser.test.js @@ -16,7 +16,7 @@ test('rawBody function', t => { asBuffer: false, fn (req, bodyInString, done) { t.equal(bodyInString, body.toString()) - t.is(typeof done, 'function') + t.equal(typeof done, 'function') return { then (cb) { cb() diff --git a/test/internals/decorator.test.js b/test/internals/decorator.test.js index 0d80193eac..193261b5f2 100644 --- a/test/internals/decorator.test.js +++ b/test/internals/decorator.test.js @@ -92,8 +92,8 @@ test('checkDependencies should throw if a dependency is not present', t => { decorator.dependencies(instance, ['test']) t.fail() } catch (e) { - t.is(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') - t.is(e.message, 'The decorator is missing dependency \'test\'.') + t.equal(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') + t.equal(e.message, 'The decorator is missing dependency \'test\'.') } }) @@ -116,8 +116,8 @@ test('decorate should internally call checkDependencies', t => { server.add('method', () => {}, ['test']) t.fail() } catch (e) { - t.is(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') - t.is(e.message, 'The decorator is missing dependency \'test\'.') + t.equal(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') + t.equal(e.message, 'The decorator is missing dependency \'test\'.') } }) @@ -138,10 +138,10 @@ test('decorate should recognize getter/setter objects', t => { this._a = val } }) - t.is(one.hasOwnProperty('foo'), true) - t.is(one.foo, undefined) + t.equal(one.hasOwnProperty('foo'), true) + t.equal(one.foo, undefined) one.foo = 'a' - t.is(one.foo, 'a') + t.equal(one.foo, 'a') // getter only const two = { @@ -154,6 +154,6 @@ test('decorate should recognize getter/setter objects', t => { decorator.add.call(two, 'foo', { getter: () => 'a getter' }) - t.is(two.hasOwnProperty('foo'), true) - t.is(two.foo, 'a getter') + t.equal(two.hasOwnProperty('foo'), true) + t.equal(two.foo, 'a getter') }) diff --git a/test/internals/handleRequest.test.js b/test/internals/handleRequest.test.js index 351d2915e8..38e769aeba 100644 --- a/test/internals/handleRequest.test.js +++ b/test/internals/handleRequest.test.js @@ -35,7 +35,7 @@ test('handleRequest function - invoke with error', t => { t.plan(1) const request = {} const reply = {} - reply.send = (err) => t.is(err.message, 'Kaboom') + reply.send = (err) => t.equal(err.message, 'Kaboom') handleRequest(new Error('Kaboom'), request, reply) }) @@ -89,7 +89,7 @@ test('handler function - reply', t => { res.writeHead = () => {} const context = { handler: (req, reply) => { - t.is(typeof reply, 'object') + t.equal(typeof reply, 'object') reply.code(204) reply.send(undefined) }, @@ -188,7 +188,7 @@ test('request should be defined in onSend Hook on post request with content type }, (err, response, body) => { t.error(err) // a 400 error is expected because of no body - t.strictEqual(response.statusCode, 400) + t.equal(response.statusCode, 400) }) }) }) @@ -219,7 +219,7 @@ test('request should be defined in onSend Hook on post request with content type }, (err, response, body) => { t.error(err) // a 415 error is expected because of missing content type parser - t.strictEqual(response.statusCode, 415) + t.equal(response.statusCode, 415) }) }) }) @@ -250,7 +250,7 @@ test('request should be defined in onSend Hook on options request with content t }, (err, response, body) => { t.error(err) // Body parsing skipped, so no body sent - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) }) @@ -270,8 +270,8 @@ test('request should respond with an error if an unserialized payload is sent in url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) - t.strictDeepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 500) + t.strictSame(JSON.parse(res.payload), { error: 'Internal Server Error', code: 'FST_ERR_REP_INVALID_PAYLOAD_TYPE', message: 'Attempted to send payload of invalid type \'object\'. Expected a string or Buffer.', diff --git a/test/internals/hookRunner.test.js b/test/internals/hookRunner.test.js index f7d593acdc..438e55c74d 100644 --- a/test/internals/hookRunner.test.js +++ b/test/internals/hookRunner.test.js @@ -14,27 +14,27 @@ test('hookRunner - Basic', t => { } function fn1 (a, b, done) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') done() } function fn2 (a, b, done) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') done() } function fn3 (a, b, done) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') done() } function done (err, a, b) { t.error(err) - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') } }) @@ -48,14 +48,14 @@ test('hookRunner - In case of error should skip to done', t => { } function fn1 (a, b, done) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') done() } function fn2 (a, b, done) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') done(new Error('kaboom')) } @@ -64,9 +64,9 @@ test('hookRunner - In case of error should skip to done', t => { } function done (err, a, b) { - t.strictEqual(err.message, 'kaboom') - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(err.message, 'kaboom') + t.equal(a, 'a') + t.equal(b, 'b') } }) @@ -80,14 +80,14 @@ test('hookRunner - Should handle throw', t => { } function fn1 (a, b, done) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') done() } function fn2 (a, b, done) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') throw new Error('kaboom') } @@ -96,9 +96,9 @@ test('hookRunner - Should handle throw', t => { } function done (err, a, b) { - t.strictEqual(err.message, 'kaboom') - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(err.message, 'kaboom') + t.equal(a, 'a') + t.equal(b, 'b') } }) @@ -112,27 +112,27 @@ test('hookRunner - Should handle promises', t => { } function fn1 (a, b) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') return Promise.resolve() } function fn2 (a, b) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') return Promise.resolve() } function fn3 (a, b) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') return Promise.resolve() } function done (err, a, b) { t.error(err) - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') } }) @@ -146,14 +146,14 @@ test('hookRunner - In case of error should skip to done (with promises)', t => { } function fn1 (a, b) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') return Promise.resolve() } function fn2 (a, b) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') return Promise.reject(new Error('kaboom')) } @@ -162,9 +162,9 @@ test('hookRunner - In case of error should skip to done (with promises)', t => { } function done (err, a, b) { - t.strictEqual(err.message, 'kaboom') - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(err.message, 'kaboom') + t.equal(a, 'a') + t.equal(b, 'b') } }) @@ -182,14 +182,14 @@ test('hookRunner - Be able to exit before its natural end', t => { } function fn1 (a, b, done) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') done() } function fn2 (a, b) { - t.strictEqual(a, 'a') - t.strictEqual(b, 'b') + t.equal(a, 'a') + t.equal(b, 'b') shouldStop = true return Promise.resolve() } @@ -215,23 +215,23 @@ test('hookRunner - Promises that resolve to a value do not change the state', t } function fn1 (state, b, done) { - t.strictEqual(state, originalState) + t.equal(state, originalState) return Promise.resolve(null) } function fn2 (state, b, done) { - t.strictEqual(state, originalState) + t.equal(state, originalState) return Promise.resolve('string') } function fn3 (state, b, done) { - t.strictEqual(state, originalState) + t.equal(state, originalState) return Promise.resolve({ object: true }) } function done (err, state, b) { t.error(err) - t.strictEqual(state, originalState) + t.equal(state, originalState) } }) @@ -245,31 +245,31 @@ test('onSendHookRunner - Basic', t => { onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, originalPayload, done) function fn1 (request, reply, payload, done) { - t.deepEqual(request, originalRequest) - t.deepEqual(reply, originalReply) - t.strictEqual(payload, originalPayload) + t.same(request, originalRequest) + t.same(reply, originalReply) + t.equal(payload, originalPayload) done() } function fn2 (request, reply, payload, done) { - t.deepEqual(request, originalRequest) - t.deepEqual(reply, originalReply) - t.strictEqual(payload, originalPayload) + t.same(request, originalRequest) + t.same(reply, originalReply) + t.equal(payload, originalPayload) done() } function fn3 (request, reply, payload, done) { - t.deepEqual(request, originalRequest) - t.deepEqual(reply, originalReply) - t.strictEqual(payload, originalPayload) + t.same(request, originalRequest) + t.same(reply, originalReply) + t.equal(payload, originalPayload) done() } function done (err, request, reply, payload) { t.error(err) - t.deepEqual(request, originalRequest) - t.deepEqual(reply, originalReply) - t.strictEqual(payload, originalPayload) + t.same(request, originalRequest) + t.same(reply, originalReply) + t.equal(payload, originalPayload) } }) @@ -286,25 +286,25 @@ test('onSendHookRunner - Can change the payload', t => { onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done) function fn1 (request, reply, payload, done) { - t.deepEqual(payload, v1) + t.same(payload, v1) done(null, v2) } function fn2 (request, reply, payload, done) { - t.deepEqual(payload, v2) + t.same(payload, v2) done(null, v3) } function fn3 (request, reply, payload, done) { - t.deepEqual(payload, v3) + t.same(payload, v3) done(null, v4) } function done (err, request, reply, payload) { t.error(err) - t.deepEqual(request, originalRequest) - t.deepEqual(reply, originalReply) - t.deepEqual(payload, v4) + t.same(request, originalRequest) + t.same(reply, originalReply) + t.same(payload, v4) } }) @@ -319,12 +319,12 @@ test('onSendHookRunner - In case of error should skip to done', t => { onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done) function fn1 (request, reply, payload, done) { - t.deepEqual(payload, v1) + t.same(payload, v1) done(null, v2) } function fn2 (request, reply, payload, done) { - t.deepEqual(payload, v2) + t.same(payload, v2) done(new Error('kaboom')) } @@ -333,10 +333,10 @@ test('onSendHookRunner - In case of error should skip to done', t => { } function done (err, request, reply, payload) { - t.strictEqual(err.message, 'kaboom') - t.deepEqual(request, originalRequest) - t.deepEqual(reply, originalReply) - t.deepEqual(payload, v2) + t.equal(err.message, 'kaboom') + t.same(request, originalRequest) + t.same(reply, originalReply) + t.same(payload, v2) } }) @@ -353,25 +353,25 @@ test('onSendHookRunner - Should handle promises', t => { onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done) function fn1 (request, reply, payload) { - t.deepEqual(payload, v1) + t.same(payload, v1) return Promise.resolve(v2) } function fn2 (request, reply, payload) { - t.deepEqual(payload, v2) + t.same(payload, v2) return Promise.resolve(v3) } function fn3 (request, reply, payload) { - t.deepEqual(payload, v3) + t.same(payload, v3) return Promise.resolve(v4) } function done (err, request, reply, payload) { t.error(err) - t.deepEqual(request, originalRequest) - t.deepEqual(reply, originalReply) - t.deepEqual(payload, v4) + t.same(request, originalRequest) + t.same(reply, originalReply) + t.same(payload, v4) } }) @@ -386,12 +386,12 @@ test('onSendHookRunner - In case of error should skip to done (with promises)', onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done) function fn1 (request, reply, payload) { - t.deepEqual(payload, v1) + t.same(payload, v1) return Promise.resolve(v2) } function fn2 (request, reply, payload) { - t.deepEqual(payload, v2) + t.same(payload, v2) return Promise.reject(new Error('kaboom')) } @@ -400,10 +400,10 @@ test('onSendHookRunner - In case of error should skip to done (with promises)', } function done (err, request, reply, payload) { - t.strictEqual(err.message, 'kaboom') - t.deepEqual(request, originalRequest) - t.deepEqual(reply, originalReply) - t.deepEqual(payload, v2) + t.equal(err.message, 'kaboom') + t.same(request, originalRequest) + t.same(reply, originalReply) + t.same(payload, v2) } }) @@ -418,12 +418,12 @@ test('onSendHookRunner - Be able to exit before its natural end', t => { onSendHookRunner([fn1, fn2, fn3], originalRequest, originalReply, v1, done) function fn1 (request, reply, payload, done) { - t.deepEqual(payload, v1) + t.same(payload, v1) done(null, v2) } function fn2 (request, reply, payload) { - t.deepEqual(payload, v2) + t.same(payload, v2) } function fn3 () { diff --git a/test/internals/hooks.test.js b/test/internals/hooks.test.js index 719ed7f267..38594aa82f 100644 --- a/test/internals/hooks.test.js +++ b/test/internals/hooks.test.js @@ -8,7 +8,7 @@ const noop = () => {} test('hooks should have 4 array with the registered hooks', t => { const hooks = new Hooks() - t.is(typeof hooks, 'object') + t.equal(typeof hooks, 'object') t.ok(Array.isArray(hooks.onRequest)) t.ok(Array.isArray(hooks.onSend)) t.ok(Array.isArray(hooks.preParsing)) @@ -22,32 +22,32 @@ test('hooks should have 4 array with the registered hooks', t => { test('hooks.add should add a hook to the given hook', t => { const hooks = new Hooks() hooks.add('onRequest', noop) - t.is(hooks.onRequest.length, 1) - t.is(typeof hooks.onRequest[0], 'function') + t.equal(hooks.onRequest.length, 1) + t.equal(typeof hooks.onRequest[0], 'function') hooks.add('preParsing', noop) - t.is(hooks.preParsing.length, 1) - t.is(typeof hooks.preParsing[0], 'function') + t.equal(hooks.preParsing.length, 1) + t.equal(typeof hooks.preParsing[0], 'function') hooks.add('preValidation', noop) - t.is(hooks.preValidation.length, 1) - t.is(typeof hooks.preValidation[0], 'function') + t.equal(hooks.preValidation.length, 1) + t.equal(typeof hooks.preValidation[0], 'function') hooks.add('preHandler', noop) - t.is(hooks.preHandler.length, 1) - t.is(typeof hooks.preHandler[0], 'function') + t.equal(hooks.preHandler.length, 1) + t.equal(typeof hooks.preHandler[0], 'function') hooks.add('onResponse', noop) - t.is(hooks.onResponse.length, 1) - t.is(typeof hooks.onResponse[0], 'function') + t.equal(hooks.onResponse.length, 1) + t.equal(typeof hooks.onResponse[0], 'function') hooks.add('onSend', noop) - t.is(hooks.onSend.length, 1) - t.is(typeof hooks.onSend[0], 'function') + t.equal(hooks.onSend.length, 1) + t.equal(typeof hooks.onSend[0], 'function') hooks.add('onError', noop) - t.is(hooks.onError.length, 1) - t.is(typeof hooks.onError[0], 'function') + t.equal(hooks.onError.length, 1) + t.equal(typeof hooks.onError[0], 'function') t.end() }) @@ -69,15 +69,15 @@ test('should throw on wrong parameters', t => { hooks.add(null, noop) t.fail() } catch (e) { - t.is(e.code, 'FST_ERR_HOOK_INVALID_TYPE') - t.is(e.message, 'The hook name must be a string') + t.equal(e.code, 'FST_ERR_HOOK_INVALID_TYPE') + t.equal(e.message, 'The hook name must be a string') } try { hooks.add('', null) t.fail() } catch (e) { - t.is(e.code, 'FST_ERR_HOOK_INVALID_HANDLER') - t.is(e.message, 'The hook callback must be a function') + t.equal(e.code, 'FST_ERR_HOOK_INVALID_HANDLER') + t.equal(e.message, 'The hook callback must be a function') } }) diff --git a/test/internals/initialConfig.test.js b/test/internals/initialConfig.test.js index 2dc5b5d0f7..b07ee869f1 100644 --- a/test/internals/initialConfig.test.js +++ b/test/internals/initialConfig.test.js @@ -36,7 +36,7 @@ test('without options passed to Fastify, initialConfig should expose default val http2SessionTimeout: 5000 } - t.deepEquals(Fastify().initialConfig, fastifyDefaultOptions) + t.same(Fastify().initialConfig, fastifyDefaultOptions) }) test('Fastify.initialConfig should expose all options', t => { @@ -98,26 +98,26 @@ test('Fastify.initialConfig should expose all options', t => { } const fastify = Fastify(options) - t.strictEqual(fastify.initialConfig.http2, true) - t.strictEqual(fastify.initialConfig.https, true) - t.strictEqual(fastify.initialConfig.ignoreTrailingSlash, true) - t.strictEqual(fastify.initialConfig.maxParamLength, 200) - t.strictEqual(fastify.initialConfig.connectionTimeout, 0) - t.strictEqual(fastify.initialConfig.keepAliveTimeout, 5000) - t.strictEqual(fastify.initialConfig.bodyLimit, 1049600) - t.strictEqual(fastify.initialConfig.onProtoPoisoning, 'remove') - t.strictEqual(fastify.initialConfig.caseSensitive, true) - t.strictEqual(fastify.initialConfig.requestIdHeader, 'request-id-alt') - t.strictEqual(fastify.initialConfig.pluginTimeout, 20000) + t.equal(fastify.initialConfig.http2, true) + t.equal(fastify.initialConfig.https, true) + t.equal(fastify.initialConfig.ignoreTrailingSlash, true) + t.equal(fastify.initialConfig.maxParamLength, 200) + t.equal(fastify.initialConfig.connectionTimeout, 0) + t.equal(fastify.initialConfig.keepAliveTimeout, 5000) + t.equal(fastify.initialConfig.bodyLimit, 1049600) + t.equal(fastify.initialConfig.onProtoPoisoning, 'remove') + t.equal(fastify.initialConfig.caseSensitive, true) + t.equal(fastify.initialConfig.requestIdHeader, 'request-id-alt') + t.equal(fastify.initialConfig.pluginTimeout, 20000) t.ok(fastify.initialConfig.constraints.version) // obfuscated options: - t.strictEqual(fastify.initialConfig.serverFactory, undefined) - t.strictEqual(fastify.initialConfig.trustProxy, undefined) - t.strictEqual(fastify.initialConfig.genReqId, undefined) - t.strictEqual(fastify.initialConfig.querystringParser, undefined) - t.strictEqual(fastify.initialConfig.logger, undefined) - t.strictEqual(fastify.initialConfig.trustProxy, undefined) + t.equal(fastify.initialConfig.serverFactory, undefined) + t.equal(fastify.initialConfig.trustProxy, undefined) + t.equal(fastify.initialConfig.genReqId, undefined) + t.equal(fastify.initialConfig.querystringParser, undefined) + t.equal(fastify.initialConfig.logger, undefined) + t.equal(fastify.initialConfig.trustProxy, undefined) }) test('Should throw if you try to modify Fastify.initialConfig', t => { @@ -187,10 +187,10 @@ test('Original options must not be frozen', t => { const fastify = Fastify(originalOptions) - t.strictEqual(Object.isFrozen(originalOptions), false) - t.strictEqual(Object.isFrozen(originalOptions.https), false) - t.strictEqual(Object.isFrozen(fastify.initialConfig), true) - t.strictEqual(Object.isFrozen(fastify.initialConfig.https), true) + t.equal(Object.isFrozen(originalOptions), false) + t.equal(Object.isFrozen(originalOptions.https), false) + t.equal(Object.isFrozen(fastify.initialConfig), true) + t.equal(Object.isFrozen(fastify.initialConfig.https), true) }) test('Original options must not be altered (test deep cloning)', t => { @@ -209,11 +209,11 @@ test('Original options must not be altered (test deep cloning)', t => { const fastify = Fastify(originalOptions) // initialConfig has been triggered - t.strictEqual(Object.isFrozen(fastify.initialConfig), true) + t.equal(Object.isFrozen(fastify.initialConfig), true) // originalOptions must not have been altered - t.deepEqual(originalOptions.https.key, originalOptionsClone.https.key) - t.deepEqual(originalOptions.https.cert, originalOptionsClone.https.cert) + t.same(originalOptions.https.key, originalOptionsClone.https.key) + t.same(originalOptions.https.cert, originalOptionsClone.https.cert) }) test('Should not have issues when passing stream options to Pino.js', t => { @@ -235,7 +235,7 @@ test('Should not have issues when passing stream options to Pino.js', t => { fastify = Fastify(originalOptions) t.type(fastify, 'object') - t.deepEqual(fastify.initialConfig, { + t.same(fastify.initialConfig, { connectionTimeout: 0, keepAliveTimeout: 5000, bodyLimit: 1024 * 1024, @@ -307,11 +307,11 @@ test('deepFreezeObject() should not throw on TypedArray', t => { const frozenObject = deepFreezeObject(object) // Buffers should not be frozen, as they are Uint8Array inherited instances - t.strictEqual(Object.isFrozen(frozenObject.buffer), false) + t.equal(Object.isFrozen(frozenObject.buffer), false) - t.strictEqual(Object.isFrozen(frozenObject), true) - t.strictEqual(Object.isFrozen(frozenObject.object), true) - t.strictEqual(Object.isFrozen(frozenObject.object.nested), true) + t.equal(Object.isFrozen(frozenObject), true) + t.equal(Object.isFrozen(frozenObject.object), true) + t.equal(Object.isFrozen(frozenObject.object.nested), true) t.pass() } catch (error) { @@ -323,7 +323,7 @@ test('Fastify.initialConfig should accept the deprecated versioning option', t = t.plan(1) function onWarning (warning) { - t.is(warning.code, 'FSTDEP009') + t.equal(warning.code, 'FSTDEP009') } process.on('warning', onWarning) diff --git a/test/internals/logger.test.js b/test/internals/logger.test.js index 6f1f5a5769..3b3da210e9 100644 --- a/test/internals/logger.test.js +++ b/test/internals/logger.test.js @@ -7,8 +7,8 @@ const loggerUtils = require('../../lib/logger') test('time resolution', t => { t.plan(2) - t.is(typeof loggerUtils.now, 'function') - t.is(typeof loggerUtils.now(), 'number') + t.equal(typeof loggerUtils.now, 'function') + t.equal(typeof loggerUtils.now(), 'number') }) test('The logger should add a unique id for every request', t => { @@ -108,7 +108,7 @@ test('The logger should error if both stream and file destination are given', t } }) } catch (err) { - t.is(err.code, 'FST_ERR_LOG_INVALID_DESTINATION') - t.is(err.message, 'Cannot specify both logger.stream and logger.file options') + t.equal(err.code, 'FST_ERR_LOG_INVALID_DESTINATION') + t.equal(err.message, 'Cannot specify both logger.stream and logger.file options') } }) diff --git a/test/internals/plugin.test.js b/test/internals/plugin.test.js index 4689f5360f..d325689a90 100644 --- a/test/internals/plugin.test.js +++ b/test/internals/plugin.test.js @@ -12,8 +12,8 @@ test("shouldSkipOverride should check the 'skip-override' symbol", t => { yes[Symbol.for('skip-override')] = true - t.true(pluginUtils.shouldSkipOverride(yes)) - t.false(pluginUtils.shouldSkipOverride(no)) + t.ok(pluginUtils.shouldSkipOverride(yes)) + t.notOk(pluginUtils.shouldSkipOverride(no)) function yes () {} function no () {} @@ -26,7 +26,7 @@ test('getPluginName should return plugin name if the file is cached', t => { require.cache[expectedPluginName] = { exports: fn } const pluginName = pluginUtilsPublic.getPluginName(fn) - t.isEqual(pluginName, expectedPluginName) + t.equal(pluginName, expectedPluginName) }) test("getMeta should return the object stored with the 'plugin-meta' symbol", t => { @@ -35,7 +35,7 @@ test("getMeta should return the object stored with the 'plugin-meta' symbol", t const meta = { hello: 'world' } fn[Symbol.for('plugin-meta')] = meta - t.deepEqual(meta, pluginUtils.getMeta(fn)) + t.same(meta, pluginUtils.getMeta(fn)) function fn () {} }) @@ -86,7 +86,7 @@ test('checkDecorators should check if the given decorator is present in the inst pluginUtils.checkDecorators.call(context, fn) t.fail('should throw') } catch (err) { - t.is(err.message, "The decorator 'plugin' is not present in Request") + t.equal(err.message, "The decorator 'plugin' is not present in Request") } function fn () {} @@ -127,7 +127,7 @@ test('checkDependencies should check if the given dependency is present in the i pluginUtils.checkDependencies.call(context, fn) t.fail('should throw') } catch (err) { - t.is(err.message, "The dependency 'plugin' of plugin 'test-plugin' is not registered") + t.equal(err.message, "The dependency 'plugin' of plugin 'test-plugin' is not registered") } function fn () {} diff --git a/test/internals/reply.test.js b/test/internals/reply.test.js index 9a0713eeff..d357b27bc0 100644 --- a/test/internals/reply.test.js +++ b/test/internals/reply.test.js @@ -22,19 +22,19 @@ test('Once called, Reply should return an object with methods', t => { const context = {} const request = { context } const reply = new Reply(response, request) - t.is(typeof reply, 'object') - t.is(typeof reply[kReplyIsError], 'boolean') - t.is(typeof reply[kReplyErrorHandlerCalled], 'boolean') - t.is(typeof reply.send, 'function') - t.is(typeof reply.code, 'function') - t.is(typeof reply.status, 'function') - t.is(typeof reply.header, 'function') - t.is(typeof reply.serialize, 'function') - t.is(typeof reply.getResponseTime, 'function') - t.is(typeof reply[kReplyHeaders], 'object') - t.deepEqual(reply.raw, response) - t.strictEqual(reply.context, context) - t.strictEqual(reply.request, request) + t.equal(typeof reply, 'object') + t.equal(typeof reply[kReplyIsError], 'boolean') + t.equal(typeof reply[kReplyErrorHandlerCalled], 'boolean') + t.equal(typeof reply.send, 'function') + t.equal(typeof reply.code, 'function') + t.equal(typeof reply.status, 'function') + t.equal(typeof reply.header, 'function') + t.equal(typeof reply.serialize, 'function') + t.equal(typeof reply.getResponseTime, 'function') + t.equal(typeof reply[kReplyHeaders], 'object') + t.same(reply.raw, response) + t.equal(reply.context, context) + t.equal(reply.request, request) }) test('reply.send will logStream error and destroy the stream', { only: true }, t => { @@ -127,7 +127,7 @@ test('reply.serializer should support running preSerialization hooks', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"foo":"bar"}') + t.equal(res.payload, '{"foo":"bar"}') }) }) @@ -188,7 +188,7 @@ test('reply.serialize should serialize payload with Fastify instance', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"foo":"bar"}') + t.equal(res.payload, '{"foo":"bar"}') }) }) @@ -259,8 +259,8 @@ test('within an instance', t => { url: 'http://localhost:' + fastify.server.address().port + '/custom-serializer' }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'text/plain') - t.deepEqual(body.toString(), 'hello=world!') + t.equal(response.headers['content-type'], 'text/plain') + t.same(body.toString(), 'hello=world!') }) }) @@ -271,9 +271,9 @@ test('within an instance', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-type'], 'text/plain') - t.deepEqual(body.toString(), 'hello world!') + t.equal(response.statusCode, 200) + t.equal(response.headers['content-type'], 'text/plain') + t.same(body.toString(), 'hello world!') }) }) @@ -284,8 +284,8 @@ test('within an instance', t => { url: 'http://localhost:' + fastify.server.address().port + '/auto-status-code' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), 'hello world!') + t.equal(response.statusCode, 200) + t.same(body.toString(), 'hello world!') }) }) @@ -296,8 +296,8 @@ test('within an instance', t => { url: 'http://localhost:' + fastify.server.address().port + '/auto-type' }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'text/plain') - t.deepEqual(body.toString(), 'hello world!') + t.equal(response.headers['content-type'], 'text/plain') + t.same(body.toString(), 'hello world!') }) }) @@ -305,7 +305,7 @@ test('within an instance', t => { t.plan(1) http.get('http://localhost:' + fastify.server.address().port + '/redirect', function (response) { - t.strictEqual(response.statusCode, 302) + t.equal(response.statusCode, 302) }) }) @@ -313,7 +313,7 @@ test('within an instance', t => { t.plan(1) http.get('http://localhost:' + fastify.server.address().port + '/redirect-code', function (response) { - t.strictEqual(response.statusCode, 301) + t.equal(response.statusCode, 301) }) }) @@ -324,9 +324,9 @@ test('within an instance', t => { url: 'http://localhost:' + fastify.server.address().port + '/redirect' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-type'], 'text/plain') - t.deepEqual(body.toString(), 'hello world!') + t.equal(response.statusCode, 200) + t.equal(response.headers['content-type'], 'text/plain') + t.same(body.toString(), 'hello world!') }) }) @@ -337,9 +337,9 @@ test('within an instance', t => { url: 'http://localhost:' + fastify.server.address().port + '/redirect-code' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-type'], 'text/plain') - t.deepEqual(body.toString(), 'hello world!') + t.equal(response.statusCode, 200) + t.equal(response.headers['content-type'], 'text/plain') + t.same(body.toString(), 'hello world!') }) }) @@ -347,9 +347,9 @@ test('within an instance', t => { t.plan(3) const url = 'http://localhost:' + fastify.server.address().port + '/redirect-onsend' http.get(url, (response) => { - t.strictEqual(response.headers['x-onsend'], 'yes') - t.strictEqual(response.headers['content-length'], '0') - t.strictEqual(response.headers.location, '/') + t.equal(response.headers['x-onsend'], 'yes') + t.equal(response.headers['content-length'], '0') + t.equal(response.headers.location, '/') }) }) @@ -360,9 +360,9 @@ test('within an instance', t => { url: 'http://localhost:' + fastify.server.address().port + '/redirect-code-before-call' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-type'], 'text/plain') - t.deepEqual(body.toString(), 'hello world!') + t.equal(response.statusCode, 200) + t.equal(response.headers['content-type'], 'text/plain') + t.same(body.toString(), 'hello world!') }) }) @@ -373,9 +373,9 @@ test('within an instance', t => { url: 'http://localhost:' + fastify.server.address().port + '/redirect-code-before-call-overwrite' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-type'], 'text/plain') - t.deepEqual(body.toString(), 'hello world!') + t.equal(response.statusCode, 200) + t.equal(response.headers['content-type'], 'text/plain') + t.same(body.toString(), 'hello world!') }) }) @@ -383,7 +383,7 @@ test('within an instance', t => { t.plan(1) http.get('http://localhost:' + fastify.server.address().port + '/redirect-code-before-call', function (response) { - t.strictEqual(response.statusCode, 307) + t.equal(response.statusCode, 307) }) }) @@ -391,7 +391,7 @@ test('within an instance', t => { t.plan(1) http.get('http://localhost:' + fastify.server.address().port + '/redirect-code-before-call-overwrite', function (response) { - t.strictEqual(response.statusCode, 302) + t.equal(response.statusCode, 302) }) }) @@ -417,8 +417,8 @@ test('buffer without content type should send a application/octet-stream and raw url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'application/octet-stream') - t.deepEqual(body, Buffer.alloc(1024)) + t.equal(response.headers['content-type'], 'application/octet-stream') + t.same(body, Buffer.alloc(1024)) }) }) }) @@ -442,8 +442,8 @@ test('buffer with content type should not send application/octet-stream', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'text/plain') - t.deepEqual(body, Buffer.alloc(1024)) + t.equal(response.headers['content-type'], 'text/plain') + t.same(body, Buffer.alloc(1024)) }) }) }) @@ -471,8 +471,8 @@ test('stream with content type should not send application/octet-stream', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'text/plain') - t.deepEqual(body, buf) + t.equal(response.headers['content-type'], 'text/plain') + t.same(body, buf) }) }) }) @@ -506,9 +506,9 @@ test('stream using reply.raw.writeHead should return customize headers', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers.location, '/') - t.strictEqual(response.headers['Content-Type'], undefined) - t.deepEqual(body, buf) + t.equal(response.headers.location, '/') + t.equal(response.headers['Content-Type'], undefined) + t.same(body, buf) }) }) }) @@ -531,8 +531,8 @@ test('plain string without content type should send a text/plain', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'text/plain; charset=utf-8') - t.deepEqual(body.toString(), 'hello world!') + t.equal(response.headers['content-type'], 'text/plain; charset=utf-8') + t.same(body.toString(), 'hello world!') }) }) }) @@ -555,8 +555,8 @@ test('plain string with content type should be sent unmodified', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'text/css') - t.deepEqual(body.toString(), 'hello world!') + t.equal(response.headers['content-type'], 'text/css') + t.same(body.toString(), 'hello world!') }) }) }) @@ -582,8 +582,8 @@ test('plain string with content type and custom serializer should be serialized' url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'text/css') - t.deepEqual(body.toString(), 'serialized') + t.equal(response.headers['content-type'], 'text/css') + t.same(body.toString(), 'serialized') }) }) }) @@ -606,8 +606,8 @@ test('plain string with content type application/json should NOT be serialized a url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(body.toString(), '{"key": "hello world!"}') + t.equal(response.headers['content-type'], 'application/json; charset=utf-8') + t.same(body.toString(), '{"key": "hello world!"}') }) }) }) @@ -660,8 +660,8 @@ test('plain string with custom json content type should NOT be serialized as jso url: 'http://localhost:' + fastify.server.address().port + '/' + path }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], customSamples[path].mimeType + '; charset=utf-8') - t.deepEqual(body.toString(), customSamples[path].sample) + t.equal(response.headers['content-type'], customSamples[path].mimeType + '; charset=utf-8') + t.same(body.toString(), customSamples[path].sample) }) }) }) @@ -685,8 +685,8 @@ test('non-string with content type application/json SHOULD be serialized as json url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(body.toString(), JSON.stringify({ key: 'hello world!' })) + t.equal(response.headers['content-type'], 'application/json; charset=utf-8') + t.same(body.toString(), JSON.stringify({ key: 'hello world!' })) }) }) }) @@ -735,8 +735,8 @@ test('non-string with custom json content type SHOULD be serialized as json', t url: 'http://localhost:' + fastify.server.address().port + '/' + path }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], customSamples[path].mimeType + '; charset=utf-8') - t.deepEqual(body.toString(), JSON.stringify(customSamples[path].sample)) + t.equal(response.headers['content-type'], customSamples[path].mimeType + '; charset=utf-8') + t.same(body.toString(), JSON.stringify(customSamples[path].sample)) }) }) }) @@ -762,8 +762,8 @@ test('error object with a content type that is not application/json should work' url: '/text' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) - t.strictEqual(JSON.parse(res.payload).message, 'some application error') + t.equal(res.statusCode, 500) + t.equal(JSON.parse(res.payload).message, 'some application error') }) fastify.inject({ @@ -771,8 +771,8 @@ test('error object with a content type that is not application/json should work' url: '/html' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) - t.strictEqual(JSON.parse(res.payload).message, 'some application error') + t.equal(res.statusCode, 500) + t.equal(JSON.parse(res.payload).message, 'some application error') }) }) @@ -782,7 +782,7 @@ test('undefined payload should be sent as-is', t => { const fastify = require('../..')() fastify.addHook('onSend', function (request, reply, payload, done) { - t.strictEqual(payload, undefined) + t.equal(payload, undefined) done() }) @@ -799,9 +799,9 @@ test('undefined payload should be sent as-is', t => { url: `http://localhost:${fastify.server.address().port}` }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], undefined) - t.strictEqual(response.headers['content-length'], undefined) - t.strictEqual(body.length, 0) + t.equal(response.headers['content-type'], undefined) + t.equal(response.headers['content-length'], undefined) + t.equal(body.length, 0) }) }) }) @@ -815,7 +815,7 @@ test('for HEAD method, no body should be sent but content-length should be', t = fastify.head('/', { onSend: function (request, reply, payload, done) { - t.strictEqual(payload, undefined) + t.equal(payload, undefined) done() } }, function (req, reply) { @@ -826,7 +826,7 @@ test('for HEAD method, no body should be sent but content-length should be', t = fastify.head('/with/null', { onSend: function (request, reply, payload, done) { - t.strictEqual(payload, 'null') + t.equal(payload, 'null') done() } }, function (req, reply) { @@ -844,9 +844,9 @@ test('for HEAD method, no body should be sent but content-length should be', t = url: `http://localhost:${fastify.server.address().port}` }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], contentType) - t.strictEqual(response.headers['content-length'], bodySize.toString()) - t.strictEqual(body.length, 0) + t.equal(response.headers['content-type'], contentType) + t.equal(response.headers['content-length'], bodySize.toString()) + t.equal(body.length, 0) }) sget({ @@ -854,9 +854,9 @@ test('for HEAD method, no body should be sent but content-length should be', t = url: `http://localhost:${fastify.server.address().port}/with/null` }, (err, response, body) => { t.error(err) - t.strictEqual(response.headers['content-type'], contentType) - t.strictEqual(response.headers['content-length'], bodySize.toString()) - t.strictEqual(body.length, 0) + t.equal(response.headers['content-type'], contentType) + t.equal(response.headers['content-length'], bodySize.toString()) + t.equal(body.length, 0) }) }) }) @@ -892,9 +892,9 @@ test('reply.send(new NotFound()) should not invoke the 404 handler', t => { url: 'http://localhost:' + fastify.server.address().port + '/not-found' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(body.toString()), { + t.equal(response.statusCode, 404) + t.equal(response.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(body.toString()), { statusCode: 404, error: 'Not Found', message: 'Not Found' @@ -906,9 +906,9 @@ test('reply.send(new NotFound()) should not invoke the 404 handler', t => { url: 'http://localhost:' + fastify.server.address().port + '/prefixed/not-found' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) - t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(body), { + t.equal(response.statusCode, 404) + t.equal(response.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(body), { error: 'Not Found', message: 'Not Found', statusCode: 404 @@ -939,7 +939,7 @@ test('reply can set multiple instances of same header', t => { }, (err, response, body) => { t.error(err) t.ok(response.headers['set-cookie']) - t.strictDeepEqual(response.headers['set-cookie'], ['one', 'two']) + t.strictSame(response.headers['set-cookie'], ['one', 'two']) }) }) }) @@ -951,8 +951,8 @@ test('reply.hasHeader returns correct values', t => { fastify.get('/headers', function (req, reply) { reply.header('x-foo', 'foo') - t.is(reply.hasHeader('x-foo'), true) - t.is(reply.hasHeader('x-bar'), false) + t.equal(reply.hasHeader('x-foo'), true) + t.equal(reply.hasHeader('x-bar'), false) reply.send() }) @@ -973,14 +973,14 @@ test('reply.getHeader returns correct values', t => { fastify.get('/headers', function (req, reply) { reply.header('x-foo', 'foo') - t.is(reply.getHeader('x-foo'), 'foo') + t.equal(reply.getHeader('x-foo'), 'foo') reply.header('x-foo', 'bar') - t.strictDeepEqual(reply.getHeader('x-foo'), 'bar') + t.strictSame(reply.getHeader('x-foo'), 'bar') reply.header('set-cookie', 'one') reply.header('set-cookie', 'two') - t.strictDeepEqual(reply.getHeader('set-cookie'), ['one', 'two']) + t.strictSame(reply.getHeader('set-cookie'), ['one', 'two']) reply.send() }) @@ -1016,7 +1016,7 @@ test('reply.getHeaders returns correct values', t => { fastify.get('/headers', function (req, reply) { reply.header('x-foo', 'foo') - t.strictDeepEqual(reply.getHeaders(), { + t.strictSame(reply.getHeaders(), { 'x-foo': 'foo' }) @@ -1024,7 +1024,7 @@ test('reply.getHeaders returns correct values', t => { reply.raw.setHeader('x-foo', 'foo2') reply.raw.setHeader('x-baz', 'baz') - t.strictDeepEqual(reply.getHeaders(), { + t.strictSame(reply.getHeaders(), { 'x-foo': 'foo', 'x-bar': 'bar', 'x-baz': 'baz' @@ -1047,10 +1047,10 @@ test('reply.removeHeader can remove the value', t => { fastify.get('/headers', function (req, reply) { reply.header('x-foo', 'foo') - t.is(reply.getHeader('x-foo'), 'foo') + t.equal(reply.getHeader('x-foo'), 'foo') - t.is(reply.removeHeader('x-foo'), reply) - t.strictDeepEqual(reply.getHeader('x-foo'), undefined) + t.equal(reply.removeHeader('x-foo'), reply) + t.strictSame(reply.getHeader('x-foo'), undefined) reply.send() }) @@ -1077,7 +1077,7 @@ test('reply.header can reset the value', t => { fastify.get('/headers', function (req, reply) { reply.header('x-foo', 'foo') reply.header('x-foo', undefined) - t.strictDeepEqual(reply.getHeader('x-foo'), '') + t.strictSame(reply.getHeader('x-foo'), '') reply.send() }) @@ -1147,42 +1147,42 @@ test('Reply should handle JSON content type with a charset', t => { fastify.inject('/default', (err, res) => { t.error(err) - t.is(res.headers['content-type'], 'application/json; charset=utf-8') + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') }) fastify.inject('/utf8', (err, res) => { t.error(err) - t.is(res.headers['content-type'], 'application/json; charset=utf-8') + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') }) fastify.inject('/utf16', (err, res) => { t.error(err) - t.is(res.headers['content-type'], 'application/json; charset=utf-16') + t.equal(res.headers['content-type'], 'application/json; charset=utf-16') }) fastify.inject('/utf32', (err, res) => { t.error(err) - t.is(res.headers['content-type'], 'application/json; charset=utf-32') + t.equal(res.headers['content-type'], 'application/json; charset=utf-32') }) fastify.inject('/type-utf8', (err, res) => { t.error(err) - t.is(res.headers['content-type'], 'application/json; charset=utf-8') + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') }) fastify.inject('/type-utf16', (err, res) => { t.error(err) - t.is(res.headers['content-type'], 'application/json; charset=utf-16') + t.equal(res.headers['content-type'], 'application/json; charset=utf-16') }) fastify.inject('/type-utf32', (err, res) => { t.error(err) - t.is(res.headers['content-type'], 'application/json; charset=utf-32') + t.equal(res.headers['content-type'], 'application/json; charset=utf-32') }) fastify.inject('/no-space-type-utf32', (err, res) => { t.error(err) - t.is(res.headers['content-type'], 'application/json;charset=utf-32') + t.equal(res.headers['content-type'], 'application/json;charset=utf-32') }) }) @@ -1202,7 +1202,7 @@ test('Content type and charset set previously', t => { fastify.inject('/', (err, res) => { t.error(err) - t.is(res.headers['content-type'], 'application/json; charset=utf-16') + t.equal(res.headers['content-type'], 'application/json; charset=utf-16') }) }) @@ -1216,7 +1216,7 @@ test('.status() is an alias for .code()', t => { fastify.inject('/', (err, res) => { t.error(err) - t.is(res.statusCode, 418) + t.equal(res.statusCode, 418) }) }) @@ -1233,7 +1233,7 @@ test('.statusCode is getter and setter', t => { fastify.inject('/', (err, res) => { t.error(err) - t.is(res.statusCode, 418) + t.equal(res.statusCode, 418) }) }) @@ -1261,14 +1261,14 @@ test('reply.header setting multiple cookies as multiple Set-Cookie headers', t = }, (err, response, body) => { t.error(err) t.ok(response.headers['set-cookie']) - t.strictDeepEqual(response.headers['set-cookie'], ['one', 'two', 'three', 'four', 'five', 'six']) + t.strictSame(response.headers['set-cookie'], ['one', 'two', 'three', 'four', 'five', 'six']) }) }) fastify.inject('/headers', (error, response) => { t.error(error) t.ok(response.headers['set-cookie']) - t.strictDeepEqual(response.headers['set-cookie'], ['one', 'two', 'three', 'four', 'five', 'six']) + t.strictSame(response.headers['set-cookie'], ['one', 'two', 'three', 'four', 'five', 'six']) }) }) @@ -1280,8 +1280,8 @@ test('should throw error when passing falsy value to reply.sent', t => { try { reply.sent = false } catch (err) { - t.is(err.code, 'FST_ERR_REP_SENT_VALUE') - t.strictEqual(err.message, 'The only possible value for reply.sent is true.') + t.equal(err.code, 'FST_ERR_REP_SENT_VALUE') + t.equal(err.message, 'The only possible value for reply.sent is true.') reply.send() } }) @@ -1301,8 +1301,8 @@ test('should throw error when attempting to set reply.sent more than once', t => try { reply.sent = true } catch (err) { - t.is(err.code, 'FST_ERR_REP_ALREADY_SENT') - t.strictEqual(err.message, 'Reply was already sent.') + t.equal(err.code, 'FST_ERR_REP_ALREADY_SENT') + t.equal(err.message, 'Reply was already sent.') } reply.raw.end() }) @@ -1332,7 +1332,7 @@ test('reply.getResponseTime() should return a number greater than 0 after the ti }) fastify.addHook('onResponse', (req, reply) => { - t.true(reply.getResponseTime() > 0) + t.ok(reply.getResponseTime() > 0) t.end() }) @@ -1343,7 +1343,7 @@ test('reply should use the custom serializer', t => { t.plan(4) const fastify = require('../..')() fastify.setReplySerializer((payload, statusCode) => { - t.deepEqual(payload, { foo: 'bar' }) + t.same(payload, { foo: 'bar' }) t.equal(statusCode, 200) payload.foo = 'bar bar' return JSON.stringify(payload) @@ -1362,7 +1362,7 @@ test('reply should use the custom serializer', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"foo":"bar bar"}') + t.equal(res.payload, '{"foo":"bar bar"}') }) }) @@ -1371,7 +1371,7 @@ test('reply should use the right serializer in encapsulated context', t => { const fastify = require('../..')() fastify.setReplySerializer((payload) => { - t.deepEqual(payload, { foo: 'bar' }) + t.same(payload, { foo: 'bar' }) payload.foo = 'bar bar' return JSON.stringify(payload) }) @@ -1389,7 +1389,7 @@ test('reply should use the right serializer in encapsulated context', t => { handler: (req, reply) => { reply.send({ john: 'doo' }) } }) instance.setReplySerializer((payload) => { - t.deepEqual(payload, { john: 'doo' }) + t.same(payload, { john: 'doo' }) payload.john = 'too too' return JSON.stringify(payload) }) @@ -1403,7 +1403,7 @@ test('reply should use the right serializer in encapsulated context', t => { handler: (req, reply) => { reply.send({ sweet: 'potato' }) } }) instance.setReplySerializer((payload) => { - t.deepEqual(payload, { sweet: 'potato' }) + t.same(payload, { sweet: 'potato' }) payload.sweet = 'potato potato' return JSON.stringify(payload) }) @@ -1415,7 +1415,7 @@ test('reply should use the right serializer in encapsulated context', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"foo":"bar bar"}') + t.equal(res.payload, '{"foo":"bar bar"}') }) fastify.inject({ @@ -1423,7 +1423,7 @@ test('reply should use the right serializer in encapsulated context', t => { url: '/sub' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"john":"too too"}') + t.equal(res.payload, '{"john":"too too"}') }) fastify.inject({ @@ -1431,7 +1431,7 @@ test('reply should use the right serializer in encapsulated context', t => { url: '/sub/sub' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"sweet":"potato potato"}') + t.equal(res.payload, '{"sweet":"potato potato"}') }) }) @@ -1453,7 +1453,7 @@ test('reply should use the right serializer in deep encapsulated context', t => handler: (req, reply) => { reply.send({ john: 'doo' }) } }) instance.setReplySerializer((payload) => { - t.deepEqual(payload, { john: 'doo' }) + t.same(payload, { john: 'doo' }) payload.john = 'too too' return JSON.stringify(payload) }) @@ -1465,7 +1465,7 @@ test('reply should use the right serializer in deep encapsulated context', t => handler: (req, reply) => { reply.send({ john: 'deep' }) } }) subInstance.setReplySerializer((payload) => { - t.deepEqual(payload, { john: 'deep' }) + t.same(payload, { john: 'deep' }) payload.john = 'deep deep' return JSON.stringify(payload) }) @@ -1479,7 +1479,7 @@ test('reply should use the right serializer in deep encapsulated context', t => url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"foo":"bar"}') + t.equal(res.payload, '{"foo":"bar"}') }) fastify.inject({ @@ -1487,7 +1487,7 @@ test('reply should use the right serializer in deep encapsulated context', t => url: '/sub' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"john":"too too"}') + t.equal(res.payload, '{"john":"too too"}') }) fastify.inject({ @@ -1495,7 +1495,7 @@ test('reply should use the right serializer in deep encapsulated context', t => url: '/deep' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"john":"deep deep"}') + t.equal(res.payload, '{"john":"deep deep"}') }) }) @@ -1513,7 +1513,7 @@ test('reply should use the route serializer', t => { handler: (req, reply) => { reply .serializer((payload) => { - t.deepEqual(payload, { john: 'doo' }) + t.same(payload, { john: 'doo' }) payload.john = 'too too' return JSON.stringify(payload) }) @@ -1526,7 +1526,7 @@ test('reply should use the route serializer', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"john":"too too"}') + t.equal(res.payload, '{"john":"too too"}') }) }) @@ -1542,7 +1542,7 @@ test('cannot set the replySerializer when the server is running', t => { fastify.setReplySerializer(() => {}) t.fail('this serializer should not be setup') } catch (e) { - t.is(e.message, 'Cannot call "setReplySerializer" when fastify instance is already started!') + t.equal(e.message, 'Cannot call "setReplySerializer" when fastify instance is already started!') } }) }) @@ -1552,7 +1552,7 @@ test('reply should not call the custom serializer for errors and not found', t = const fastify = require('../..')() fastify.setReplySerializer((payload, statusCode) => { - t.deepEqual(payload, { foo: 'bar' }) + t.same(payload, { foo: 'bar' }) t.equal(statusCode, 200) return JSON.stringify(payload) }) @@ -1565,8 +1565,8 @@ test('reply should not call the custom serializer for errors and not found', t = url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.payload, '{"foo":"bar"}') + t.equal(res.statusCode, 200) + t.equal(res.payload, '{"foo":"bar"}') }) fastify.inject({ @@ -1574,7 +1574,7 @@ test('reply should not call the custom serializer for errors and not found', t = url: '/err' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) + t.equal(res.statusCode, 500) }) fastify.inject({ @@ -1582,7 +1582,7 @@ test('reply should not call the custom serializer for errors and not found', t = url: '/not-existing' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) diff --git a/test/internals/request.test.js b/test/internals/request.test.js index d2deaa33f0..3a940c4d49 100644 --- a/test/internals/request.test.js +++ b/test/internals/request.test.js @@ -17,19 +17,19 @@ test('Regular request', t => { } const request = new Request('id', 'params', req, 'query', 'log') t.type(request, Request) - t.strictEqual(request.id, 'id') - t.strictEqual(request.params, 'params') - t.deepEqual(request.raw, req) - t.strictEqual(request.query, 'query') - t.strictEqual(request.headers, headers) - t.strictEqual(request.log, 'log') - t.strictEqual(request.ip, 'ip') - t.strictEqual(request.ips, undefined) - t.strictEqual(request.hostname, 'hostname') - t.strictEqual(request.body, null) - t.strictEqual(request.method, 'GET') - t.strictEqual(request.url, '/') - t.deepEqual(request.socket, req.socket) + t.equal(request.id, 'id') + t.equal(request.params, 'params') + t.same(request.raw, req) + t.equal(request.query, 'query') + t.equal(request.headers, headers) + t.equal(request.log, 'log') + t.equal(request.ip, 'ip') + t.equal(request.ips, undefined) + t.equal(request.hostname, 'hostname') + t.equal(request.body, null) + t.equal(request.method, 'GET') + t.equal(request.url, '/') + t.same(request.socket, req.socket) }) test('Regular request - hostname from authority', t => { @@ -46,7 +46,7 @@ test('Regular request - hostname from authority', t => { const request = new Request('id', 'params', req, 'query', 'log') t.type(request, Request) - t.strictEqual(request.hostname, 'authority') + t.equal(request.hostname, 'authority') }) test('Regular request - host header has precedence over authority', t => { @@ -63,7 +63,7 @@ test('Regular request - host header has precedence over authority', t => { } const request = new Request('id', 'params', req, 'query', 'log') t.type(request, Request) - t.strictEqual(request.hostname, 'hostname') + t.equal(request.hostname, 'hostname') }) test('Request with trust proxy', t => { @@ -82,19 +82,19 @@ test('Request with trust proxy', t => { const TpRequest = Request.buildRequest(Request, true) const request = new TpRequest('id', 'params', req, 'query', 'log') t.type(request, TpRequest) - t.strictEqual(request.id, 'id') - t.strictEqual(request.params, 'params') - t.deepEqual(request.raw, req) - t.strictEqual(request.query, 'query') - t.strictEqual(request.headers, headers) - t.strictEqual(request.log, 'log') - t.strictEqual(request.ip, '2.2.2.2') - t.deepEqual(request.ips, ['ip', '1.1.1.1', '2.2.2.2']) - t.strictEqual(request.hostname, 'example.com') - t.strictEqual(request.body, null) - t.strictEqual(request.method, 'GET') - t.strictEqual(request.url, '/') - t.deepEqual(request.socket, req.socket) + t.equal(request.id, 'id') + t.equal(request.params, 'params') + t.same(request.raw, req) + t.equal(request.query, 'query') + t.equal(request.headers, headers) + t.equal(request.log, 'log') + t.equal(request.ip, '2.2.2.2') + t.same(request.ips, ['ip', '1.1.1.1', '2.2.2.2']) + t.equal(request.hostname, 'example.com') + t.equal(request.body, null) + t.equal(request.method, 'GET') + t.equal(request.url, '/') + t.same(request.socket, req.socket) }) test('Request with trust proxy - no x-forwarded-host header', t => { @@ -113,7 +113,7 @@ test('Request with trust proxy - no x-forwarded-host header', t => { const TpRequest = Request.buildRequest(Request, true) const request = new TpRequest('id', 'params', req, 'query', 'log') t.type(request, TpRequest) - t.strictEqual(request.hostname, 'hostname') + t.equal(request.hostname, 'hostname') }) test('Request with trust proxy - no x-forwarded-host header and fallback to authority', t => { @@ -132,7 +132,7 @@ test('Request with trust proxy - no x-forwarded-host header and fallback to auth const TpRequest = Request.buildRequest(Request, true) const request = new TpRequest('id', 'params', req, 'query', 'log') t.type(request, TpRequest) - t.strictEqual(request.hostname, 'authority') + t.equal(request.hostname, 'authority') }) test('Request with trust proxy - x-forwarded-host header has precedence over host', t => { @@ -152,7 +152,7 @@ test('Request with trust proxy - x-forwarded-host header has precedence over hos const TpRequest = Request.buildRequest(Request, true) const request = new TpRequest('id', 'params', req, 'query', 'log') t.type(request, TpRequest) - t.strictEqual(request.hostname, 'example.com') + t.equal(request.hostname, 'example.com') }) test('Request with trust proxy - handles multiple entries in x-forwarded-host/proto', t => { @@ -171,6 +171,6 @@ test('Request with trust proxy - handles multiple entries in x-forwarded-host/pr const TpRequest = Request.buildRequest(Request, true) const request = new TpRequest('id', 'params', req, 'query', 'log') t.type(request, TpRequest) - t.strictEqual(request.hostname, 'example.com') - t.strictEqual(request.protocol, 'https') + t.equal(request.hostname, 'example.com') + t.equal(request.protocol, 'https') }) diff --git a/test/internals/validation.test.js b/test/internals/validation.test.js index c3f249e903..9bcf65b479 100644 --- a/test/internals/validation.test.js +++ b/test/internals/validation.test.js @@ -13,11 +13,11 @@ const { kSchemaVisited } = require('../../lib/symbols') test('Symbols', t => { t.plan(5) - t.is(typeof symbols.responseSchema, 'symbol') - t.is(typeof symbols.bodySchema, 'symbol') - t.is(typeof symbols.querystringSchema, 'symbol') - t.is(typeof symbols.paramsSchema, 'symbol') - t.is(typeof symbols.headersSchema, 'symbol') + t.equal(typeof symbols.responseSchema, 'symbol') + t.equal(typeof symbols.bodySchema, 'symbol') + t.equal(typeof symbols.querystringSchema, 'symbol') + t.equal(typeof symbols.paramsSchema, 'symbol') + t.equal(typeof symbols.headersSchema, 'symbol') }) ;['compileSchemasForValidation', @@ -26,15 +26,15 @@ test('Symbols', t => { t.plan(2) const context = {} validation[func](context) - t.is(typeof context[symbols.bodySchema], 'undefined') - t.is(typeof context[symbols.responseSchema], 'undefined') + t.equal(typeof context[symbols.bodySchema], 'undefined') + t.equal(typeof context[symbols.responseSchema], 'undefined') }) test(`${func} schema - missing output schema`, t => { t.plan(1) const context = { schema: {} } validation[func](context, null) - t.is(typeof context[symbols.responseSchema], 'undefined') + t.equal(typeof context[symbols.responseSchema], 'undefined') }) }) @@ -59,8 +59,8 @@ test('build schema - output schema', t => { } } validation.compileSchemasForSerialization(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema)) - t.is(typeof opts[symbols.responseSchema]['2xx'], 'function') - t.is(typeof opts[symbols.responseSchema]['201'], 'function') + t.equal(typeof opts[symbols.responseSchema]['2xx'], 'function') + t.equal(typeof opts[symbols.responseSchema]['201'], 'function') }) test('build schema - payload schema', t => { @@ -76,7 +76,7 @@ test('build schema - payload schema', t => { } } validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema)) - t.is(typeof opts[symbols.bodySchema], 'function') + t.equal(typeof opts[symbols.bodySchema], 'function') }) test('build schema - avoid repeated normalize schema', t => { @@ -92,9 +92,9 @@ test('build schema - avoid repeated normalize schema', t => { } } opts.schema = normalizeSchema(opts.schema) - t.notEqual(kSchemaVisited, undefined) - t.is(opts.schema[kSchemaVisited], true) - t.strictEqual(opts.schema, normalizeSchema(opts.schema)) + t.not(kSchemaVisited, undefined) + t.equal(opts.schema[kSchemaVisited], true) + t.equal(opts.schema, normalizeSchema(opts.schema)) }) test('build schema - query schema', t => { @@ -112,7 +112,7 @@ test('build schema - query schema', t => { opts.schema = normalizeSchema(opts.schema) validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema)) t.type(opts[symbols.querystringSchema].schema.type, 'string') - t.is(typeof opts[symbols.querystringSchema], 'function') + t.equal(typeof opts[symbols.querystringSchema], 'function') }) test('build schema - query schema abbreviated', t => { @@ -127,7 +127,7 @@ test('build schema - query schema abbreviated', t => { opts.schema = normalizeSchema(opts.schema) validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema)) t.type(opts[symbols.querystringSchema].schema.type, 'string') - t.is(typeof opts[symbols.querystringSchema], 'function') + t.equal(typeof opts[symbols.querystringSchema], 'function') }) test('build schema - querystring schema', t => { @@ -144,7 +144,7 @@ test('build schema - querystring schema', t => { } validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema)) t.type(opts[symbols.querystringSchema].schema.type, 'string') - t.is(typeof opts[symbols.querystringSchema], 'function') + t.equal(typeof opts[symbols.querystringSchema], 'function') }) test('build schema - querystring schema abbreviated', t => { @@ -159,7 +159,7 @@ test('build schema - querystring schema abbreviated', t => { opts.schema = normalizeSchema(opts.schema) validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema)) t.type(opts[symbols.querystringSchema].schema.type, 'string') - t.is(typeof opts[symbols.querystringSchema], 'function') + t.equal(typeof opts[symbols.querystringSchema], 'function') }) test('build schema - must throw if querystring and query schema exist', t => { @@ -183,8 +183,8 @@ test('build schema - must throw if querystring and query schema exist', t => { } opts.schema = normalizeSchema(opts.schema) } catch (err) { - t.is(err.code, 'FST_ERR_SCH_DUPLICATE') - t.is(err.message, 'Schema with \'querystring\' already present!') + t.equal(err.code, 'FST_ERR_SCH_DUPLICATE') + t.equal(err.message, 'Schema with \'querystring\' already present!') } }) @@ -201,7 +201,7 @@ test('build schema - params schema', t => { } } validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema)) - t.is(typeof opts[symbols.paramsSchema], 'function') + t.equal(typeof opts[symbols.paramsSchema], 'function') }) test('build schema - headers schema', t => { @@ -217,7 +217,7 @@ test('build schema - headers schema', t => { } } validation.compileSchemasForValidation(opts, ({ schema, method, url, httpPart }) => ajv.compile(schema)) - t.is(typeof opts[symbols.headersSchema], 'function') + t.equal(typeof opts[symbols.headersSchema], 'function') }) test('build schema - headers are lowercase', t => { diff --git a/test/internals/version.test.js b/test/internals/version.test.js index 9c1f384302..dfc73a2753 100644 --- a/test/internals/version.test.js +++ b/test/internals/version.test.js @@ -8,21 +8,21 @@ test('should output an undefined version in case of package.json not available', const Fastify = proxyquire('../..', { fs: { accessSync: () => { throw Error('error') } } }) t.plan(1) const srv = Fastify() - t.is(srv.version, undefined) + t.equal(srv.version, undefined) }) test('should output an undefined version in case of package.json is not the fastify one', t => { const Fastify = proxyquire('../..', { fs: { accessSync: () => { }, readFileSync: () => JSON.stringify({ name: 'foo', version: '6.6.6' }) } }) t.plan(1) const srv = Fastify() - t.is(srv.version, undefined) + t.equal(srv.version, undefined) }) test('should skip the version check if the version is undefined', t => { const Fastify = proxyquire('../..', { fs: { accessSync: () => { }, readFileSync: () => JSON.stringify({ name: 'foo', version: '6.6.6' }) } }) t.plan(3) const srv = Fastify() - t.is(srv.version, undefined) + t.equal(srv.version, undefined) plugin[Symbol.for('skip-override')] = false plugin[Symbol.for('plugin-meta')] = { diff --git a/test/keepAliveTimeout.test.js b/test/keepAliveTimeout.test.js index 0f797dd941..f322f04aee 100644 --- a/test/keepAliveTimeout.test.js +++ b/test/keepAliveTimeout.test.js @@ -29,7 +29,7 @@ test('keepAliveTimeout', t => { t.equal(httpsServer.keepAliveTimeout, 2) const http2Server = Fastify({ keepAliveTimeout: 3, http2: true }).server - t.notEqual(http2Server.keepAliveTimeout, 3) + t.not(http2Server.keepAliveTimeout, 3) const serverFactory = (handler, _) => { const server = http.createServer((req, res) => { diff --git a/test/listen.test.js b/test/listen.test.js index 4a3f70d109..1d51d7f747 100644 --- a/test/listen.test.js +++ b/test/listen.test.js @@ -9,9 +9,9 @@ const Fastify = require('..') test('listen accepts a callback', t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen((err) => { - t.is(fastify.server.address().address, '127.0.0.1') + t.equal(fastify.server.address().address, '127.0.0.1') t.error(err) }) }) @@ -19,9 +19,9 @@ test('listen accepts a callback', t => { test('listen accepts a port and a callback', t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, (err) => { - t.is(fastify.server.address().address, '127.0.0.1') + t.equal(fastify.server.address().address, '127.0.0.1') t.error(err) }) }) @@ -29,9 +29,9 @@ test('listen accepts a port and a callback', t => { test('listen accepts a port and a callback with (err, address)', t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, (err, address) => { - t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port) t.error(err) }) }) @@ -39,7 +39,7 @@ test('listen accepts a port and a callback with (err, address)', t => { test('listen accepts a port, address, and callback', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, '127.0.0.1', (err) => { t.error(err) }) @@ -48,7 +48,7 @@ test('listen accepts a port, address, and callback', t => { test('listen accepts options and a callback', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen({ port: 0, host: 'localhost', @@ -65,7 +65,7 @@ test('listen accepts options and a callback', t => { test('listen accepts options, backlog and a callback', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen({ port: 0, host: 'localhost' @@ -77,9 +77,9 @@ test('listen accepts options, backlog and a callback', t => { test('listen accepts a port, address and a callback with (err, address)', t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, '127.0.0.1', (err, address) => { - t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port) t.error(err) }) }) @@ -87,7 +87,7 @@ test('listen accepts a port, address and a callback with (err, address)', t => { test('listen accepts a port, address, backlog and callback', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, '127.0.0.1', 511, (err) => { t.error(err) }) @@ -96,9 +96,9 @@ test('listen accepts a port, address, backlog and callback', t => { test('listen accepts a port, address, backlog and callback with (err, address)', t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, '127.0.0.1', 511, (err, address) => { - t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port) t.error(err) }) }) @@ -106,12 +106,12 @@ test('listen accepts a port, address, backlog and callback with (err, address)', test('listen after Promise.resolve()', t => { t.plan(2) const f = Fastify() - t.tearDown(f.close.bind(f)) + t.teardown(f.close.bind(f)) Promise.resolve() .then(() => { f.listen(0, (err, address) => { f.server.unref() - t.is(address, 'http://127.0.0.1:' + f.server.address().port) + t.equal(address, 'http://127.0.0.1:' + f.server.address().port) t.error(err) }) }) @@ -138,11 +138,11 @@ test('register after listen using Promise.resolve()', t => { test('double listen errors', t => { t.plan(3) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, (err) => { t.error(err) fastify.listen(fastify.server.address().port, (err, address) => { - t.is(address, null) + t.equal(address, null) t.ok(err) }) }) @@ -151,12 +151,12 @@ test('double listen errors', t => { test('double listen errors callback with (err, address)', t => { t.plan(4) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, (err1, address1) => { - t.is(address1, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address1, 'http://127.0.0.1:' + fastify.server.address().port) t.error(err1) fastify.listen(fastify.server.address().port, (err2, address2) => { - t.is(address2, null) + t.equal(address2, null) t.ok(err2) }) }) @@ -165,14 +165,14 @@ test('double listen errors callback with (err, address)', t => { test('listen twice on the same port', t => { t.plan(4) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, (err1, address1) => { - t.is(address1, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address1, 'http://127.0.0.1:' + fastify.server.address().port) t.error(err1) const s2 = Fastify() - t.tearDown(s2.close.bind(s2)) + t.teardown(s2.close.bind(s2)) s2.listen(fastify.server.address().port, (err2, address2) => { - t.is(address2, null) + t.equal(address2, null) t.ok(err2) }) }) @@ -181,15 +181,15 @@ test('listen twice on the same port', t => { test('listen twice on the same port callback with (err, address)', t => { t.plan(4) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, (err1, address1) => { const _port = fastify.server.address().port - t.is(address1, 'http://127.0.0.1:' + _port) + t.equal(address1, 'http://127.0.0.1:' + _port) t.error(err1) const s2 = Fastify() - t.tearDown(s2.close.bind(s2)) + t.teardown(s2.close.bind(s2)) s2.listen(_port, (err2, address2) => { - t.is(address2, null) + t.equal(address2, null) t.ok(err2) }) }) @@ -200,7 +200,7 @@ if (os.platform() !== 'win32') { test('listen on socket', t => { t.plan(3) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) const sockFile = path.join(os.tmpdir(), `${(Math.random().toString(16) + '0000000').substr(2, 8)}-server.sock`) try { @@ -218,67 +218,67 @@ if (os.platform() !== 'win32') { test('listen without callback (port zero)', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0) .then(() => { - t.is(fastify.server.address().address, '127.0.0.1') + t.equal(fastify.server.address().address, '127.0.0.1') }) }) test('listen without callback (port not given)', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen() .then(() => { - t.is(fastify.server.address().address, '127.0.0.1') + t.equal(fastify.server.address().address, '127.0.0.1') }) }) test('listen null without callback with (address)', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(null) .then(address => { - t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port) }) }) test('listen without port without callback with (address)', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen() .then(address => { - t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port) }) }) test('listen with undefined without callback with (address)', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(undefined) .then(address => { - t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port) }) }) test('listen without callback with (address)', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0) .then(address => { - t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port) }) }) test('double listen without callback rejects', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0) .then(() => { fastify.listen(0) @@ -292,10 +292,10 @@ test('double listen without callback rejects', t => { test('double listen without callback with (address)', t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0) .then(address => { - t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) + t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port) fastify.listen(0) .catch(err => { t.ok(err) @@ -307,12 +307,12 @@ test('double listen without callback with (address)', t => { test('listen twice on the same port without callback rejects', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0) .then(() => { const s2 = Fastify() - t.tearDown(s2.close.bind(s2)) + t.teardown(s2.close.bind(s2)) s2.listen(fastify.server.address().port) .catch(err => { t.ok(err) @@ -324,12 +324,12 @@ test('listen twice on the same port without callback rejects', t => { test('listen twice on the same port without callback rejects with (address)', t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0) .then(address => { const s2 = Fastify() - t.tearDown(s2.close.bind(s2)) - t.is(address, 'http://127.0.0.1:' + fastify.server.address().port) + t.teardown(s2.close.bind(s2)) + t.equal(address, 'http://127.0.0.1:' + fastify.server.address().port) s2.listen(fastify.server.address().port) .catch(err => { t.ok(err) @@ -340,7 +340,7 @@ test('listen twice on the same port without callback rejects with (address)', t test('listen on invalid port without callback rejects', t => { const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) return fastify.listen(-1) .catch(err => { t.ok(err) @@ -351,7 +351,7 @@ test('listen on invalid port without callback rejects', t => { test('listen logs the port as info', t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) const msgs = [] fastify.log.info = function (msg) { @@ -367,15 +367,15 @@ test('listen logs the port as info', t => { test('listen when firstArg is string(pipe) and without backlog', async t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) const address = await fastify.listen('\\\\.\\pipe\\testPipe') - t.is(address, '\\\\.\\pipe\\testPipe') + t.equal(address, '\\\\.\\pipe\\testPipe') }) test('listen when firstArg is string(pipe) and with backlog', async t => { t.plan(1) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) const address = await fastify.listen('\\\\.\\pipe\\testPipe', 511) - t.is(address, '\\\\.\\pipe\\testPipe') + t.equal(address, '\\\\.\\pipe\\testPipe') }) diff --git a/test/logger.test.js b/test/logger.test.js index e0975305f9..70c44eee41 100644 --- a/test/logger.test.js +++ b/test/logger.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test, tearDown } = require('tap') +const { test, teardown } = require('tap') const http = require('http') const stream = require('stream') const split = require('split2') @@ -20,7 +20,7 @@ function file () { return file } -tearDown(() => { +teardown(() => { files.forEach((file) => { try { fs.unlinkSync(file) @@ -211,7 +211,7 @@ test('can use external logger instance with custom serializer', t => { const key = check[0] const value = check[1] - t.deepEqual(line[key], value) + t.same(line[key], value) }) const logger = require('pino')({ @@ -262,7 +262,7 @@ test('expose the logger', t => { } t.ok(fastify.log) - t.is(typeof fastify.log, 'object') + t.same(typeof fastify.log, 'object') }) test('The request id header key can be customized', t => { @@ -274,7 +274,7 @@ test('The request id header key can be customized', t => { logger: { stream: stream, level: 'info' }, requestIdHeader: 'my-custom-request-id' }) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) fastify.get('/', (req, reply) => { t.equal(req.id, REQUEST_ID) @@ -322,7 +322,7 @@ test('The request id header key can be customized along with a custom id generat return 'foo' } }) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) fastify.get('/one', (req, reply) => { t.equal(req.id, REQUEST_ID) @@ -383,7 +383,7 @@ test('The request id log label can be changed', t => { requestIdHeader: 'my-custom-request-id', requestIdLogLabel: 'traceId' }) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) fastify.get('/one', (req, reply) => { t.equal(req.id, REQUEST_ID) @@ -450,12 +450,12 @@ test('The logger should accept custom serializer', t => { stream.once('data', line => { t.ok(line.req, 'req is defined') t.equal(line.msg, 'incoming request', 'message is set') - t.deepEqual(line.req, { url: '/custom' }, 'custom req serializer is use') + t.same(line.req, { url: '/custom' }, 'custom req serializer is use') stream.once('data', line => { t.ok(line.res, 'res is defined') t.equal(line.msg, 'kaboom', 'message is set') - t.deepEqual(line.res, { statusCode: 500 }, 'default res serializer is use') + t.same(line.res, { statusCode: 500 }, 'default res serializer is use') }) }) }) @@ -468,7 +468,7 @@ test('reply.send logs an error if called twice in a row', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, lines.shift()) + t.same(line.msg, lines.shift()) }) const logger = pino(splitStream) @@ -489,7 +489,7 @@ test('reply.send logs an error if called twice in a row', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -499,25 +499,25 @@ test('logger can be silented', t => { logger: false }) t.ok(fastify.log) - t.is(typeof fastify.log, 'object') - t.is(typeof fastify.log.fatal, 'function') - t.is(typeof fastify.log.error, 'function') - t.is(typeof fastify.log.warn, 'function') - t.is(typeof fastify.log.info, 'function') - t.is(typeof fastify.log.debug, 'function') - t.is(typeof fastify.log.trace, 'function') - t.is(typeof fastify.log.child, 'function') + t.same(typeof fastify.log, 'object') + t.same(typeof fastify.log.fatal, 'function') + t.same(typeof fastify.log.error, 'function') + t.same(typeof fastify.log.warn, 'function') + t.same(typeof fastify.log.info, 'function') + t.same(typeof fastify.log.debug, 'function') + t.same(typeof fastify.log.trace, 'function') + t.same(typeof fastify.log.child, 'function') const childLog = fastify.log.child() - t.is(typeof childLog, 'object') - t.is(typeof childLog.fatal, 'function') - t.is(typeof childLog.error, 'function') - t.is(typeof childLog.warn, 'function') - t.is(typeof childLog.info, 'function') - t.is(typeof childLog.debug, 'function') - t.is(typeof childLog.trace, 'function') - t.is(typeof childLog.child, 'function') + t.same(typeof childLog, 'object') + t.same(typeof childLog.fatal, 'function') + t.same(typeof childLog.error, 'function') + t.same(typeof childLog.warn, 'function') + t.same(typeof childLog.info, 'function') + t.same(typeof childLog.debug, 'function') + t.same(typeof childLog.trace, 'function') + t.same(typeof childLog.child, 'function') }) test('Should set a custom logLevel for a plugin', t => { @@ -526,7 +526,7 @@ test('Should set a custom logLevel for a plugin', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, lines.shift()) + t.same(line.msg, lines.shift()) }) const logger = pino({ level: 'error' }, splitStream) @@ -554,7 +554,7 @@ test('Should set a custom logLevel for a plugin', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) fastify.inject({ @@ -563,7 +563,7 @@ test('Should set a custom logLevel for a plugin', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -573,7 +573,7 @@ test('Should set a custom logSerializers for a plugin', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { if (line.test) { - t.is(line.test, 'XHello') + t.same(line.test, 'XHello') } }) @@ -597,7 +597,7 @@ test('Should set a custom logSerializers for a plugin', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -646,7 +646,7 @@ test('Should set a custom logLevel for every plugin', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) fastify.inject({ @@ -655,7 +655,7 @@ test('Should set a custom logLevel for every plugin', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) fastify.inject({ @@ -664,7 +664,7 @@ test('Should set a custom logLevel for every plugin', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -675,7 +675,7 @@ test('Should set a custom logSerializers for every plugin', async t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { if (line.test) { - t.is(line.test, lines.shift()) + t.same(line.test, lines.shift()) } }) @@ -709,19 +709,19 @@ test('Should set a custom logSerializers for every plugin', async t => { method: 'GET', url: '/' }) - t.deepEqual(res.json(), { hello: 'world' }) + t.same(res.json(), { hello: 'world' }) res = await fastify.inject({ method: 'GET', url: '/test1' }) - t.deepEqual(res.json(), { hello: 'world' }) + t.same(res.json(), { hello: 'world' }) res = await fastify.inject({ method: 'GET', url: '/test2' }) - t.deepEqual(res.json(), { hello: 'world' }) + t.same(res.json(), { hello: 'world' }) }) test('Should override serializers from route', t => { @@ -730,7 +730,7 @@ test('Should override serializers from route', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { if (line.test) { - t.is(line.test, 'ZHello') + t.same(line.test, 'ZHello') } }) @@ -757,7 +757,7 @@ test('Should override serializers from route', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -767,7 +767,7 @@ test('Should override serializers from plugin', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { if (line.test) { - t.is(line.test, 'ZHello') + t.same(line.test, 'ZHello') } }) @@ -799,7 +799,7 @@ test('Should override serializers from plugin', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -809,10 +809,10 @@ test('Should use serializers from plugin and route', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { if (line.test) { - t.is(line.test, 'XHello') + t.same(line.test, 'XHello') } if (line.test2) { - t.is(line.test2, 'ZHello') + t.same(line.test2, 'ZHello') } }) @@ -843,7 +843,7 @@ test('Should use serializers from plugin and route', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -853,10 +853,10 @@ test('Should use serializers from instance fastify and route', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { if (line.test) { - t.is(line.test, 'XHello') + t.same(line.test, 'XHello') } if (line.test2) { - t.is(line.test2, 'ZHello') + t.same(line.test2, 'ZHello') } }) @@ -886,7 +886,7 @@ test('Should use serializers from instance fastify and route', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -896,9 +896,9 @@ test('Should use serializers inherit from contexts', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { if (line.test && line.test2 && line.test3) { - t.is(line.test, 'XHello') - t.is(line.test2, 'YHello') - t.is(line.test3, 'ZHello') + t.same(line.test, 'XHello') + t.same(line.test2, 'YHello') + t.same(line.test3, 'ZHello') } }) @@ -930,7 +930,7 @@ test('Should use serializers inherit from contexts', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -939,7 +939,7 @@ test('Should increase the log level for a specific plugin', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, 'Hello') + t.same(line.msg, 'Hello') t.ok(line.level === 50) }) @@ -963,7 +963,7 @@ test('Should increase the log level for a specific plugin', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -972,7 +972,7 @@ test('Should set the log level for the customized 404 handler', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, 'Hello') + t.same(line.msg, 'Hello') t.ok(line.level === 50) }) @@ -995,7 +995,7 @@ test('Should set the log level for the customized 404 handler', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -1004,7 +1004,7 @@ test('Should set the log level for the customized 500 handler', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, 'Hello') + t.same(line.msg, 'Hello') t.ok(line.level === 60) }) @@ -1032,7 +1032,7 @@ test('Should set the log level for the customized 500 handler', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 500) + t.equal(res.statusCode, 500) }) }) @@ -1042,7 +1042,7 @@ test('Should set a custom log level for a specific route', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, lines.shift()) + t.same(line.msg, lines.shift()) }) const logger = pino({ level: 'error' }, splitStream) @@ -1067,7 +1067,7 @@ test('Should set a custom log level for a specific route', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) fastify.inject({ @@ -1076,7 +1076,7 @@ test('Should set a custom log level for a specific route', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -1091,7 +1091,7 @@ test('The default 404 handler logs the incoming request', t => { const splitStream = split(JSON.parse) splitStream.on('data', (line) => { - t.is(line.msg, expectedMessages.shift()) + t.same(line.msg, expectedMessages.shift()) }) const logger = pino({ level: 'trace' }, splitStream) @@ -1105,7 +1105,7 @@ test('The default 404 handler logs the incoming request', t => { url: '/not-found' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -1130,8 +1130,8 @@ test('should serialize request and response', t => { }, (e, res) => { const l = lines.find((line) => line.res && line.res.statusCode === 500) t.ok(l.req) - t.is(l.req.method, 'GET') - t.is(l.req.url, '/500') + t.same(l.req.method, 'GET') + t.same(l.req.url, '/500') }) }) @@ -1160,7 +1160,7 @@ test('should serialize request and response', t => { stream.once('data', line => { const expected = 'Server listening at http://[' + ipv6 + ']:' + fastify.server.address().port - t.is(line.msg, expected) + t.same(line.msg, expected) fastify.close() }) }) @@ -1182,7 +1182,7 @@ test('Do not wrap IPv4 address', t => { stream.once('data', line => { const expected = 'Server listening at http://127.0.0.1:' + fastify.server.address().port - t.is(line.msg, expected) + t.same(line.msg, expected) fastify.close() }) }) @@ -1262,7 +1262,7 @@ test('should log the error if no error handler is defined', t => { t.equal(line.msg, 'a generic error', 'message is set') stream.once('data', line => { t.equal(line.msg, 'request completed', 'message is set') - t.deepEqual(line.res, { statusCode: 500 }, 'status code is set') + t.same(line.res, { statusCode: 500 }, 'status code is set') }) }) }) @@ -1300,7 +1300,7 @@ test('should log as info if error status code >= 400 and < 500 if no error handl t.equal(line.msg, 'a 400 error', 'message is set') stream.once('data', line => { t.equal(line.msg, 'request completed', 'message is set') - t.deepEqual(line.res, { statusCode: 400 }, 'status code is set') + t.same(line.res, { statusCode: 400 }, 'status code is set') }) }) }) @@ -1334,7 +1334,7 @@ test('should log as error if error status code >= 500 if no error handler is def t.equal(line.msg, 'a 503 error', 'message is set') stream.once('data', line => { t.equal(line.msg, 'request completed', 'message is set') - t.deepEqual(line.res, { statusCode: 503 }, 'status code is set') + t.same(line.res, { statusCode: 503 }, 'status code is set') }) }) }) @@ -1369,7 +1369,7 @@ test('should not log the error if error handler is defined', t => { stream.once('data', line => { t.equal(line.level, 30, 'level is correct') t.equal(line.msg, 'request completed', 'message is set') - t.deepEqual(line.res, { statusCode: 500 }, 'status code is set') + t.same(line.res, { statusCode: 500 }, 'status code is set') }) }) }) @@ -1400,7 +1400,7 @@ test('should not rely on raw request to log errors', t => { stream.once('data', line => { t.equal(line.level, 30, 'level is correct') t.equal(line.msg, 'something happened', 'message is set') - t.deepEqual(line.res, { statusCode: 415 }, 'status code is set') + t.same(line.res, { statusCode: 415 }, 'status code is set') }) }) }) @@ -1430,7 +1430,7 @@ test('should redact the authorization header if so specified', t => { } }) fastify.get('/', function (req, reply) { - t.is(req.headers.authorization, 'Bearer abcde') + t.same(req.headers.authorization, 'Bearer abcde') reply.send({ hello: 'world' }) }) stream.once('data', listenAtLogLine => { @@ -1450,8 +1450,8 @@ test('should redact the authorization header if so specified', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(body.toString(), JSON.stringify({ hello: 'world' })) + t.equal(response.statusCode, 200) + t.same(body.toString(), JSON.stringify({ hello: 'world' })) }) }) }) @@ -1475,9 +1475,9 @@ test('should not log incoming request and outgoing response when disabled', t => url: '/500', method: 'GET' }, (e, res) => { - t.is(lines.length, 1) + t.same(lines.length, 1) t.ok(lines[0].msg) - t.is(lines[0].msg, '500 error') + t.same(lines[0].msg, '500 error') }) }) diff --git a/test/middleware.test.js b/test/middleware.test.js index 01e62797c7..976c9c6a9e 100644 --- a/test/middleware.test.js +++ b/test/middleware.test.js @@ -23,7 +23,7 @@ test('Should be able to override the default use API', t => { t.plan(1) const fastify = Fastify() fastify.decorate('use', () => true) - t.strictEqual(fastify.use(), true) + t.equal(fastify.use(), true) }) test('Cannot decorate use twice', t => { @@ -43,7 +43,7 @@ test('Encapsulation works', t => { fastify.register((instance, opts, done) => { instance.decorate('use', () => true) - t.strictEqual(instance.use(), true) + t.equal(instance.use(), true) done() }) diff --git a/test/nullable-validation.test.js b/test/nullable-validation.test.js index 87f3f6c5c1..28be199a9b 100644 --- a/test/nullable-validation.test.js +++ b/test/nullable-validation.test.js @@ -61,7 +61,7 @@ test('object or null body', t => { method: 'POST', url: '/', handler: (req, reply) => { - t.strictEqual(req.body, null) + t.equal(req.body, null) reply.code(200).send({ requestBody: req.body }) }, schema: { @@ -99,8 +99,8 @@ test('object or null body', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { requestBody: null }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { requestBody: null }) }) }) }) @@ -114,7 +114,7 @@ test('nullable body', t => { method: 'POST', url: '/', handler: (req, reply) => { - t.strictEqual(req.body, null) + t.equal(req.body, null) reply.code(200).send({ requestBody: req.body }) }, schema: { @@ -153,8 +153,8 @@ test('nullable body', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { requestBody: null }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { requestBody: null }) }) }) }) diff --git a/test/output-validation.test.js b/test/output-validation.test.js index 307dea6416..65b2a5e575 100644 --- a/test/output-validation.test.js +++ b/test/output-validation.test.js @@ -101,9 +101,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/string' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -114,9 +114,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/number' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 201) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 55 }) + t.equal(response.statusCode, 201) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 55 }) }) }) @@ -127,9 +127,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/wrong-object-for-schema' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 201) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), {}) + t.equal(response.statusCode, 201) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), {}) }) }) @@ -140,7 +140,7 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/empty' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 204) + t.equal(response.statusCode, 204) }) }) @@ -151,9 +151,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/400' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'DOOM' }) + t.equal(response.statusCode, 400) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'DOOM' }) }) }) }) diff --git a/test/plugin.test.js b/test/plugin.test.js index 491fd240de..d513dcf890 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -30,7 +30,7 @@ test('plugin metadata - ignore prefix', t => { url: '/' }, function (err, res) { t.error(err) - t.equals(res.payload, 'hello') + t.equal(res.payload, 'hello') }) function plugin (instance, opts, done) { @@ -80,9 +80,9 @@ test('fastify.register with fastify-plugin should not encapsulate his code', t = url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -139,7 +139,7 @@ test('fastify.register with fastify-plugin should provide access to external fas // the decoration is added at the end instance.after(() => { t.ok(instance.global) - t.strictEqual(instance.global_2(), 'hello') + t.equal(instance.global_2(), 'hello') t.notOk(instance.local) }) @@ -159,9 +159,9 @@ test('fastify.register with fastify-plugin should provide access to external fas url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -214,9 +214,9 @@ test('fastify.register with fastify-plugin registers root level plugins', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { test: 'first' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { test: 'first' }) }) sget({ @@ -224,9 +224,9 @@ test('fastify.register with fastify-plugin registers root level plugins', t => { url: 'http://localhost:' + fastify.server.address().port + '/test2' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { test2: 'second' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { test2: 'second' }) }) }) }) @@ -276,9 +276,9 @@ test('check dependencies - should not throw', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -293,8 +293,8 @@ test('check dependencies - should throw', t => { i.decorate('otherTest', () => {}, ['test']) t.fail() } catch (e) { - t.is(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') - t.is(e.message, 'The decorator is missing dependency \'test\'.') + t.equal(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') + t.equal(e.message, 'The decorator is missing dependency \'test\'.') } n() })) @@ -328,9 +328,9 @@ test('check dependencies - should throw', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -340,20 +340,20 @@ test('set the plugin name based on the plugin displayName symbol', t => { const fastify = Fastify() fastify.register(fp((fastify, opts, done) => { - t.strictEqual(fastify.pluginName, 'plugin-A') + t.equal(fastify.pluginName, 'plugin-A') fastify.register(fp((fastify, opts, done) => { - t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB') + t.equal(fastify.pluginName, 'plugin-A -> plugin-AB') done() }, { name: 'plugin-AB' })) fastify.register(fp((fastify, opts, done) => { - t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC') + t.equal(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC') done() }, { name: 'plugin-AC' })) done() }, { name: 'plugin-A' })) fastify.register(fp((fastify, opts, done) => { - t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC -> plugin-B') + t.equal(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC -> plugin-B') done() }, { name: 'plugin-B' })) @@ -371,18 +371,18 @@ test('plugin name will change when using no encapsulation', t => { // store it in a different variable will hold the correct name const pluginName = fastify.pluginName fastify.register(fp((fastify, opts, done) => { - t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB') + t.equal(fastify.pluginName, 'plugin-A -> plugin-AB') done() }, { name: 'plugin-AB' })) fastify.register(fp((fastify, opts, done) => { - t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC') + t.equal(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC') done() }, { name: 'plugin-AC' })) setImmediate(() => { // normally we would expect the name plugin-A // but we operate on the same instance in each plugin - t.strictEqual(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC') - t.strictEqual(pluginName, 'plugin-A') + t.equal(fastify.pluginName, 'plugin-A -> plugin-AB -> plugin-AC') + t.equal(pluginName, 'plugin-A') }) done() }, { name: 'plugin-A' })) @@ -397,7 +397,7 @@ test('plugin name is undefined when accessing in no plugin context', t => { t.plan(2) const fastify = Fastify() - t.strictEqual(fastify.pluginName, undefined) + t.equal(fastify.pluginName, undefined) fastify.listen(0, err => { t.error(err) @@ -410,20 +410,20 @@ test('set the plugin name based on the plugin function name', t => { const fastify = Fastify() fastify.register(function myPluginA (fastify, opts, done) { - t.strictEqual(fastify.pluginName, 'myPluginA') + t.equal(fastify.pluginName, 'myPluginA') fastify.register(function myPluginAB (fastify, opts, done) { - t.strictEqual(fastify.pluginName, 'myPluginAB') + t.equal(fastify.pluginName, 'myPluginAB') done() }) setImmediate(() => { // exact name due to encapsulation - t.strictEqual(fastify.pluginName, 'myPluginA') + t.equal(fastify.pluginName, 'myPluginA') }) done() }) fastify.register(function myPluginB (fastify, opts, done) { - t.strictEqual(fastify.pluginName, 'myPluginB') + t.equal(fastify.pluginName, 'myPluginB') done() }) @@ -439,17 +439,17 @@ test('approximate a plugin name when no meta data is available', t => { fastify.register((fastify, opts, done) => { // A - t.is(fastify.pluginName.startsWith('(fastify, opts, done)'), true) - t.is(fastify.pluginName.includes('// A'), true) + t.equal(fastify.pluginName.startsWith('(fastify, opts, done)'), true) + t.equal(fastify.pluginName.includes('// A'), true) fastify.register((fastify, opts, done) => { // B - t.is(fastify.pluginName.startsWith('(fastify, opts, done)'), true) - t.is(fastify.pluginName.includes('// B'), true) + t.equal(fastify.pluginName.startsWith('(fastify, opts, done)'), true) + t.equal(fastify.pluginName.includes('// B'), true) done() }) setImmediate(() => { - t.is(fastify.pluginName.startsWith('(fastify, opts, done)'), true) - t.is(fastify.pluginName.includes('// A'), true) + t.equal(fastify.pluginName.startsWith('(fastify, opts, done)'), true) + t.equal(fastify.pluginName.includes('// A'), true) }) done() }) @@ -526,9 +526,9 @@ test('plugin encapsulation', t => { url: 'http://localhost:' + fastify.server.address().port + '/first' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { plugin: 'first' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { plugin: 'first' }) }) sget({ @@ -536,9 +536,9 @@ test('plugin encapsulation', t => { url: 'http://localhost:' + fastify.server.address().port + '/second' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { plugin: 'second' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { plugin: 'second' }) }) }) }) @@ -553,7 +553,7 @@ test('if a plugin raises an error and there is not a callback to handle it, the fastify.listen(0, err => { t.ok(err instanceof Error) - t.is(err.message, 'err') + t.equal(err.message, 'err') }) }) @@ -602,7 +602,7 @@ test('add hooks after route declaration', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.deepEqual(JSON.parse(body), { hook1: true, hook2: true, hook3: true }) + t.same(JSON.parse(body), { hook1: true, hook2: true, hook3: true }) fastify.close() }) }) @@ -613,7 +613,7 @@ test('nested plugins', t => { const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.register(function (fastify, opts, done) { fastify.register((fastify, opts, done) => { @@ -641,7 +641,7 @@ test('nested plugins', t => { url: 'http://localhost:' + fastify.server.address().port + '/parent/child1' }, (err, response, body) => { t.error(err) - t.deepEqual(body.toString(), 'I am child 1') + t.same(body.toString(), 'I am child 1') }) sget({ @@ -649,7 +649,7 @@ test('nested plugins', t => { url: 'http://localhost:' + fastify.server.address().port + '/parent/child2' }, (err, response, body) => { t.error(err) - t.deepEqual(body.toString(), 'I am child 2') + t.same(body.toString(), 'I am child 2') }) }) }) @@ -659,7 +659,7 @@ test('nested plugins awaited', t => { const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.register(async function wrap (fastify, opts) { await fastify.register(async function child1 (fastify, opts) { @@ -683,7 +683,7 @@ test('nested plugins awaited', t => { url: 'http://localhost:' + fastify.server.address().port + '/parent/child1' }, (err, response, body) => { t.error(err) - t.deepEqual(body.toString(), 'I am child 1') + t.same(body.toString(), 'I am child 1') }) sget({ @@ -691,7 +691,7 @@ test('nested plugins awaited', t => { url: 'http://localhost:' + fastify.server.address().port + '/parent/child2' }, (err, response, body) => { t.error(err) - t.deepEqual(body.toString(), 'I am child 2') + t.same(body.toString(), 'I am child 2') }) }) }) @@ -743,7 +743,7 @@ test('plugin metadata - decorators - should throw', t => { fastify.register(plugin) fastify.ready((err) => { - t.equals(err.message, "The decorator 'plugin1' is not present in Request") + t.equal(err.message, "The decorator 'plugin1' is not present in Request") }) function plugin (instance, opts, done) { @@ -771,7 +771,7 @@ test('plugin metadata - decorators - should throw with plugin name', t => { fastify.register(plugin) fastify.ready((err) => { - t.equals(err.message, "The decorator 'plugin1' required by 'the-plugin' is not present in Request") + t.equal(err.message, "The decorator 'plugin1' required by 'the-plugin' is not present in Request") }) function plugin (instance, opts, done) { @@ -874,7 +874,7 @@ test('pluginTimeout default', t => { t.equal(err.code, 'ERR_AVVIO_PLUGIN_TIMEOUT') }) - t.tearDown(clock.uninstall) + t.teardown(clock.uninstall) }) test('plugin metadata - version', t => { diff --git a/test/pretty-print.test.js b/test/pretty-print.test.js index 793b83b675..bf8ef22735 100644 --- a/test/pretty-print.test.js +++ b/test/pretty-print.test.js @@ -21,7 +21,7 @@ test('pretty print - static routes', t => { └── hello/world (GET) ` - t.is(typeof tree, 'string') + t.equal(typeof tree, 'string') t.equal(tree, expected) }) }) @@ -43,7 +43,7 @@ test('pretty print - parametric routes', t => { └── hello/:world (GET) ` - t.is(typeof tree, 'string') + t.equal(typeof tree, 'string') t.equal(tree, expected) }) }) @@ -67,7 +67,7 @@ test('pretty print - mixed parametric routes', t => { └── /world (GET) ` - t.is(typeof tree, 'string') + t.equal(typeof tree, 'string') t.equal(tree, expected) }) }) @@ -89,7 +89,7 @@ test('pretty print - wildcard routes', t => { └── hello/* (GET) ` - t.is(typeof tree, 'string') + t.equal(typeof tree, 'string') t.equal(tree, expected) }) }) @@ -100,7 +100,7 @@ test('pretty print - empty plugins', t => { const fastify = Fastify() fastify.ready(() => { const tree = fastify.printPlugins() - t.is(typeof tree, 'string') + t.equal(typeof tree, 'string') t.match(tree, 'bound root') }) }) @@ -115,7 +115,7 @@ test('pretty print - nested plugins', t => { }) fastify.ready(() => { const tree = fastify.printPlugins() - t.is(typeof tree, 'string') + t.equal(typeof tree, 'string') t.match(tree, 'foo') t.match(tree, 'bar') t.match(tree, 'baz') diff --git a/test/promises.test.js b/test/promises.test.js index 29c21c509a..8ba016082a 100644 --- a/test/promises.test.js +++ b/test/promises.test.js @@ -71,9 +71,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/return' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -84,7 +84,7 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/return-error' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) }) @@ -96,8 +96,8 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/double' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { hello: '42' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: '42' }) }) }) @@ -108,9 +108,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/thenable' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -121,7 +121,7 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/thenable-error' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) }) @@ -132,9 +132,9 @@ fastify.listen(0, err => { url: 'http://localhost:' + fastify.server.address().port + '/return-reply' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) diff --git a/test/proto-poisoning.test.js b/test/proto-poisoning.test.js index b1a7232962..6b340f6273 100644 --- a/test/proto-poisoning.test.js +++ b/test/proto-poisoning.test.js @@ -9,7 +9,7 @@ test('proto-poisoning error', t => { t.plan(3) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.post('/', (request, reply) => { t.fail('handler should not be called') @@ -25,7 +25,7 @@ test('proto-poisoning error', t => { body: '{ "__proto__": { "a": 42 } }' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) + t.equal(response.statusCode, 400) }) }) }) @@ -34,7 +34,7 @@ test('proto-poisoning remove', t => { t.plan(4) const fastify = Fastify({ onProtoPoisoning: 'remove' }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.post('/', (request, reply) => { t.equal(undefined, Object.assign({}, request.body).a) @@ -51,7 +51,7 @@ test('proto-poisoning remove', t => { body: '{ "__proto__": { "a": 42 }, "b": 42 }' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) }) @@ -60,7 +60,7 @@ test('proto-poisoning ignore', t => { t.plan(4) const fastify = Fastify({ onProtoPoisoning: 'ignore' }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.post('/', (request, reply) => { t.equal(42, Object.assign({}, request.body).a) @@ -77,7 +77,7 @@ test('proto-poisoning ignore', t => { body: '{ "__proto__": { "a": 42 }, "b": 42 }' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) }) @@ -86,7 +86,7 @@ test('constructor-poisoning error (default in v3)', t => { t.plan(3) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.post('/', (request, reply) => { reply.send('ok') @@ -102,7 +102,7 @@ test('constructor-poisoning error (default in v3)', t => { body: '{ "constructor": { "prototype": { "foo": "bar" } } }' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) + t.equal(response.statusCode, 400) }) }) }) @@ -111,7 +111,7 @@ test('constructor-poisoning error', t => { t.plan(3) const fastify = Fastify({ onConstructorPoisoning: 'error' }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.post('/', (request, reply) => { t.fail('handler should not be called') @@ -127,7 +127,7 @@ test('constructor-poisoning error', t => { body: '{ "constructor": { "prototype": { "foo": "bar" } } }' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 400) + t.equal(response.statusCode, 400) }) }) }) @@ -136,7 +136,7 @@ test('constructor-poisoning remove', t => { t.plan(4) const fastify = Fastify({ onConstructorPoisoning: 'remove' }) - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.post('/', (request, reply) => { t.equal(undefined, Object.assign({}, request.body).foo) @@ -153,7 +153,7 @@ test('constructor-poisoning remove', t => { body: '{ "constructor": { "prototype": { "foo": "bar" } } }' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) }) diff --git a/test/register.test.js b/test/register.test.js index 47ad05f6bf..4c791125ed 100644 --- a/test/register.test.js +++ b/test/register.test.js @@ -13,11 +13,11 @@ test('register', t => { const fastify = Fastify() fastify.register(function (instance, opts, done) { - t.notEqual(instance, fastify) + t.not(instance, fastify) t.ok(fastify.isPrototypeOf(instance)) - t.is(typeof opts, 'object') - t.is(typeof done, 'function') + t.equal(typeof opts, 'object') + t.equal(typeof done, 'function') instance.get('/first', function (req, reply) { reply.send({ hello: 'world' }) @@ -26,11 +26,11 @@ test('register', t => { }) fastify.register(function (instance, opts, done) { - t.notEqual(instance, fastify) + t.not(instance, fastify) t.ok(fastify.isPrototypeOf(instance)) - t.is(typeof opts, 'object') - t.is(typeof done, 'function') + t.equal(typeof opts, 'object') + t.equal(typeof done, 'function') instance.get('/second', function (req, reply) { reply.send({ hello: 'world' }) @@ -52,9 +52,9 @@ test('register', t => { url: 'http://localhost:' + fastify.server.address().port + '/' + path }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.strictEqual(response.headers['content-length'], '' + body.length) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.equal(response.headers['content-length'], '' + body.length) + t.same(JSON.parse(body), { hello: 'world' }) }) } }) @@ -73,7 +73,7 @@ test('internal route declaration should pass the error generated by the register fastify.listen(0, err => { fastify.close() - t.is(err.message, 'kaboom') + t.equal(err.message, 'kaboom') }) }) @@ -90,7 +90,7 @@ test('internal route declaration should pass the error generated by the register }) fastify.after(err => { - t.is(err.message, 'kaboom') + t.equal(err.message, 'kaboom') }) fastify.listen(0, err => { @@ -109,21 +109,21 @@ test('awaitable register and after', async t => { first = true }) - t.is(first, true) + t.equal(first, true) fastify.register(async (instance, opts, done) => { second = true }) await fastify.after() - t.is(second, true) + t.equal(second, true) fastify.register(async (instance, opts, done) => { third = true }) await fastify.ready() - t.is(third, true) + t.equal(third, true) }) function thenableRejects (t, promise, error) { diff --git a/test/reply-error.test.js b/test/reply-error.test.js index ad2658a983..bb9f58cbb5 100644 --- a/test/reply-error.test.js +++ b/test/reply-error.test.js @@ -29,9 +29,9 @@ function helper (code) { url: '/' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, Number(code)) + t.equal(res.statusCode, Number(code)) t.equal(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual( + t.same( { error: statusCodes[code], message: err.message, @@ -60,8 +60,8 @@ test('preHandler hook error handling with external code', t => { url: '/' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 400) - t.deepEqual( + t.equal(res.statusCode, 400) + t.same( { error: statusCodes['400'], message: err.message, @@ -89,8 +89,8 @@ test('onRequest hook error handling with external done', t => { url: '/' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 400) - t.deepEqual( + t.equal(res.statusCode, 400) + t.same( { error: statusCodes['400'], message: err.message, @@ -192,8 +192,8 @@ test('Error instance sets HTTP status code', t => { url: '/' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 418) - t.deepEqual( + t.equal(res.statusCode, 418) + t.same( { error: statusCodes['418'], message: err.message, @@ -219,8 +219,8 @@ test('Error status code below 400 defaults to 500', t => { url: '/' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 500) - t.deepEqual( + t.equal(res.statusCode, 500) + t.same( { error: statusCodes['500'], message: err.message, @@ -246,8 +246,8 @@ test('Error.status property support', t => { url: '/' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 418) - t.deepEqual( + t.equal(res.statusCode, 418) + t.same( { error: statusCodes['418'], message: err.message, @@ -284,9 +284,9 @@ test('Support rejection with values that are not Error instances', t => { fastify.setErrorHandler((err, request, reply) => { if (typeof err === 'object') { - t.deepEqual(err, nonErr) + t.same(err, nonErr) } else { - t.strictEqual(err, nonErr) + t.equal(err, nonErr) } reply.send('error') }) @@ -296,8 +296,8 @@ test('Support rejection with values that are not Error instances', t => { url: '/' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 500) - t.strictEqual(res.payload, 'error') + t.equal(res.statusCode, 500) + t.equal(res.payload, 'error') }) }) } @@ -330,8 +330,8 @@ test('invalid schema - ajv', t => { method: 'GET' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.strictEqual(res.payload, 'error') + t.equal(res.statusCode, 400) + t.equal(res.payload, 'error') }) }) @@ -351,9 +351,9 @@ test('should set the status code and the headers from the error object (from rou method: 'GET' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.strictEqual(res.headers.hello, 'world') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 400) + t.equal(res.headers.hello, 'world') + t.same(JSON.parse(res.payload), { error: 'Bad Request', message: 'kaboom', statusCode: 400 @@ -372,8 +372,8 @@ test('should set the status code and the headers from the error object (from cus }) fastify.setErrorHandler((err, request, reply) => { - t.is(err.message, 'ouch') - t.is(reply.raw.statusCode, 401) + t.equal(err.message, 'ouch') + t.equal(reply.raw.statusCode, 401) const error = new Error('kaboom') error.headers = { hello: 'world' } error.statusCode = 400 @@ -385,9 +385,9 @@ test('should set the status code and the headers from the error object (from cus method: 'GET' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.strictEqual(res.headers.hello, 'world') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 400) + t.equal(res.headers.hello, 'world') + t.same(JSON.parse(res.payload), { error: 'Bad Request', message: 'kaboom', statusCode: 400 @@ -406,8 +406,8 @@ test('\'*\' should throw an error due to serializer can not handle the payload t reply.send({}) } catch (err) { t.type(err, TypeError) - t.is(err.code, 'FST_ERR_REP_INVALID_PAYLOAD_TYPE') - t.is(err.message, "Attempted to send payload of invalid type 'object'. Expected a string or Buffer.") + t.equal(err.code, 'FST_ERR_REP_INVALID_PAYLOAD_TYPE') + t.equal(err.message, "Attempted to send payload of invalid type 'object'. Expected a string or Buffer.") } }) @@ -431,8 +431,8 @@ test('should throw an error if the custom serializer does not serialize the payl .send({}) } catch (err) { t.type(err, TypeError) - t.is(err.code, 'FST_ERR_REP_INVALID_PAYLOAD_TYPE') - t.is(err.message, "Attempted to send payload of invalid type 'object'. Expected a string or Buffer.") + t.equal(err.code, 'FST_ERR_REP_INVALID_PAYLOAD_TYPE') + t.equal(err.message, "Attempted to send payload of invalid type 'object'. Expected a string or Buffer.") } }) @@ -460,8 +460,8 @@ invalidErrorCodes.forEach((invalidCode) => { try { return reply.code(invalidCode).send('You should not read this') } catch (err) { - t.is(err.code, 'FST_ERR_BAD_STATUS_CODE') - t.is(err.message, 'Called reply with an invalid status code: ' + invalidCode) + t.equal(err.code, 'FST_ERR_BAD_STATUS_CODE') + t.equal(err.message, 'Called reply with an invalid status code: ' + invalidCode) } }) fastify.inject({ diff --git a/test/request-error.test.js b/test/request-error.test.js index 7b8645202b..91f02d1b5c 100644 --- a/test/request-error.test.js +++ b/test/request-error.test.js @@ -26,9 +26,9 @@ test('default 400 on request error', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 400) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(res.payload), { error: 'Bad Request', message: 'Simulated', statusCode: 400 @@ -65,9 +65,9 @@ test('default 400 on request error with custom error handler', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 400) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(res.payload), { error: 'Bad Request', message: 'Simulated', statusCode: 400 @@ -133,7 +133,7 @@ test('error handler binding', t => { const fastify = Fastify() fastify.setErrorHandler(function (err, request, reply) { - t.strictEqual(this, fastify) + t.equal(this, fastify) reply .code(err.statusCode) .type('application/json; charset=utf-8') @@ -155,9 +155,9 @@ test('error handler binding', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 400) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(JSON.parse(res.payload), { error: 'Bad Request', message: 'Simulated', statusCode: 400 @@ -172,12 +172,12 @@ test('encapsulated error handler binding', t => { fastify.register(function (app, opts, done) { app.decorate('hello', 'world') - t.strictEqual(app.hello, 'world') + t.equal(app.hello, 'world') app.post('/', function (req, reply) { reply.send({ hello: 'world' }) }) app.setErrorHandler(function (err, request, reply) { - t.strictEqual(this.hello, 'world') + t.equal(this.hello, 'world') reply .code(err.statusCode) .type('application/json; charset=utf-8') @@ -197,13 +197,13 @@ test('encapsulated error handler binding', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(res.json(), { + t.equal(res.statusCode, 400) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(res.json(), { error: 'Bad Request', message: 'Simulated', statusCode: 400 }) - t.strictEqual(fastify.hello, undefined) + t.equal(fastify.hello, undefined) }) }) diff --git a/test/route-hooks.test.js b/test/route-hooks.test.js index e811be9638..64233ab76d 100644 --- a/test/route-hooks.test.js +++ b/test/route-hooks.test.js @@ -35,7 +35,7 @@ function testExecutionHook (hook) { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -170,7 +170,7 @@ function testBeforeHandlerHook (hook) { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'earth' }) + t.same(payload, { hello: 'earth' }) }) fastify.inject({ @@ -180,7 +180,7 @@ function testBeforeHandlerHook (hook) { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -204,7 +204,7 @@ function testBeforeHandlerHook (hook) { t.error(err) const payload = JSON.parse(res.payload) t.equal(res.statusCode, 500) - t.deepEqual(payload, { + t.same(payload, { message: 'kaboom', error: 'Internal Server Error', statusCode: 500 @@ -219,7 +219,7 @@ function testBeforeHandlerHook (hook) { const myError = { myError: 'kaboom' } fastify.setErrorHandler(async (error, request, reply) => { - t.deepEqual(error, myError, 'the error object throws by the user') + t.same(error, myError, 'the error object throws by the user') reply.send({ this: 'is', my: 'error' }) }) @@ -237,8 +237,8 @@ function testBeforeHandlerHook (hook) { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 500) - t.deepEqual(res.json(), { this: 'is', my: 'error' }) + t.equal(res.statusCode, 500) + t.same(res.json(), { this: 'is', my: 'error' }) }) }) @@ -260,8 +260,8 @@ function testBeforeHandlerHook (hook) { method: 'GET' }, (err, res) => { t.error(err) - t.is(res.statusCode, 500) - t.deepEqual(res.json(), { myError: 'kaboom', message: 'i am an error' }) + t.equal(res.statusCode, 500) + t.same(res.json(), { myError: 'kaboom', message: 'i am an error' }) }) }) @@ -286,7 +286,7 @@ function testBeforeHandlerHook (hook) { t.error(err) const payload = JSON.parse(res.payload) t.equal(res.statusCode, 401) - t.deepEqual(payload, { + t.same(payload, { message: 'go away', error: 'Unauthorized', statusCode: 401 @@ -302,7 +302,7 @@ function testBeforeHandlerHook (hook) { fastify.post('/', { [hook]: function (req, reply, done) { - t.strictEqual(this.foo, 42) + t.equal(this.foo, 42) this.foo += 1 done() } @@ -317,7 +317,7 @@ function testBeforeHandlerHook (hook) { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { foo: 43 }) + t.same(payload, { foo: 43 }) }) }) @@ -329,7 +329,7 @@ function testBeforeHandlerHook (hook) { fastify.post('/', { [hook]: [function (req, reply, done) { - t.strictEqual(this.foo, 42) + t.equal(this.foo, 42) this.foo += 1 done() }] @@ -344,7 +344,7 @@ function testBeforeHandlerHook (hook) { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { foo: 43 }) + t.same(payload, { foo: 43 }) }) }) } @@ -366,7 +366,7 @@ test('preValidation option should be called before preHandler hook', t => { const fastify = Fastify() fastify.addHook('preHandler', (req, reply, done) => { - t.true(req.called) + t.ok(req.called) done() }) @@ -386,7 +386,7 @@ test('preValidation option should be called before preHandler hook', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -408,7 +408,7 @@ test('preSerialization option should be able to modify the payload', t => { }, (err, res) => { t.error(err) t.equal(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'another world' }) + t.same(JSON.parse(res.payload), { hello: 'another world' }) }) }) @@ -417,7 +417,7 @@ test('preParsing option should be called before preValidation hook', t => { const fastify = Fastify() fastify.addHook('preValidation', (req, reply, done) => { - t.true(req.called) + t.ok(req.called) done() }) @@ -437,7 +437,7 @@ test('preParsing option should be called before preValidation hook', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) @@ -464,7 +464,7 @@ test('preParsing option should be able to modify the payload', t => { }, (err, res) => { t.error(err) t.equal(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'another world' }) + t.same(JSON.parse(res.payload), { hello: 'another world' }) }) }) @@ -473,7 +473,7 @@ test('onRequest option should be called before preParsing', t => { const fastify = Fastify() fastify.addHook('preParsing', (req, reply, done) => { - t.true(req.called) + t.ok(req.called) done() }) @@ -493,6 +493,6 @@ test('onRequest option should be called before preParsing', t => { }, (err, res) => { t.error(err) const payload = JSON.parse(res.payload) - t.deepEqual(payload, { hello: 'world' }) + t.same(payload, { hello: 'world' }) }) }) diff --git a/test/route-prefix.test.js b/test/route-prefix.test.js index a049332efc..dbce8bc467 100644 --- a/test/route-prefix.test.js +++ b/test/route-prefix.test.js @@ -322,7 +322,7 @@ test('Can retrieve prefix within encapsulated instances', t => { url: '/v1/one' }, (err, res) => { t.error(err) - t.is(res.payload, '/v1') + t.equal(res.payload, '/v1') }) fastify.inject({ @@ -330,7 +330,7 @@ test('Can retrieve prefix within encapsulated instances', t => { url: '/v1/v2/two' }, (err, res) => { t.error(err) - t.is(res.payload, '/v1/v2') + t.equal(res.payload, '/v1/v2') }) }) @@ -588,5 +588,5 @@ test('calls onRoute only once when prefixing', async t => { await fastify.ready() - t.deepEqual(onRouteCalled, 1) + t.same(onRouteCalled, 1) }) diff --git a/test/route.test.js b/test/route.test.js index f07d7b0b9a..85e5cf7869 100644 --- a/test/route.test.js +++ b/test/route.test.js @@ -130,8 +130,8 @@ test('route', t => { url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -142,8 +142,8 @@ test('route', t => { url: 'http://localhost:' + fastify.server.address().port + '/missing' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) }) @@ -154,8 +154,8 @@ test('route', t => { url: 'http://localhost:' + fastify.server.address().port + '/multiple' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -163,8 +163,8 @@ test('route', t => { url: 'http://localhost:' + fastify.server.address().port + '/multiple' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -188,8 +188,8 @@ test('invalid schema - route', t => { t.notOk(err, 'the error is throw on preReady') }) fastify.ready(err => { - t.is(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') - t.isLike(err.message, /Failed building the validation schema for GET: \/invalid/) + t.equal(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') + t.match(err.message, /Failed building the validation schema for GET: \/invalid/) }) }) @@ -206,13 +206,13 @@ test('same route definition object on multiple prefixes', async t => { fastify.register(async function (f) { f.addHook('onRoute', (routeOptions) => { - t.is(routeOptions.url, '/v1/simple') + t.equal(routeOptions.url, '/v1/simple') }) f.route(routeObject) }, { prefix: '/v1' }) fastify.register(async function (f) { f.addHook('onRoute', (routeOptions) => { - t.is(routeOptions.url, '/v2/simple') + t.equal(routeOptions.url, '/v2/simple') }) f.route(routeObject) }, { prefix: '/v2' }) @@ -239,8 +239,8 @@ test('path can be specified in place of uri', t => { fastify.inject(reqOpts, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) }) }) @@ -256,14 +256,14 @@ test('invalid bodyLimit option - route', t => { }) t.fail('bodyLimit must be an integer') } catch (err) { - t.strictEqual(err.message, "'bodyLimit' option must be an integer > 0. Got 'false'") + t.equal(err.message, "'bodyLimit' option must be an integer > 0. Got 'false'") } try { fastify.post('/url', { bodyLimit: 10000.1 }, () => null) t.fail('bodyLimit must be an integer') } catch (err) { - t.strictEqual(err.message, "'bodyLimit' option must be an integer > 0. Got '10000.1'") + t.equal(err.message, "'bodyLimit' option must be an integer > 0. Got '10000.1'") } }) @@ -282,8 +282,8 @@ test('handler function in options of shorthand route should works correctly', t url: '/foo' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) }) }) @@ -314,7 +314,7 @@ test('does not mutate joi schemas', t => { params: { an_id: joi.number() } }, handler (req, res) { - t.deepEqual(req.params, { an_id: 42 }) + t.same(req.params, { an_id: 42 }) res.send({ hello: 'world' }) } }) @@ -324,8 +324,8 @@ test('does not mutate joi schemas', t => { url: '/foo/42' }, (err, result) => { t.error(err) - t.strictEqual(result.statusCode, 200) - t.deepEqual(JSON.parse(result.payload), { hello: 'world' }) + t.equal(result.statusCode, 200) + t.same(JSON.parse(result.payload), { hello: 'world' }) }) }) @@ -360,7 +360,7 @@ test('multiple routes with one schema', t => { fastify.ready(error => { t.error(error) - t.deepEquals(schema, schema) + t.same(schema, schema) }) }) @@ -393,8 +393,8 @@ test('route error handler overrides default error handler', t => { url: '/coffee' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 418) - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 418) + t.same(JSON.parse(res.payload), { message: 'Make a brew', statusCode: 418, error: 'Wrong Pot Error' @@ -439,8 +439,8 @@ test('route error handler does not affect other routes', t => { url: '/tea' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 500) - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 500) + t.same(JSON.parse(res.payload), { message: 'No tea today', statusCode: 500, error: 'Internal Server Error' @@ -477,8 +477,8 @@ test('async error handler for a route', t => { url: '/late-coffee' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 418) - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 418) + t.same(JSON.parse(res.payload), { message: 'Make a brew sometime later', statusCode: 418, error: 'Delayed Pot Error' @@ -521,8 +521,8 @@ test('route error handler overrides global custom error handler', t => { url: '/more-coffee' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 418) - t.deepEqual(JSON.parse(res.payload), { + t.equal(res.statusCode, 418) + t.same(JSON.parse(res.payload), { message: 'Make a brew', statusCode: 418, error: 'Wrong Pot Error' @@ -545,7 +545,7 @@ test('throws when route-level error handler is not a function', t => { errorHandler: 'teapot' }) } catch (err) { - t.is(err.message, 'Error Handler for GET:/tea route, if defined, must be a function') + t.equal(err.message, 'Error Handler for GET:/tea route, if defined, must be a function') } }) @@ -575,9 +575,9 @@ test('Creates a HEAD route for each GET one', t => { url: '/more-coffee' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(res.body, '') }) fastify.inject({ @@ -585,9 +585,9 @@ test('Creates a HEAD route for each GET one', t => { url: '/some-light' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'text/plain; charset=utf-8') - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'text/plain; charset=utf-8') + t.equal(res.body, '') }) }) @@ -654,9 +654,9 @@ test('Will not create a HEAD route that is not GET', t => { url: '/more-coffee' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.deepEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.same(res.body, '') }) fastify.inject({ @@ -664,10 +664,10 @@ test('Will not create a HEAD route that is not GET', t => { url: '/some-light' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], undefined) - t.strictEqual(res.headers['content-length'], '0') - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], undefined) + t.equal(res.headers['content-length'], '0') + t.equal(res.body, '') }) fastify.inject({ @@ -675,7 +675,7 @@ test('Will not create a HEAD route that is not GET', t => { url: '/something' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -734,10 +734,10 @@ test('HEAD route should handle properly each response type', t => { url: '/json' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.strictEqual(res.headers['content-length'], `${Buffer.byteLength(JSON.stringify(resJSON))}`) - t.deepEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.equal(res.headers['content-length'], `${Buffer.byteLength(JSON.stringify(resJSON))}`) + t.same(res.body, '') }) fastify.inject({ @@ -745,10 +745,10 @@ test('HEAD route should handle properly each response type', t => { url: '/string' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'text/plain; charset=utf-8') - t.strictEqual(res.headers['content-length'], `${Buffer.byteLength(resString)}`) - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'text/plain; charset=utf-8') + t.equal(res.headers['content-length'], `${Buffer.byteLength(resString)}`) + t.equal(res.body, '') }) fastify.inject({ @@ -756,10 +756,10 @@ test('HEAD route should handle properly each response type', t => { url: '/buffer' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/octet-stream') - t.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`) - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/octet-stream') + t.equal(res.headers['content-length'], `${resBuffer.byteLength}`) + t.equal(res.body, '') }) fastify.inject({ @@ -767,10 +767,10 @@ test('HEAD route should handle properly each response type', t => { url: '/buffer-with-content-type' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'image/jpeg') - t.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`) - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'image/jpeg') + t.equal(res.headers['content-length'], `${resBuffer.byteLength}`) + t.equal(res.body, '') }) fastify.inject({ @@ -778,10 +778,10 @@ test('HEAD route should handle properly each response type', t => { url: '/stream' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/octet-stream') - t.strictEqual(res.headers['content-length'], undefined) - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/octet-stream') + t.equal(res.headers['content-length'], undefined) + t.equal(res.body, '') }) }) @@ -810,11 +810,11 @@ test('HEAD route should respect custom onSend handlers', t => { url: '/more-coffee' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/octet-stream') - t.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`) - t.strictEqual(res.body, '') - t.strictEqual(counter, 2) + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/octet-stream') + t.equal(res.headers['content-length'], `${resBuffer.byteLength}`) + t.equal(res.body, '') + t.equal(counter, 2) }) }) @@ -868,7 +868,7 @@ test("HEAD route should handle stream.on('error')", t => { logStream.once('data', line => { const { message, stack } = expectedError - t.deepEquals(line.err, { type: 'Error', message, stack }) + t.same(line.err, { type: 'Error', message, stack }) t.equal(line.msg, 'Error on Stream found for HEAD route') t.equal(line.level, 50) }) @@ -878,8 +878,8 @@ test("HEAD route should handle stream.on('error')", t => { url: '/more-coffee' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/octet-stream') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/octet-stream') }) }) @@ -912,7 +912,7 @@ test('HEAD route should not be exposed by default', t => { url: '/without-flag' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) fastify.inject({ @@ -920,10 +920,10 @@ test('HEAD route should not be exposed by default', t => { url: '/with-flag' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8') - t.strictEqual(res.headers['content-length'], `${Buffer.byteLength(JSON.stringify(resJson))}`) - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/json; charset=utf-8') + t.equal(res.headers['content-length'], `${Buffer.byteLength(JSON.stringify(resJson))}`) + t.equal(res.body, '') }) }) @@ -956,10 +956,10 @@ test('HEAD route should be exposed if route exposeHeadRoute is set', t => { url: '/one' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/octet-stream') - t.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`) - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/octet-stream') + t.equal(res.headers['content-length'], `${resBuffer.byteLength}`) + t.equal(res.body, '') }) fastify.inject({ @@ -967,7 +967,7 @@ test('HEAD route should be exposed if route exposeHeadRoute is set', t => { url: '/two' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -1003,11 +1003,11 @@ test('Set a custom HEAD route before GET one without disabling exposeHeadRoutes url: '/one' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/pdf') - t.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`) - t.strictEqual(res.headers['x-custom-header'], 'some-custom-header') - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/pdf') + t.equal(res.headers['content-length'], `${resBuffer.byteLength}`) + t.equal(res.headers['x-custom-header'], 'some-custom-header') + t.equal(res.body, '') }) }) @@ -1015,7 +1015,7 @@ test('Set a custom HEAD route before GET one without disabling exposeHeadRoutes t.plan(7) function onWarning (code) { - t.strictEqual(code, 'FSTDEP007') + t.equal(code, 'FSTDEP007') } const warning = { emit: onWarning @@ -1051,11 +1051,11 @@ test('Set a custom HEAD route before GET one without disabling exposeHeadRoutes url: '/one' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers['content-type'], 'application/pdf') - t.strictEqual(res.headers['content-length'], `${resBuffer.byteLength}`) - t.strictEqual(res.headers['x-custom-header'], 'some-custom-header') - t.strictEqual(res.body, '') + t.equal(res.statusCode, 200) + t.equal(res.headers['content-type'], 'application/pdf') + t.equal(res.headers['content-length'], `${resBuffer.byteLength}`) + t.equal(res.headers['x-custom-header'], 'some-custom-header') + t.equal(res.body, '') }) }) @@ -1080,7 +1080,7 @@ test('HEAD routes properly auto created for GET routes when prefixTrailingSlash: fastify.inject({ url: '/prefix/prefix', method: 'HEAD' }, (err, res) => { t.error(err) - t.strictEquals(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -1107,7 +1107,7 @@ test('HEAD routes properly auto created for GET routes when prefixTrailingSlash: const trailingSlashReply = await fastify.inject({ url: '/prefix/', method: 'HEAD' }) const noneTrailingReply = await fastify.inject({ url: '/prefix', method: 'HEAD' }) - t.equals(doublePrefixReply.statusCode, 404) - t.equals(trailingSlashReply.statusCode, 200) - t.equals(noneTrailingReply.statusCode, 200) + t.equal(doublePrefixReply.statusCode, 404) + t.equal(trailingSlashReply.statusCode, 200) + t.equal(noneTrailingReply.statusCode, 200) }) diff --git a/test/router-options.test.js b/test/router-options.test.js index 054d33912f..0dc5c3aa09 100644 --- a/test/router-options.test.js +++ b/test/router-options.test.js @@ -23,14 +23,14 @@ test('Should honor ignoreTrailingSlash option', t => { sget.concat(baseUrl + '/test', (err, res, data) => { if (err) t.threw(err) - t.is(res.statusCode, 200) - t.is(data.toString(), 'test') + t.equal(res.statusCode, 200) + t.equal(data.toString(), 'test') }) sget.concat(baseUrl + '/test/', (err, res, data) => { if (err) t.threw(err) - t.is(res.statusCode, 200) - t.is(data.toString(), 'test') + t.equal(res.statusCode, 200) + t.equal(data.toString(), 'test') }) }) }) @@ -48,7 +48,7 @@ test('Should honor maxParamLength option', t => { url: '/test/123456789' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -56,7 +56,7 @@ test('Should honor maxParamLength option', t => { url: '/test/123456789abcd' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -65,11 +65,11 @@ test('Should expose router options via getters on request and reply', t => { const fastify = Fastify() fastify.get('/test/:id', (req, reply) => { - t.strictEqual(reply.context.config.url, '/test/:id') - t.strictEqual(reply.context.config.method, 'GET') - t.strictEqual(req.routerPath, '/test/:id') - t.strictEqual(req.routerMethod, 'GET') - t.strictEqual(req.is404, false) + t.equal(reply.context.config.url, '/test/:id') + t.equal(reply.context.config.method, 'GET') + t.equal(req.routerPath, '/test/:id') + t.equal(req.routerMethod, 'GET') + t.equal(req.is404, false) reply.send({ hello: 'world' }) }) @@ -78,7 +78,7 @@ test('Should expose router options via getters on request and reply', t => { url: '/test/123456789' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -87,7 +87,7 @@ test('Should set is404 flag for unmatched paths', t => { const fastify = Fastify() fastify.setNotFoundHandler((req, reply) => { - t.strictEqual(req.is404, true) + t.equal(req.is404, true) reply.code(404).send({ error: 'Not Found', message: 'Four oh for', statusCode: 404 }) }) @@ -96,7 +96,7 @@ test('Should set is404 flag for unmatched paths', t => { url: '/nonexist/123456789' }, (error, res) => { t.error(error) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -124,7 +124,7 @@ test('Should honor frameworkErrors option', t => { }, (err, res) => { t.error(err) - t.equals(res.body, '\'%world\' is not a valid url component - FST_ERR_BAD_URL') + t.equal(res.body, '\'%world\' is not a valid url component - FST_ERR_BAD_URL') } ) }) diff --git a/test/schema-examples.test.js b/test/schema-examples.test.js index 2daf6a866e..d57660f888 100644 --- a/test/schema-examples.test.js +++ b/test/schema-examples.test.js @@ -63,7 +63,7 @@ test('Example - get schema', t => { const mySchemas = fastify.getSchemas() const mySchema = fastify.getSchema('schemaId') - t.deepEquals(mySchemas.schemaId, mySchema) + t.same(mySchemas.schemaId, mySchema) }) test('Example - get schema encapsulated', async t => { @@ -91,9 +91,9 @@ test('Example - get schema encapsulated', async t => { const r2 = await fastify.inject('/sub') const r3 = await fastify.inject('/deep') - t.deepEquals(Object.keys(r1.json()), ['one']) - t.deepEquals(Object.keys(r2.json()), ['one', 'two']) - t.deepEquals(Object.keys(r3.json()), ['one', 'two', 'three']) + t.same(Object.keys(r1.json()), ['one']) + t.same(Object.keys(r2.json()), ['one', 'two']) + t.same(Object.keys(r3.json()), ['one', 'two', 'three']) }) test('Example - validation', t => { @@ -494,12 +494,12 @@ test('should return custom error messages with ajv-errors', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { + t.same(JSON.parse(res.payload), { statusCode: 400, error: 'Bad Request', message: 'body/age bad age - should be num, body name please, body work please' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -544,13 +544,13 @@ test('should return localized error messages with ajv-i18n', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), [{ + t.same(JSON.parse(res.payload), [{ dataPath: '', keyword: 'required', message: 'должно иметь обязательное поле work', params: { missingProperty: 'work' }, schemaPath: '#/required' }]) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) diff --git a/test/schema-feature.test.js b/test/schema-feature.test.js index 7ffc589197..a18f486033 100644 --- a/test/schema-feature.test.js +++ b/test/schema-feature.test.js @@ -12,7 +12,7 @@ const echoBody = (req, reply) => { reply.send(req.body) } test(`Should expose ${f} function`, t => { t.plan(1) const fastify = Fastify() - t.is(typeof fastify[f], 'function') + t.equal(typeof fastify[f], 'function') }) }) @@ -20,7 +20,7 @@ const echoBody = (req, reply) => { reply.send(req.body) } test(`cannot call ${f} after binding`, t => { t.plan(2) const fastify = Fastify() - t.tearDown(fastify.close.bind(fastify)) + t.teardown(fastify.close.bind(fastify)) fastify.listen(0, err => { t.error(err) try { @@ -38,7 +38,7 @@ test('The schemas should be added to an internal storage', t => { const fastify = Fastify() const schema = { $id: 'id', my: 'schema' } fastify.addSchema(schema) - t.deepEqual(fastify[kSchemaController].schemaBucket.store, { id: schema }) + t.same(fastify[kSchemaController].schemaBucket.store, { id: schema }) }) test('The schemas should be accessible via getSchemas', t => { @@ -52,7 +52,7 @@ test('The schemas should be accessible via getSchemas', t => { } Object.values(schemas).forEach(schema => { fastify.addSchema(schema) }) - t.deepEqual(fastify.getSchemas(), schemas) + t.same(fastify.getSchemas(), schemas) }) test('The schema should be accessible by id via getSchema', t => { @@ -65,14 +65,14 @@ test('The schema should be accessible by id via getSchema', t => { { $id: 'bcd', my: 'schema', properties: { a: 'a', b: 1 } } ] schemas.forEach(schema => { fastify.addSchema(schema) }) - t.deepEqual(fastify.getSchema('abc'), schemas[1]) - t.deepEqual(fastify.getSchema('id'), schemas[0]) - t.deepEqual(fastify.getSchema('foo'), undefined) + t.same(fastify.getSchema('abc'), schemas[1]) + t.same(fastify.getSchema('id'), schemas[0]) + t.same(fastify.getSchema('foo'), undefined) fastify.register((instance, opts, done) => { const pluginSchema = { $id: 'cde', my: 'schema' } instance.addSchema(pluginSchema) - t.deepEqual(instance.getSchema('cde'), pluginSchema) + t.same(instance.getSchema('cde'), pluginSchema) done() }) @@ -133,7 +133,7 @@ test('Should throw if the $id property is missing', t => { fastify.addSchema({ type: 'string' }) t.fail() } catch (err) { - t.is(err.code, 'FST_ERR_SCH_MISSING_ID') + t.equal(err.code, 'FST_ERR_SCH_MISSING_ID') } }) @@ -145,8 +145,8 @@ test('Cannot add multiple times the same id', t => { try { fastify.addSchema({ $id: 'id' }) } catch (err) { - t.is(err.code, 'FST_ERR_SCH_ALREADY_PRESENT') - t.is(err.message, 'Schema with id \'id\' already declared!') + t.equal(err.code, 'FST_ERR_SCH_ALREADY_PRESENT') + t.equal(err.message, 'Schema with id \'id\' already declared!') } }) @@ -163,8 +163,8 @@ test('Cannot add schema for query and querystring', t => { }) fastify.ready(err => { - t.is(err.code, 'FST_ERR_SCH_DUPLICATE') - t.is(err.message, 'Schema with \'querystring\' already present!') + t.equal(err.code, 'FST_ERR_SCH_DUPLICATE') + t.equal(err.message, 'Schema with \'querystring\' already present!') }) }) @@ -182,8 +182,8 @@ test('Should throw of the schema does not exists in input', t => { }) fastify.ready(err => { - t.is(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') - t.is(err.message, "Failed building the validation schema for GET: /:id, due to error can't resolve reference #notExist from id #") + t.equal(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') + t.equal(err.message, "Failed building the validation schema for GET: /:id, due to error can't resolve reference #notExist from id #") }) }) @@ -203,8 +203,8 @@ test('Should throw of the schema does not exists in output', t => { }) fastify.ready(err => { - t.is(err.code, 'FST_ERR_SCH_SERIALIZATION_BUILD') - t.is(err.message, "Failed building the serialization schema for GET: /:id, due to error Cannot read property 'type' of undefined") // error from fast-json-strinfigy + t.equal(err.code, 'FST_ERR_SCH_SERIALIZATION_BUILD') + t.equal(err.message, "Failed building the serialization schema for GET: /:id, due to error Cannot read property 'type' of undefined") // error from fast-json-strinfigy }) }) @@ -245,9 +245,9 @@ test('Should not change the input schemas', t => { payload: { name: 'Foo', surname: 'Bar' } }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { name: 'Foo' }) + t.same(res.json(), { name: 'Foo' }) t.ok(theSchema.$id, 'the $id is not removed') - t.deepEqual(fastify.getSchema('helloSchema'), theSchema) + t.same(fastify.getSchema('helloSchema'), theSchema) }) }) @@ -280,7 +280,7 @@ test('First level $ref', t => { url: '/123' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { id: 246 }) + t.same(res.json(), { id: 246 }) }) }) @@ -289,31 +289,31 @@ test('Customize validator compiler in instance and route', t => { const fastify = Fastify() fastify.setValidatorCompiler(({ schema, method, url, httpPart }) => { - t.equals(method, 'POST') // run 4 times - t.equals(url, '/:id') // run 4 times + t.equal(method, 'POST') // run 4 times + t.equal(url, '/:id') // run 4 times switch (httpPart) { case 'body': t.pass('body evaluated') return body => { - t.deepEqual(body, { foo: ['bar', 'BAR'] }) + t.same(body, { foo: ['bar', 'BAR'] }) return true } case 'params': t.pass('params evaluated') return params => { - t.deepEqual(params, { id: 1234 }) + t.same(params, { id: 1234 }) return true } case 'querystring': t.pass('querystring evaluated') return query => { - t.deepEqual(query, { lang: 'en' }) + t.same(query, { lang: 'en' }) return true } case 'headers': t.pass('headers evaluated') return headers => { - t.like(headers, { x: 'hello' }) + t.match(headers, { x: 'hello' }) return true } case '2xx': @@ -340,8 +340,8 @@ test('Customize validator compiler in instance and route', t => { fastify.get('/wow/:id', { handler: echoParams, validatorCompiler: ({ schema, method, url, httpPart }) => { - t.equals(method, 'GET') // run 3 times (params, headers, query) - t.equals(url, '/wow/:id') // run 4 times + t.equal(method, 'GET') // run 3 times (params, headers, query) + t.equal(url, '/wow/:id') // run 4 times return () => { return true } // ignore the validation }, schema: { @@ -361,7 +361,7 @@ test('Customize validator compiler in instance and route', t => { }, (err, res) => { t.error(err) t.equal(res.statusCode, 200) - t.deepEqual(res.json(), { foo: ['bar', 'BAR'] }) + t.same(res.json(), { foo: ['bar', 'BAR'] }) }) fastify.inject({ @@ -372,7 +372,7 @@ test('Customize validator compiler in instance and route', t => { }, (err, res) => { t.error(err) t.equal(res.statusCode, 200) // the validation is always true - t.deepEqual(res.json(), {}) + t.same(res.json(), {}) }) }) @@ -411,7 +411,7 @@ test('Use the same schema across multiple routes', t => { url: '/first/123' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, 'number') + t.equal(res.payload, 'number') }) fastify.inject({ @@ -419,7 +419,7 @@ test('Use the same schema across multiple routes', t => { url: '/second/123' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, 'number') + t.equal(res.payload, 'number') }) }) @@ -449,8 +449,8 @@ test('Encapsulation should intervene', t => { }) fastify.ready(err => { - t.is(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') - t.is(err.message, "Failed building the validation schema for GET: /:id, due to error can't resolve reference encapsulation#/properties/id from id #") + t.equal(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') + t.equal(err.message, "Failed building the validation schema for GET: /:id, due to error can't resolve reference encapsulation#/properties/id from id #") }) }) @@ -495,8 +495,8 @@ test('Add schema after register', t => { try { instance.addSchema({ $id: 'test' }) } catch (err) { - t.is(err.code, 'FST_ERR_SCH_ALREADY_PRESENT') - t.is(err.message, 'Schema with id \'test\' already declared!') + t.equal(err.code, 'FST_ERR_SCH_ALREADY_PRESENT') + t.equal(err.message, 'Schema with id \'test\' already declared!') } done() }) @@ -506,8 +506,8 @@ test('Add schema after register', t => { url: '/4242' }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEqual(res.json(), { id: 4242 }) + t.equal(res.statusCode, 200) + t.same(res.json(), { id: 4242 }) }) }) @@ -547,10 +547,10 @@ test('Encapsulation isolation for getSchemas', t => { fastify.ready(err => { t.error(err) - t.deepEqual(fastify.getSchemas(), { z: schemas.z }) - t.deepEqual(pluginDeepOneSide.getSchemas(), { z: schemas.z, a: schemas.a }) - t.deepEqual(pluginDeepOne.getSchemas(), { z: schemas.z, b: schemas.b }) - t.deepEqual(pluginDeepTwo.getSchemas(), { z: schemas.z, b: schemas.b, c: schemas.c }) + t.same(fastify.getSchemas(), { z: schemas.z }) + t.same(pluginDeepOneSide.getSchemas(), { z: schemas.z, a: schemas.a }) + t.same(pluginDeepOne.getSchemas(), { z: schemas.z, b: schemas.b }) + t.same(pluginDeepTwo.getSchemas(), { z: schemas.z, b: schemas.b, c: schemas.c }) }) }) @@ -723,7 +723,7 @@ test('Shared schema should be ignored in string enum', t => { fastify.inject('/C%23', (err, res) => { t.error(err) - t.deepEqual(res.json(), { lang: 'C#' }) + t.same(res.json(), { lang: 'C#' }) }) }) @@ -755,7 +755,7 @@ test('Shared schema should NOT be ignored in != string enum', t => { payload: { lang: 'C#' } }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { lang: 'C#' }) + t.same(res.json(), { lang: 'C#' }) }) }) @@ -812,7 +812,7 @@ test('Not evaluate json-schema $schema keyword', t => { body: { hello: 'world', foo: 'bar' } }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { hello: 'world' }) + t.same(res.json(), { hello: 'world' }) }) }) @@ -995,7 +995,7 @@ test('Check how many AJV instances are built #1', t => { fastify.validatorCompiler.checkPointer = true instances.forEach(i => { t.ok(i.validatorCompiler, 'validator initialized on preReady') - t.equals(i.validatorCompiler.checkPointer, true, 'validator is only one for all the instances') + t.equal(i.validatorCompiler.checkPointer, true, 'validator is only one for all the instances') }) }) }) @@ -1037,7 +1037,7 @@ test('onReady hook has the compilers ready', t => { fastify.ready(err => { t.error(err) - t.equals(hookCallCounter, 1, 'it is called once') + t.equal(hookCallCounter, 1, 'it is called once') }) }) @@ -1063,7 +1063,7 @@ test('Check how many AJV instances are built #2 - verify validatorPool', t => { addRandomRoute(instance) t.notOk(instance.validatorCompiler, 'validator not initialized') instance.ready(() => { - t.equals(instance.validatorCompiler.sharedPool, 1, 'this context must share the validator with the same schemas') + t.equal(instance.validatorCompiler.sharedPool, 1, 'this context must share the validator with the same schemas') instance.validatorCompiler.sharedPool = 2 }) instance.after(() => { @@ -1073,7 +1073,7 @@ test('Check how many AJV instances are built #2 - verify validatorPool', t => { instance.register((instance, opts, done) => { t.notOk(instance.validatorCompiler, 'validator not initialized') instance.ready(() => { - t.equals(instance.validatorCompiler.sharedPool, 2, 'this context must share the validator of the parent') + t.equal(instance.validatorCompiler.sharedPool, 2, 'this context must share the validator of the parent') }) done() }) @@ -1169,7 +1169,7 @@ test('Schema controller setter', t => { Fastify({ schemaController: { bucket: {} } }) t.fail('the bucket option must be a function') } catch (err) { - t.is(err.message, "schemaController.bucket option should be a function, instead got 'object'") + t.equal(err.message, "schemaController.bucket option should be a function, instead got 'object'") } }) @@ -1183,7 +1183,7 @@ test('Schema controller bucket', t => { function factoryBucket (storeInit) { builtBucket++ - t.deepEqual(initStoreQueue.pop(), storeInit) + t.same(initStoreQueue.pop(), storeInit) const store = new Map(storeInit) return { add (schema) { @@ -1210,13 +1210,13 @@ test('Schema controller bucket', t => { fastify.register(async (instance) => { instance.addSchema({ $id: 'b', type: 'string' }) instance.addHook('onReady', function (done) { - t.equals(instance.getSchemas().size, 2) + t.equal(instance.getSchemas().size, 2) done() }) instance.register(async (subinstance) => { subinstance.addSchema({ $id: 'c', type: 'string' }) subinstance.addHook('onReady', function (done) { - t.equals(subinstance.getSchemas().size, 3) + t.equal(subinstance.getSchemas().size, 3) done() }) }) @@ -1224,7 +1224,7 @@ test('Schema controller bucket', t => { fastify.register(async (instance) => { instance.addHook('onReady', function (done) { - t.equals(instance.getSchemas().size, 1) + t.equal(instance.getSchemas().size, 1) done() }) }) @@ -1233,8 +1233,8 @@ test('Schema controller bucket', t => { fastify.ready(err => { t.error(err) - t.equals(added, 3, 'three schema added') - t.equals(builtBucket, 4, 'one bucket built for every register call + 1 for the root instance') + t.equal(added, 3, 'three schema added') + t.equal(builtBucket, 4, 'one bucket built for every register call + 1 for the root instance') }) }) @@ -1264,7 +1264,7 @@ test('setSchemaController per instance', t => { const map = {} return { add (schema) { - t.equals(schema.$id, bSchema.$id, 'add is called') + t.equal(schema.$id, bSchema.$id, 'add is called') map[schema.$id] = schema }, getSchema (id) { @@ -1282,7 +1282,7 @@ test('setSchemaController per instance', t => { instance2.addHook('onReady', function (done) { instance2.getSchemas() - t.deepEquals(instance2.getSchema('b'), bSchema, 'the schema are loaded') + t.same(instance2.getSchema('b'), bSchema, 'the schema are loaded') done() }) }) diff --git a/test/schema-serialization.test.js b/test/schema-serialization.test.js index c8fa759fba..71ca75f41d 100644 --- a/test/schema-serialization.test.js +++ b/test/schema-serialization.test.js @@ -29,8 +29,8 @@ test('basic test', t => { fastify.inject('/', (err, res) => { t.error(err) - t.deepEqual(res.json(), { name: 'Foo', work: 'Bar' }) - t.strictEqual(res.statusCode, 200) + t.same(res.json(), { name: 'Foo', work: 'Bar' }) + t.equal(res.statusCode, 200) }) }) @@ -65,7 +65,7 @@ test('Use the same schema id in different places', t => { url: '/123' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), [{ id: 1 }, { id: 2 }, { }]) + t.same(res.json(), [{ id: 1 }, { id: 2 }, { }]) }) }) @@ -125,7 +125,7 @@ test('Use shared schema and $ref with $id in response ($ref to $id)', t => { payload }, (err, res) => { t.error(err) - t.deepEqual(res.json(), payload) + t.same(res.json(), payload) }) fastify.inject({ @@ -134,8 +134,8 @@ test('Use shared schema and $ref with $id in response ($ref to $id)', t => { payload: { test: { id: Date.now() } } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.deepEqual(res.json(), { + t.equal(res.statusCode, 400) + t.same(res.json(), { error: 'Bad Request', message: "body should have required property 'address'", statusCode: 400 @@ -233,7 +233,7 @@ test('Shared schema should be pass to serializer and validator ($ref to shared s payload: locations }, (err, res) => { t.error(err) - t.deepEqual(res.json(), locations) + t.same(res.json(), locations) fastify.inject({ method: 'POST', @@ -244,8 +244,8 @@ test('Shared schema should be pass to serializer and validator ($ref to shared s }) }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.deepEqual(res.json(), { + t.equal(res.statusCode, 400) + t.same(res.json(), { error: 'Bad Request', message: 'body[0].location.email should match format "email"', statusCode: 400 @@ -265,10 +265,10 @@ test('Custom setSerializerCompiler', t => { } fastify.setSerializerCompiler(({ schema, method, url, httpStatus }) => { - t.equals(method, 'GET') - t.equals(url, '/foo/:id') - t.equals(httpStatus, '200') - t.deepEqual(schema, outSchema) + t.equal(method, 'GET') + t.equal(url, '/foo/:id') + t.equal(httpStatus, '200') + t.same(schema, outSchema) return data => JSON.stringify(data) }) @@ -292,7 +292,7 @@ test('Custom setSerializerCompiler', t => { url: '/foo/123' }, (err, res) => { t.error(err) - t.equals(res.payload, JSON.stringify({ id: 1 })) + t.equal(res.payload, JSON.stringify({ id: 1 })) }) }) @@ -335,15 +335,15 @@ test('Custom serializer per route', async t => { }) let res = await fastify.inject('/default') - t.equals(res.json().mean, 'default') + t.equal(res.json().mean, 'default') res = await fastify.inject('/custom') - t.equals(res.json().mean, 'custom') + t.equal(res.json().mean, 'custom') res = await fastify.inject('/route') - t.equals(res.json().mean, 'route') + t.equal(res.json().mean, 'route') - t.equals(hit, 2, 'the custom and route serializer has been called') + t.equal(hit, 2, 'the custom and route serializer has been called') }) test('Reply serializer win over serializer ', t => { @@ -351,7 +351,7 @@ test('Reply serializer win over serializer ', t => { const fastify = Fastify() fastify.setReplySerializer(function (payload, statusCode) { - t.deepEqual(payload, { name: 'Foo', work: 'Bar', nick: 'Boo' }) + t.same(payload, { name: 'Foo', work: 'Bar', nick: 'Boo' }) return 'instance serializator' }) @@ -380,8 +380,8 @@ test('Reply serializer win over serializer ', t => { fastify.inject('/', (err, res) => { t.error(err) - t.deepEqual(res.payload, 'instance serializator') - t.strictEqual(res.statusCode, 200) + t.same(res.payload, 'instance serializator') + t.equal(res.statusCode, 200) }) }) @@ -390,7 +390,7 @@ test('Reply serializer win over serializer ', t => { const fastify = Fastify() fastify.setReplySerializer(function (payload, statusCode) { - t.deepEqual(payload, { name: 'Foo', work: 'Bar', nick: 'Boo' }) + t.same(payload, { name: 'Foo', work: 'Bar', nick: 'Boo' }) return 'instance serializator' }) @@ -419,8 +419,8 @@ test('Reply serializer win over serializer ', t => { fastify.inject('/', (err, res) => { t.error(err) - t.deepEqual(res.payload, 'instance serializator') - t.strictEqual(res.statusCode, 200) + t.same(res.payload, 'instance serializator') + t.equal(res.statusCode, 200) }) }) @@ -491,12 +491,12 @@ test('The schema changes the default error handler output', async t => { }) let res = await fastify.inject('/501') - t.equals(res.statusCode, 501) - t.deepEquals(res.json(), { message: '501 message' }) + t.equal(res.statusCode, 501) + t.same(res.json(), { message: '501 message' }) res = await fastify.inject('/500') - t.equals(res.statusCode, 500) - t.deepEquals(res.json(), { error: 'Internal Server Error', message: '500 message', customId: 42 }) + t.equal(res.statusCode, 500) + t.same(res.json(), { error: 'Internal Server Error', message: '500 message', customId: 42 }) }) test('do not crash if status code serializer errors', async t => { @@ -533,8 +533,8 @@ test('do not crash if status code serializer errors', async t => { notfoo: true } }) - t.equals(res.statusCode, 500) - t.deepEquals(res.json(), { + t.equal(res.statusCode, 500) + t.same(res.json(), { statusCode: 500, error: 'Internal Server Error', message: '"code" is required!' diff --git a/test/schema-special-usage.test.js b/test/schema-special-usage.test.js index af0b4e11a6..f09d573b82 100644 --- a/test/schema-special-usage.test.js +++ b/test/schema-special-usage.test.js @@ -43,7 +43,7 @@ test('Should handle root $merge keywords in header', t => { url: '/' }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -52,7 +52,7 @@ test('Should handle root $merge keywords in header', t => { headers: { q: 'foo' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) }) @@ -103,7 +103,7 @@ test('Should handle root $patch keywords in header', t => { } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -112,7 +112,7 @@ test('Should handle root $patch keywords in header', t => { headers: { q: 10 } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) }) @@ -154,7 +154,7 @@ test('Should handle $merge keywords in body', t => { url: '/' }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -163,7 +163,7 @@ test('Should handle $merge keywords in body', t => { payload: { q: 'foo' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) }) @@ -210,7 +210,7 @@ test('Should handle $patch keywords in body', t => { payload: { q: 'foo' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -219,7 +219,7 @@ test('Should handle $patch keywords in body', t => { payload: { q: 10 } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) }) @@ -281,8 +281,8 @@ test("serializer read validator's schemas", t => { fastify.inject('/', (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(res.json(), { hello: 'world' }) }) }) @@ -327,8 +327,8 @@ test('setSchemaController in a plugin', t => { fastify.inject('/', (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(res.json(), { hello: 'world' }) }) async function schemaPlugin (server) { @@ -497,8 +497,8 @@ test('setSchemaController in a plugin with head routes', t => { fastify.inject('/', (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(res.json(), { hello: 'world' }) }) async function schemaPlugin (server) { @@ -588,7 +588,7 @@ test('multiple refs with the same ids', t => { fastify.inject('/', (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.same(res.json(), { hello: 'world' }) }) }) diff --git a/test/schema-validation.test.js b/test/schema-validation.test.js index df4a01aca9..faf98547f0 100644 --- a/test/schema-validation.test.js +++ b/test/schema-validation.test.js @@ -63,8 +63,8 @@ test('Basic validation test', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.payload, 'michelangelo') - t.strictEqual(res.statusCode, 200) + t.same(res.payload, 'michelangelo') + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -73,8 +73,8 @@ test('Basic validation test', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { statusCode: 400, error: 'Bad Request', message: "body should have required property 'work'" }) - t.strictEqual(res.statusCode, 400) + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: "body should have required property 'work'" }) + t.equal(res.statusCode, 400) }) }) @@ -110,7 +110,7 @@ test('External AJV instance', t => { payload: { foo: 42 } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -119,7 +119,7 @@ test('External AJV instance', t => { payload: { foo: 'not a number' } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -150,7 +150,7 @@ test('Encapsulation', t => { instance.register((instance, opts, done) => { instance.post('/two', { handler (req, reply) { - t.deepEquals(instance.validatorCompiler, validator) + t.same(instance.validatorCompiler, validator) reply.send({ foo: 'two' }) }, schema: { @@ -164,7 +164,7 @@ test('Encapsulation', t => { instance.post('/three', { validatorCompiler: anotherValidator, handler (req, reply) { - t.deepEquals(instance.validatorCompiler, validator, 'the route validator does not change the instance one') + t.same(instance.validatorCompiler, validator, 'the route validator does not change the instance one') reply.send({ foo: 'three' }) }, schema: { @@ -178,7 +178,7 @@ test('Encapsulation', t => { fastify.register((instance, opts, done) => { instance.post('/clean', function (req, reply) { - t.equals(instance.validatorCompiler, undefined) + t.equal(instance.validatorCompiler, undefined) reply.send({ foo: 'bar' }) }) done() @@ -190,8 +190,8 @@ test('Encapsulation', t => { payload: { foo: 1 } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { foo: 'one' }) + t.equal(res.statusCode, 200) + t.same(res.json(), { foo: 'one' }) }) fastify.inject({ @@ -200,7 +200,7 @@ test('Encapsulation', t => { payload: { wrongFoo: 'bar' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -209,8 +209,8 @@ test('Encapsulation', t => { payload: { foo: 2 } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { foo: 'two' }) + t.equal(res.statusCode, 200) + t.same(res.json(), { foo: 'two' }) }) fastify.inject({ @@ -219,7 +219,7 @@ test('Encapsulation', t => { payload: { wrongFoo: 'bar' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -228,8 +228,8 @@ test('Encapsulation', t => { payload: { wrongFoo: 'but works' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { foo: 'three' }) + t.equal(res.statusCode, 200) + t.same(res.json(), { foo: 'three' }) }) fastify.inject({ @@ -238,8 +238,8 @@ test('Encapsulation', t => { payload: { wrongFoo: 'bar' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { foo: 'bar' }) + t.equal(res.statusCode, 200) + t.same(res.json(), { foo: 'bar' }) }) }) @@ -277,8 +277,8 @@ test('Triple $ref with a simple $id', t => { payload: { foo: 43 } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEquals(res.json(), { foo: 105 }) + t.equal(res.statusCode, 200) + t.same(res.json(), { foo: 105 }) }) fastify.inject({ @@ -287,8 +287,8 @@ test('Triple $ref with a simple $id', t => { payload: { fool: 'bar' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) - t.deepEquals(res.json().message, "body should have required property 'foo'") + t.equal(res.statusCode, 400) + t.same(res.json().message, "body should have required property 'foo'") }) }) @@ -343,7 +343,7 @@ test('Extending schema', t => { } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -358,7 +358,7 @@ test('Extending schema', t => { } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) + t.equal(res.statusCode, 200) }) }) @@ -400,8 +400,8 @@ test('Should work with nested ids', t => { } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.equals(res.payload, 'number') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'number') }) fastify.inject({ @@ -412,8 +412,8 @@ test('Should work with nested ids', t => { } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) - t.strictEqual(res.json().message, 'params.id should be number') + t.equal(res.statusCode, 400) + t.equal(res.json().message, 'params.id should be number') }) }) @@ -452,7 +452,7 @@ test('Use the same schema across multiple routes', t => { method: 'GET' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, 'number') + t.equal(res.payload, 'number') }) }) @@ -465,7 +465,7 @@ test('Use the same schema across multiple routes', t => { method: 'GET' }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) }) @@ -497,8 +497,8 @@ test('JSON Schema validation keywords', t => { url: '/127.0.0.1' }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.strictEqual(res.payload, 'string') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'string') }) fastify.inject({ @@ -506,8 +506,8 @@ test('JSON Schema validation keywords', t => { url: '/localhost' }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) - t.deepEqual(res.json(), { + t.equal(res.statusCode, 400) + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'params.ip should match format "ipv4"' @@ -551,8 +551,8 @@ test('Nested id calls', t => { payload: { host: { ip: '127.0.0.1' } } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.payload, 'string') + t.equal(res.statusCode, 200) + t.equal(res.payload, 'string') }) fastify.inject({ @@ -561,8 +561,8 @@ test('Nested id calls', t => { payload: { host: { ip: 'localhost' } } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.deepEqual(res.json(), { + t.equal(res.statusCode, 400) + t.same(res.json(), { error: 'Bad Request', message: 'body.host.ip should match format "ipv4"', statusCode: 400 @@ -598,7 +598,7 @@ test('Use the same schema id in different places', t => { payload: { id: 42 } }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { id: 21 }) + t.same(res.json(), { id: 21 }) }) }) @@ -654,7 +654,7 @@ test('Use shared schema and $ref with $id ($ref to $id)', t => { } }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { id }) + t.same(res.json(), { id }) }) fastify.inject({ @@ -663,8 +663,8 @@ test('Use shared schema and $ref with $id ($ref to $id)', t => { payload: { test: { id } } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 400) - t.deepEqual(res.json(), { + t.equal(res.statusCode, 400) + t.same(res.json(), { error: 'Bad Request', message: "body should have required property 'address'", statusCode: 400 @@ -701,7 +701,7 @@ test('Use items with $ref', t => { payload: [{ hello: 'world' }] }, (err, res) => { t.error(err) - t.equals(res.payload, 'ok') + t.equal(res.payload, 'ok') }) fastify.inject({ @@ -710,7 +710,7 @@ test('Use items with $ref', t => { payload: { hello: 'world' } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -767,8 +767,8 @@ test('Use $ref to /definitions', t => { payload }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEqual(res.json(), payload) + t.equal(res.statusCode, 200) + t.same(res.json(), payload) }) fastify.inject({ @@ -780,8 +780,8 @@ test('Use $ref to /definitions', t => { } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) - t.deepEqual(res.json(), { + t.equal(res.statusCode, 400) + t.same(res.json(), { error: 'Bad Request', message: 'body.test.id should be number', statusCode: 400 @@ -798,7 +798,7 @@ test('Custom AJV settings - pt1', t => { body: { num: { type: 'integer' } } }, handler: (req, reply) => { - t.equals(req.body.num, 12) + t.equal(req.body.num, 12) reply.send(req.body) } }) @@ -811,8 +811,8 @@ test('Custom AJV settings - pt1', t => { } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 200) - t.deepEqual(res.json(), { num: 12 }) + t.equal(res.statusCode, 200) + t.same(res.json(), { num: 12 }) }) }) @@ -843,6 +843,6 @@ test('Custom AJV settings - pt2', t => { } }, (err, res) => { t.error(err) - t.equals(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) diff --git a/test/skip-reply-send.test.js b/test/skip-reply-send.test.js index 7726dd69f9..1c3f9903ad 100644 --- a/test/skip-reply-send.test.js +++ b/test/skip-reply-send.test.js @@ -28,8 +28,8 @@ test('skip automatic reply.send() with reply.sent = true and a body', (t) => { }) stream.on('data', (line) => { - t.notEqual(line.level, 40) // there are no errors - t.notEqual(line.level, 50) // there are no errors + t.not(line.level, 40) // there are no errors + t.not(line.level, 50) // there are no errors }) app.get('/', (req, reply) => { @@ -57,8 +57,8 @@ test('skip automatic reply.send() with reply.sent = true and no body', (t) => { }) stream.on('data', (line) => { - t.notEqual(line.level, 40) // there are no error - t.notEqual(line.level, 50) // there are no error + t.not(line.level, 40) // there are no error + t.not(line.level, 50) // there are no error }) app.get('/', (req, reply) => { @@ -130,8 +130,8 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) { }) stream.on('data', (line) => { - t.notEqual(line.level, 40) // there are no errors - t.notEqual(line.level, 50) // there are no errors + t.not(line.level, 40) // there are no errors + t.not(line.level, 50) // there are no errors }) previousHooks.forEach(h => app.addHook(h, async (req, reply) => t.pass(`${h} should be called`))) @@ -173,11 +173,11 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) { stream: stream } }) - t.tearDown(() => app.close()) + t.teardown(() => app.close()) stream.on('data', (line) => { - t.notEqual(line.level, 40) // there are no errors - t.notEqual(line.level, 50) // there are no errors + t.not(line.level, 40) // there are no errors + t.not(line.level, 50) // there are no errors }) previousHooks.forEach(h => app.addHook(h, async (req, reply) => t.pass(`${h} should be called`))) @@ -220,7 +220,7 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) { stream: stream } }) - t.tearDown(() => app.close()) + t.teardown(() => app.close()) let errorSeen = false stream.on('data', (line) => { @@ -230,8 +230,8 @@ function testHandlerOrBeforeHandlerHook (test, hookOrHandler) { t.equal(line.err.code, 'FST_ERR_REP_ALREADY_SENT') } } else { - t.notEqual(line.level, 40) // there are no errors - t.notEqual(line.level, 50) // there are no errors + t.not(line.level, 40) // there are no errors + t.not(line.level, 50) // there are no errors } }) diff --git a/test/stream.test.js b/test/stream.test.js index dc1b06a543..743f8f6a5c 100644 --- a/test/stream.test.js +++ b/test/stream.test.js @@ -34,8 +34,8 @@ test('should respond with a stream', t => { sget(`http://localhost:${fastify.server.address().port}`, function (err, response, data) { t.error(err) - t.strictEqual(response.headers['content-type'], 'application/octet-stream') - t.strictEqual(response.statusCode, 200) + t.equal(response.headers['content-type'], 'application/octet-stream') + t.equal(response.statusCode, 200) fs.readFile(__filename, (err, expected) => { t.error(err) @@ -45,7 +45,7 @@ test('should respond with a stream', t => { sget(`http://localhost:${fastify.server.address().port}/error`, function (err, response) { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) }) }) @@ -68,8 +68,8 @@ test('should trigger the onSend hook', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.headers['content-type'], 'application/javascript') - t.strictEqual(res.payload, fs.readFileSync(__filename, 'utf8')) + t.equal(res.headers['content-type'], 'application/javascript') + t.equal(res.payload, fs.readFileSync(__filename, 'utf8')) fastify.close() }) }) @@ -88,7 +88,7 @@ test('should trigger the onSend hook only twice if pumping the stream fails, fir t.ok(payload._readableState) } else if (counter === 1) { const error = JSON.parse(payload) - t.strictEqual(error.statusCode, 500) + t.equal(error.statusCode, 500) } counter++ done() @@ -101,7 +101,7 @@ test('should trigger the onSend hook only twice if pumping the stream fails, fir sget(`http://localhost:${fastify.server.address().port}`, function (err, response) { t.error(err) - t.strictEqual(response.statusCode, 500) + t.equal(response.statusCode, 500) }) }) }) @@ -131,10 +131,10 @@ test('onSend hook stream', t => { method: 'GET' }, (err, res) => { t.error(err) - t.strictEqual(res.headers['content-encoding'], 'gzip') + t.equal(res.headers['content-encoding'], 'gzip') const file = fs.readFileSync(resolve(process.cwd() + '/test/stream.test.js'), 'utf8') const payload = zlib.gunzipSync(res.rawPayload) - t.strictEqual(payload.toString('utf-8'), file) + t.equal(payload.toString('utf-8'), file) fastify.close() }) }) @@ -188,7 +188,7 @@ test('Destroying streams prematurely', t => { const port = fastify.server.address().port http.get(`http://localhost:${port}`, function (response) { - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) response.on('readable', function () { response.destroy() }) @@ -251,7 +251,7 @@ test('Destroying streams prematurely should call close method', t => { const port = fastify.server.address().port http.get(`http://localhost:${port}`, function (response) { - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) response.on('readable', function () { response.destroy() }) @@ -313,7 +313,7 @@ test('Destroying streams prematurely should call close method when destroy is no const port = fastify.server.address().port http.get(`http://localhost:${port}`, function (response) { - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) response.on('readable', function () { response.destroy() }) @@ -376,7 +376,7 @@ test('Destroying streams prematurely should call abort method', t => { const port = fastify.server.address().port http.get(`http://localhost:${port}`, function (response) { - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) response.on('readable', function () { response.destroy() }) @@ -405,9 +405,9 @@ test('should respond with a stream1', t => { sget(`http://localhost:${fastify.server.address().port}`, function (err, response, body) { t.error(err) - t.strictEqual(response.headers['content-type'], 'application/json') - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), [{ hello: 'world' }, { a: 42 }]) + t.equal(response.headers['content-type'], 'application/json') + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), [{ hello: 'world' }, { a: 42 }]) }) }) }) @@ -439,8 +439,8 @@ test('return a 404 if the stream emits a 404 error', t => { sget(`http://localhost:${port}`, function (err, response) { t.error(err) - t.strictEqual(response.headers['content-type'], 'application/json; charset=utf-8') - t.strictEqual(response.statusCode, 404) + t.equal(response.headers['content-type'], 'application/json; charset=utf-8') + t.equal(response.statusCode, 404) }) }) }) @@ -465,8 +465,8 @@ test('should support send module 200 and 404', t => { sget(`http://localhost:${fastify.server.address().port}`, function (err, response, data) { t.error(err) - t.strictEqual(response.headers['content-type'], 'application/octet-stream') - t.strictEqual(response.statusCode, 200) + t.equal(response.headers['content-type'], 'application/octet-stream') + t.equal(response.statusCode, 200) fs.readFile(__filename, (err, expected) => { t.error(err) @@ -476,7 +476,7 @@ test('should support send module 200 and 404', t => { sget(`http://localhost:${fastify.server.address().port}/error`, function (err, response) { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) }) @@ -504,7 +504,7 @@ test('should destroy stream when response is ended', t => { sget(`http://localhost:${fastify.server.address().port}/error`, function (err, response) { t.error(err) - t.strictEqual(response.statusCode, 200) + t.equal(response.statusCode, 200) }) }) }) diff --git a/test/sync-routes.test.js b/test/sync-routes.test.js index d244d427ef..9491a2cfd7 100644 --- a/test/sync-routes.test.js +++ b/test/sync-routes.test.js @@ -5,28 +5,28 @@ const Fastify = require('..') test('sync route', async t => { const app = Fastify() - t.tearDown(app.close.bind(app)) + t.teardown(app.close.bind(app)) app.get('/', () => 'hello world') const res = await app.inject('/') - t.is(res.statusCode, 200) - t.is(res.body, 'hello world') + t.equal(res.statusCode, 200) + t.equal(res.body, 'hello world') }) test('sync route return null', async t => { const app = Fastify() - t.tearDown(app.close.bind(app)) + t.teardown(app.close.bind(app)) app.get('/', () => null) const res = await app.inject('/') - t.is(res.statusCode, 200) - t.is(res.body, 'null') + t.equal(res.statusCode, 200) + t.equal(res.body, 'null') }) test('sync route, error', async t => { const app = Fastify() - t.tearDown(app.close.bind(app)) + t.teardown(app.close.bind(app)) app.get('/', () => { throw new Error('kaboom') }) const res = await app.inject('/') - t.is(res.statusCode, 500) + t.equal(res.statusCode, 500) }) diff --git a/test/throw.test.js b/test/throw.test.js index ad24026725..40e32d6af1 100644 --- a/test/throw.test.js +++ b/test/throw.test.js @@ -9,7 +9,7 @@ test('Fastify should throw on wrong options', t => { Fastify('lol') t.fail() } catch (e) { - t.is(e.message, 'Options must be an object') + t.equal(e.message, 'Options must be an object') t.pass() } }) @@ -21,7 +21,7 @@ test('Fastify should throw on multiple assignment to the same route', t => { fastify.get('/', () => {}) fastify.ready(err => { - t.is(err.message, "Method 'GET' already declared for route '/' with constraints '{}'") + t.equal(err.message, "Method 'GET' already declared for route '/' with constraints '{}'") }) }) @@ -42,8 +42,8 @@ test('Fastify should throw for an invalid schema, printing the error route - hea fastify.get('/not-loaded', { schema: { headers: badSchema } }, () => {}) fastify.ready(err => { - t.is(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') - t.isLike(err.message, /Failed building the validation schema for GET: \//) + t.equal(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') + t.match(err.message, /Failed building the validation schema for GET: \//) }) }) @@ -66,8 +66,8 @@ test('Fastify should throw for an invalid schema, printing the error route - bod }, { prefix: 'hello' }) fastify.ready(err => { - t.is(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') - t.isLike(err.message, /Failed building the validation schema for POST: \/hello\/form/) + t.equal(err.code, 'FST_ERR_SCH_VALIDATION_BUILD') + t.match(err.message, /Failed building the validation schema for POST: \/hello\/form/) }) }) @@ -156,7 +156,7 @@ test('Should not throw on duplicate decorator encapsulation', t => { fastify.decorate('foo2', foo2Obj) fastify.register(function (fastify, opts, done) { - t.notThrow(() => { + t.doesNotThrow(() => { fastify.decorate('foo2', foo2Obj) }) done() @@ -175,8 +175,8 @@ test('Should throw on duplicate request decorator', t => { fastify.decorateRequest('foo', null) t.fail() } catch (e) { - t.is(e.code, 'FST_ERR_DEC_ALREADY_PRESENT') - t.is(e.message, 'The decorator \'foo\' has already been added!') + t.equal(e.code, 'FST_ERR_DEC_ALREADY_PRESENT') + t.equal(e.message, 'The decorator \'foo\' has already been added!') } }) @@ -189,8 +189,8 @@ test('Should throw if request decorator dependencies are not met', t => { fastify.decorateRequest('bar', null, ['world']) t.fail() } catch (e) { - t.is(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') - t.is(e.message, 'The decorator is missing dependency \'world\'.') + t.equal(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY') + t.equal(e.message, 'The decorator is missing dependency \'world\'.') } }) diff --git a/test/trust-proxy.test.js b/test/trust-proxy.test.js index f18527115a..eecc437310 100644 --- a/test/trust-proxy.test.js +++ b/test/trust-proxy.test.js @@ -30,7 +30,7 @@ const testRequestValues = (t, req, options) => { t.equal(req.hostname, options.hostname, 'gets hostname from x-forwarded-host') } if (options.ips) { - t.deepEqual(req.ips, options.ips, 'gets ips from x-forwarded-for') + t.same(req.ips, options.ips, 'gets ips from x-forwarded-for') } if (options.protocol) { t.ok(req.protocol, 'protocol is defined') @@ -53,7 +53,7 @@ test('trust proxy, not add properties to node req', (t) => { reply.code(200).send({ ip: req.ip, hostname: req.hostname }) }) - t.tearDown(app.close.bind(app)) + t.teardown(app.close.bind(app)) app.listen(0, (err) => { app.server.unref() @@ -74,7 +74,7 @@ test('trust proxy chain', (t) => { reply.code(200).send({ ip: req.ip, hostname: req.hostname }) }) - t.tearDown(app.close.bind(app)) + t.teardown(app.close.bind(app)) app.listen(0, (err) => { app.server.unref() @@ -93,7 +93,7 @@ test('trust proxy function', (t) => { reply.code(200).send({ ip: req.ip, hostname: req.hostname }) }) - t.tearDown(app.close.bind(app)) + t.teardown(app.close.bind(app)) app.listen(0, (err) => { app.server.unref() @@ -112,7 +112,7 @@ test('trust proxy number', (t) => { reply.code(200).send({ ip: req.ip, hostname: req.hostname }) }) - t.tearDown(app.close.bind(app)) + t.teardown(app.close.bind(app)) app.listen(0, (err) => { app.server.unref() @@ -131,7 +131,7 @@ test('trust proxy IP addresses', (t) => { reply.code(200).send({ ip: req.ip, hostname: req.hostname }) }) - t.tearDown(app.close.bind(app)) + t.teardown(app.close.bind(app)) app.listen(0, (err) => { app.server.unref() @@ -158,7 +158,7 @@ test('trust proxy protocol', (t) => { reply.code(200).send({ ip: req.ip, hostname: req.hostname }) }) - t.tearDown(app.close.bind(app)) + t.teardown(app.close.bind(app)) app.listen(0, (err) => { app.server.unref() diff --git a/test/url-rewriting.test.js b/test/url-rewriting.test.js index 8521c7d4ed..39ced33cc3 100644 --- a/test/url-rewriting.test.js +++ b/test/url-rewriting.test.js @@ -30,12 +30,12 @@ test('Should rewrite url', t => { url: 'http://localhost:' + fastify.server.address().port + '/this-would-404-without-url-rewrite' }, (err, response, body) => { t.error(err) - t.deepEqual(JSON.parse(body), { hello: 'world' }) - t.strictEqual(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) }) }) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) }) test('Should not rewrite if the url is the same', t => { @@ -63,11 +63,11 @@ test('Should not rewrite if the url is the same', t => { url: 'http://localhost:' + fastify.server.address().port + '/this-would-404-without-url-rewrite' }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) }) test('Should throw an error', t => { t.plan(5) @@ -94,10 +94,10 @@ test('Should throw an error', t => { url: 'http://localhost:' + fastify.server.address().port + '/this-would-404-without-url-rewrite' }, (err, response, body) => { t.equal(err.code, 'ECONNRESET') - t.strictEqual(response, undefined) - t.strictEqual(body, undefined) + t.equal(response, undefined) + t.equal(body, undefined) }) }) - t.tearDown(() => fastify.close()) + t.teardown(() => fastify.close()) }) diff --git a/test/validation-error-handling.test.js b/test/validation-error-handling.test.js index 023a37bbca..be09789a5d 100644 --- a/test/validation-error-handling.test.js +++ b/test/validation-error-handling.test.js @@ -35,8 +35,8 @@ test('should work with valid payload', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.payload, 'michelangelo') - t.strictEqual(res.statusCode, 200) + t.same(res.payload, 'michelangelo') + t.equal(res.statusCode, 200) }) }) @@ -55,12 +55,12 @@ test('should fail immediately with invalid payload', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: "body should have required property 'name'" }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -88,12 +88,12 @@ test('should be able to use setErrorHandler specify custom validation error', t url: '/' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { + t.same(JSON.parse(res.payload), { statusCode: 422, error: 'Unprocessable Entity', message: 'validation failed' }) - t.strictEqual(res.statusCode, 422) + t.equal(res.statusCode, 422) }) }) @@ -115,7 +115,7 @@ test('error inside custom error handler should have validationContext', t => { }) fastify.setErrorHandler(function (error, request, reply) { - t.strictEqual(error.validationContext, 'body') + t.equal(error.validationContext, 'body') reply.status(500).send(error) }) @@ -149,7 +149,7 @@ test('error inside custom error handler should have validationContext if specifi }) fastify.setErrorHandler(function (error, request, reply) { - t.strictEqual(error.validationContext, 'customContext') + t.equal(error.validationContext, 'customContext') reply.status(500).send(error) }) @@ -181,14 +181,14 @@ test('should be able to attach validation to request', t => { }, (err, res) => { t.error(err) - t.deepEqual(res.json(), [{ + t.same(res.json(), [{ keyword: 'required', dataPath: '', schemaPath: '#/required', params: { missingProperty: 'name' }, message: 'should have required property \'name\'' }]) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -210,12 +210,12 @@ test('should respect when attachValidation is explicitly set to false', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { + t.same(JSON.parse(res.payload), { statusCode: 400, error: 'Bad Request', message: "body should have required property 'name'" }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -243,8 +243,8 @@ test('Attached validation error should take precedence over setErrorHandler', t url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.payload, "Attached: Error: body should have required property 'name'") - t.strictEqual(res.statusCode, 400) + t.same(res.payload, "Attached: Error: body should have required property 'name'") + t.equal(res.statusCode, 400) }) }) @@ -278,7 +278,7 @@ test('should handle response validation error', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"statusCode":500,"error":"Internal Server Error","message":"\\"name\\" is required!"}') + t.equal(res.payload, '{"statusCode":500,"error":"Internal Server Error","message":"\\"name\\" is required!"}') }) }) @@ -308,7 +308,7 @@ test('should handle response validation error with promises', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"statusCode":500,"error":"Internal Server Error","message":"\\"name\\" is required!"}') + t.equal(res.payload, '{"statusCode":500,"error":"Internal Server Error","message":"\\"name\\" is required!"}') }) }) @@ -336,7 +336,7 @@ test('should return a defined output message parsing AJV errors', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"statusCode":400,"error":"Bad Request","message":"body should have required property \'name\'"}') + t.equal(res.payload, '{"statusCode":400,"error":"Bad Request","message":"body should have required property \'name\'"}') }) }) @@ -366,7 +366,7 @@ test('should return a defined output message parsing JOI errors', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"statusCode":400,"error":"Bad Request","message":"\\"name\\" is required"}') + t.equal(res.payload, '{"statusCode":400,"error":"Bad Request","message":"\\"name\\" is required"}') }) }) @@ -399,7 +399,7 @@ test('should return a defined output message parsing JOI error details', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.payload, '{"statusCode":400,"error":"Bad Request","message":"body \\"name\\" is required"}') + t.equal(res.payload, '{"statusCode":400,"error":"Bad Request","message":"body \\"name\\" is required"}') }) }) @@ -409,7 +409,7 @@ test('the custom error formatter context must be the server instance', t => { const fastify = Fastify() fastify.setSchemaErrorFormatter(function (errors, dataVar) { - t.deepEquals(this, fastify) + t.same(this, fastify) return new Error('my error') }) @@ -423,12 +423,12 @@ test('the custom error formatter context must be the server instance', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'my error' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -437,7 +437,7 @@ test('the custom error formatter context must be the server instance in options' const fastify = Fastify({ schemaErrorFormatter: function (errors, dataVar) { - t.deepEquals(this, fastify) + t.same(this, fastify) return new Error('my error') } }) @@ -452,12 +452,12 @@ test('the custom error formatter context must be the server instance in options' url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'my error' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -483,12 +483,12 @@ test('should call custom error formatter', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'my error' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -511,12 +511,12 @@ test('should catch error inside formatter and return message', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 500, error: 'Internal Server Error', message: 'abc' }) - t.strictEqual(res.statusCode, 500) + t.equal(res.statusCode, 500) t.end() }) }) @@ -531,7 +531,7 @@ test('cannot create a fastify instance with wrong type of errorFormatter', t => } }) } catch (err) { - t.equals(err.message, 'schemaErrorFormatter option should not be an async function') + t.equal(err.message, 'schemaErrorFormatter option should not be an async function') } try { @@ -539,14 +539,14 @@ test('cannot create a fastify instance with wrong type of errorFormatter', t => schemaErrorFormatter: 500 }) } catch (err) { - t.equals(err.message, 'schemaErrorFormatter option should be a function, instead got number') + t.equal(err.message, 'schemaErrorFormatter option should be a function, instead got number') } try { const fastify = Fastify() fastify.setSchemaErrorFormatter(500) } catch (err) { - t.equals(err.message, 'schemaErrorFormatter option should be a function, instead got number') + t.equal(err.message, 'schemaErrorFormatter option should be a function, instead got number') } }) @@ -570,12 +570,12 @@ test('should register a route based schema error formatter', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'abc' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) t.end() }) }) @@ -613,12 +613,12 @@ test('prefer route based error formatter over global one', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: '123' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -629,12 +629,12 @@ test('prefer route based error formatter over global one', t => { url: '/abc' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'abc' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -645,12 +645,12 @@ test('prefer route based error formatter over global one', t => { url: '/test' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'abc123' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) @@ -673,12 +673,12 @@ test('adding schemaErrorFormatter', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'abc' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) t.end() }) }) @@ -733,12 +733,12 @@ test('plugin override', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'A' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -749,12 +749,12 @@ test('plugin override', t => { url: '/b' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'B' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -765,12 +765,12 @@ test('plugin override', t => { url: '/c' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'C' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -781,12 +781,12 @@ test('plugin override', t => { url: '/d' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'D' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) fastify.inject({ @@ -797,11 +797,11 @@ test('plugin override', t => { url: '/stillC' }, (err, res) => { t.error(err) - t.deepEqual(res.json(), { + t.same(res.json(), { statusCode: 400, error: 'Bad Request', message: 'C' }) - t.strictEqual(res.statusCode, 400) + t.equal(res.statusCode, 400) }) }) diff --git a/test/versioned-routes.test.js b/test/versioned-routes.test.js index 9ab571bffe..86881c86f8 100644 --- a/test/versioned-routes.test.js +++ b/test/versioned-routes.test.js @@ -30,8 +30,8 @@ test('Should register a versioned route', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -42,8 +42,8 @@ test('Should register a versioned route', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -54,8 +54,8 @@ test('Should register a versioned route', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -66,7 +66,7 @@ test('Should register a versioned route', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -91,8 +91,8 @@ test('Should register a versioned route via route constraints', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -103,8 +103,8 @@ test('Should register a versioned route via route constraints', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) }) }) @@ -138,8 +138,8 @@ test('Should register the same route with different versions', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.payload, '1.3.0') + t.equal(res.statusCode, 200) + t.equal(res.payload, '1.3.0') }) fastify.inject({ @@ -150,8 +150,8 @@ test('Should register the same route with different versions', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.payload, '1.2.0') + t.equal(res.statusCode, 200) + t.equal(res.payload, '1.2.0') }) fastify.inject({ @@ -162,7 +162,7 @@ test('Should register the same route with different versions', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -195,8 +195,8 @@ test('The versioned route should take precedence', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) }) }) @@ -218,7 +218,7 @@ test('Versioned route but not version header should return a 404', t => { url: '/' }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -247,8 +247,8 @@ test('Should register a versioned route', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 200) - t.deepEqual(JSON.parse(body), { hello: 'world' }) + t.equal(response.statusCode, 200) + t.same(JSON.parse(body), { hello: 'world' }) }) sget({ @@ -259,7 +259,7 @@ test('Should register a versioned route', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) }) @@ -280,8 +280,8 @@ test('Shorthand route declaration', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -292,7 +292,7 @@ test('Shorthand route declaration', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -322,8 +322,8 @@ test('The not found handler should not use the Accept-Version header', t => { } }, (err, res) => { t.error(err) - t.deepEqual(res.payload, 'not found handler') - t.strictEqual(res.statusCode, 404) + t.same(res.payload, 'not found handler') + t.equal(res.statusCode, 404) }) }) @@ -348,7 +348,7 @@ test('Bad accept version (inject)', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) fastify.inject({ @@ -359,7 +359,7 @@ test('Bad accept version (inject)', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -388,7 +388,7 @@ test('Bas accept version (server)', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) sget({ @@ -399,7 +399,7 @@ test('Bas accept version (server)', t => { } }, (err, response, body) => { t.error(err) - t.strictEqual(response.statusCode, 404) + t.equal(response.statusCode, 404) }) }) }) @@ -496,8 +496,8 @@ test('Should register a versioned route with custom versioning strategy', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'from route v2' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'from route v2' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -508,8 +508,8 @@ test('Should register a versioned route with custom versioning strategy', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'from route v3' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'from route v3' }) + t.equal(res.statusCode, 200) }) fastify.inject({ @@ -520,7 +520,7 @@ test('Should register a versioned route with custom versioning strategy', t => { } }, (err, res) => { t.error(err) - t.strictEqual(res.statusCode, 404) + t.equal(res.statusCode, 404) }) }) @@ -562,9 +562,9 @@ test('Vary header check (for documentation example)', t => { } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers.vary, 'Accept-Version') + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.equal(res.headers.vary, 'Accept-Version') }) fastify.inject({ @@ -572,9 +572,9 @@ test('Vary header check (for documentation example)', t => { url: '/' }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) - t.strictEqual(res.headers.vary, undefined) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) + t.equal(res.headers.vary, undefined) }) }) @@ -582,7 +582,7 @@ test('Should trigger a warning when a versioned route is registered via version t.plan(4) function onWarning (code) { - t.strictEqual(code, 'FSTDEP006') + t.equal(code, 'FSTDEP006') } const warning = { emit: onWarning @@ -608,7 +608,7 @@ test('Should trigger a warning when a versioned route is registered via version } }, (err, res) => { t.error(err) - t.deepEqual(JSON.parse(res.payload), { hello: 'world' }) - t.strictEqual(res.statusCode, 200) + t.same(JSON.parse(res.payload), { hello: 'world' }) + t.equal(res.statusCode, 200) }) }) diff --git a/test/wrapThenable.test.js b/test/wrapThenable.test.js index d20608700f..6f4c838743 100644 --- a/test/wrapThenable.test.js +++ b/test/wrapThenable.test.js @@ -19,7 +19,7 @@ test('should reject immediately when reply[kReplySentOverwritten] is true', t => reply[kReplySentOverwritten] = true reply.log = { error: ({ err }) => { - t.strictEqual(err.message, 'Reply sent already') + t.equal(err.message, 'Reply sent already') } }