File tree Expand file tree Collapse file tree 3 files changed +44
-16
lines changed Expand file tree Collapse file tree 3 files changed +44
-16
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ // This file contains code that we reuse
4
+ // between our tests.
5
+
6
+ const Fastify = require ( 'fastify' )
7
+ const fp = require ( 'fastify-plugin' )
8
+ const App = require ( '../app' )
9
+
10
+ // Fill in this config with all the configurations
11
+ // needed for testing the application
12
+ function config ( ) {
13
+ return { }
14
+ }
15
+
16
+ // automatically build and tear down our instance
17
+ function build ( t ) {
18
+ const app = Fastify ( )
19
+
20
+ // fastify-plugin ensures that all decorators
21
+ // are exposed for testing purposes, this is
22
+ // different from the production setup
23
+ app . register ( fp ( App ) , config ( ) )
24
+
25
+ // tear down our app after we are done
26
+ t . tearDown ( app . close . bind ( app ) )
27
+
28
+ return app
29
+ }
30
+
31
+ module . exports = {
32
+ config,
33
+ build
34
+ }
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const { test } = require ( 'tap' )
4
- const Fastify = require ( 'fastify' )
5
- const App = require ( '../../app' )
4
+ const { build } = require ( '../helper' )
6
5
7
6
test ( 'example is loaded' , ( t ) => {
8
7
t . plan ( 2 )
9
- const fastify = Fastify ( )
10
- fastify . register ( App )
8
+ const app = build ( t )
11
9
12
- fastify . inject ( {
10
+ app . inject ( {
13
11
url : '/example'
14
12
} , ( err , res ) => {
15
13
t . error ( err )
@@ -20,10 +18,9 @@ test('example is loaded', (t) => {
20
18
// It you prefer async/await, use the following
21
19
//
22
20
// test('example is loaded', async (t) => {
23
- // const fastify = Fastify()
24
- // fastify.register(App)
21
+ // const app = build(t)
25
22
//
26
- // const res = await fastify .inject({
23
+ // const res = await app .inject({
27
24
// url: '/example'
28
25
// })
29
26
// t.equal(res.payload, 'this is an example')
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
3
const { test } = require ( 'tap' )
4
- const Fastify = require ( 'fastify' )
5
- const App = require ( '../../app' )
4
+ const { build } = require ( '../helper' )
6
5
7
6
test ( 'default root route' , ( t ) => {
8
7
t . plan ( 2 )
9
- const fastify = Fastify ( )
10
- fastify . register ( App )
8
+ const app = build ( t )
11
9
12
- fastify . inject ( {
10
+ app . inject ( {
13
11
url : '/'
14
12
} , ( err , res ) => {
15
13
t . error ( err )
@@ -20,10 +18,9 @@ test('default root route', (t) => {
20
18
// It you prefer async/await, use the following
21
19
//
22
20
// test('default root route', async (t) => {
23
- // const fastify = Fastify()
24
- // fastify.register(App)
21
+ // const app = build(t)
25
22
//
26
- // const res = await fastify .inject({
23
+ // const res = await app .inject({
27
24
// url: '/'
28
25
// })
29
26
// t.deepEqual(JSON.parse(res.payload), { root: true })
You can’t perform that action at this time.
0 commit comments