|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 |
| -const t = require('tap') |
| 3 | +const { after, before, describe, it } = require('node:test') |
| 4 | +const assert = require('node:assert') |
4 | 5 | const Fastify = require('fastify')
|
5 | 6 |
|
6 |
| -t.plan(13) |
7 |
| - |
8 |
| -const app = Fastify() |
9 |
| - |
10 |
| -app.register(require('./autohooks/cascade')) |
11 |
| -app.decorateRequest('hooked', '') |
| 7 | +describe('Node test suite for autohooks-cascade', function () { |
| 8 | + const app = Fastify() |
| 9 | + before(async function () { |
| 10 | + app.register(require('./autohooks/cascade')) |
| 11 | + app.decorateRequest('hooked', '') |
| 12 | + await app.ready() |
| 13 | + }) |
12 | 14 |
|
13 |
| -app.ready(function (err) { |
14 |
| - t.error(err) |
| 15 | + after(async function () { |
| 16 | + await app.close() |
| 17 | + }) |
15 | 18 |
|
16 |
| - app.inject({ |
17 |
| - url: '/' |
18 |
| - }, function (err, res) { |
19 |
| - t.error(err) |
| 19 | + it('should respond correctly to /', async function () { |
| 20 | + const res = await app.inject({ url: '/' }) |
20 | 21 |
|
21 |
| - t.equal(res.statusCode, 200) |
22 |
| - t.same(JSON.parse(res.payload), { hooked: ['root'] }) |
| 22 | + assert.strictEqual(res.statusCode, 200) |
| 23 | + assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] }) |
23 | 24 | })
|
24 | 25 |
|
25 |
| - app.inject({ |
26 |
| - url: '/child' |
27 |
| - }, function (err, res) { |
28 |
| - t.error(err) |
| 26 | + it('should respond correctly to /child', async function () { |
| 27 | + const res = await app.inject({ url: '/child' }) |
29 | 28 |
|
30 |
| - t.equal(res.statusCode, 200) |
31 |
| - t.same(JSON.parse(res.payload), { hooked: ['root', 'child'] }) |
| 29 | + assert.strictEqual(res.statusCode, 200) |
| 30 | + assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root', 'child'] }) |
32 | 31 | })
|
33 | 32 |
|
34 |
| - app.inject({ |
35 |
| - url: '/child/grandchild' |
36 |
| - }, function (err, res) { |
37 |
| - t.error(err) |
| 33 | + it('should respond correctly to /child/grandchild', async function () { |
| 34 | + const res = await app.inject({ url: '/child/grandchild' }) |
38 | 35 |
|
39 |
| - t.equal(res.statusCode, 200) |
40 |
| - t.same(JSON.parse(res.payload), { hooked: ['root', 'child', 'grandchild'] }) |
| 36 | + assert.strictEqual(res.statusCode, 200) |
| 37 | + assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root', 'child', 'grandchild'] }) |
41 | 38 | })
|
42 | 39 |
|
43 |
| - app.inject({ |
44 |
| - url: '/sibling' |
45 |
| - }, function (err, res) { |
46 |
| - t.error(err) |
| 40 | + it('should respond correctly to /sibling', async function () { |
| 41 | + const res = await app.inject({ url: '/sibling' }) |
47 | 42 |
|
48 |
| - t.equal(res.statusCode, 200) |
49 |
| - t.same(JSON.parse(res.payload), { hooked: ['root'] }) |
| 43 | + assert.strictEqual(res.statusCode, 200) |
| 44 | + assert.deepStrictEqual(JSON.parse(res.payload), { hooked: ['root'] }) |
50 | 45 | })
|
51 | 46 | })
|
0 commit comments