@@ -7,12 +7,12 @@ const Fastify = require('fastify')
77
88const pkg = require ( '../package.json' )
99
10- test ( 'fastify-plugin is a function' , async ( t ) => {
10+ test ( 'fastify-plugin is a function' , ( t ) => {
1111 t . plan ( 1 )
1212 t . assert . ok ( typeof fp === 'function' )
1313} )
1414
15- test ( 'should return the function with the skip-override Symbol' , async ( t ) => {
15+ test ( 'should return the function with the skip-override Symbol' , ( t ) => {
1616 t . plan ( 1 )
1717
1818 function plugin ( fastify , opts , next ) {
@@ -23,7 +23,7 @@ test('should return the function with the skip-override Symbol', async (t) => {
2323 t . assert . ok ( plugin [ Symbol . for ( 'skip-override' ) ] )
2424} )
2525
26- test ( 'should support "default" function from babel module' , async ( t ) => {
26+ test ( 'should support "default" function from babel module' , ( t ) => {
2727 t . plan ( 1 )
2828
2929 const plugin = {
@@ -38,7 +38,7 @@ test('should support "default" function from babel module', async (t) => {
3838 }
3939} )
4040
41- test ( 'should throw if the plugin is not a function' , async ( t ) => {
41+ test ( 'should throw if the plugin is not a function' , ( t ) => {
4242 t . plan ( 1 )
4343
4444 try {
@@ -49,7 +49,7 @@ test('should throw if the plugin is not a function', async (t) => {
4949 }
5050} )
5151
52- test ( 'should check the fastify version' , async ( t ) => {
52+ test ( 'should check the fastify version' , ( t ) => {
5353 t . plan ( 1 )
5454
5555 function plugin ( fastify , opts , next ) {
@@ -64,7 +64,7 @@ test('should check the fastify version', async (t) => {
6464 }
6565} )
6666
67- test ( 'should check the fastify version' , async ( t ) => {
67+ test ( 'should check the fastify version' , ( t ) => {
6868 t . plan ( 1 )
6969
7070 function plugin ( fastify , opts , next ) {
@@ -79,7 +79,7 @@ test('should check the fastify version', async (t) => {
7979 }
8080} )
8181
82- test ( 'the options object should be an object' , async ( t ) => {
82+ test ( 'the options object should be an object' , ( t ) => {
8383 t . plan ( 2 )
8484
8585 try {
@@ -97,7 +97,7 @@ test('the options object should be an object', async (t) => {
9797 }
9898} )
9999
100- test ( 'should throw if the version number is not a string' , async ( t ) => {
100+ test ( 'should throw if the version number is not a string' , ( t ) => {
101101 t . plan ( 1 )
102102
103103 try {
@@ -108,7 +108,7 @@ test('should throw if the version number is not a string', async (t) => {
108108 }
109109} )
110110
111- test ( 'Should accept an option object' , async ( t ) => {
111+ test ( 'Should accept an option object' , ( t ) => {
112112 t . plan ( 2 )
113113
114114 const opts = { hello : 'world' }
@@ -123,7 +123,7 @@ test('Should accept an option object', async (t) => {
123123 t . assert . deepStrictEqual ( plugin [ Symbol . for ( 'plugin-meta' ) ] , opts , 'plugin-meta should match opts' )
124124} )
125125
126- test ( 'Should accept an option object and checks the version' , async ( t ) => {
126+ test ( 'Should accept an option object and checks the version' , ( t ) => {
127127 t . plan ( 2 )
128128
129129 const opts = { hello : 'world' , fastify : '>=0.10.0' }
@@ -137,7 +137,7 @@ test('Should accept an option object and checks the version', async (t) => {
137137 t . assert . deepStrictEqual ( plugin [ Symbol . for ( 'plugin-meta' ) ] , opts )
138138} )
139139
140- test ( 'should set anonymous function name to file it was called from with a counter' , async ( t ) => {
140+ test ( 'should set anonymous function name to file it was called from with a counter' , ( t ) => {
141141 const fp = proxyquire ( '../plugin.js' , { stubs : { } } )
142142
143143 const fn = fp ( ( fastify , opts , next ) => {
@@ -155,7 +155,7 @@ test('should set anonymous function name to file it was called from with a count
155155 t . assert . strictEqual ( fn2 [ Symbol . for ( 'fastify.display-name' ) ] , 'test-auto-1' )
156156} )
157157
158- test ( 'should set function name if Error.stackTraceLimit is set to 0' , async ( t ) => {
158+ test ( 'should set function name if Error.stackTraceLimit is set to 0' , ( t ) => {
159159 const stackTraceLimit = Error . stackTraceLimit = 0
160160
161161 const fp = proxyquire ( '../plugin.js' , { stubs : { } } )
@@ -177,7 +177,7 @@ test('should set function name if Error.stackTraceLimit is set to 0', async (t)
177177 Error . stackTraceLimit = stackTraceLimit
178178} )
179179
180- test ( 'should set display-name to meta name' , async ( t ) => {
180+ test ( 'should set display-name to meta name' , ( t ) => {
181181 t . plan ( 2 )
182182
183183 const functionName = 'superDuperSpecialFunction'
@@ -190,7 +190,7 @@ test('should set display-name to meta name', async (t) => {
190190 t . assert . strictEqual ( fn [ Symbol . for ( 'fastify.display-name' ) ] , functionName )
191191} )
192192
193- test ( 'should preserve fastify version in meta' , async ( t ) => {
193+ test ( 'should preserve fastify version in meta' , ( t ) => {
194194 t . plan ( 1 )
195195
196196 const opts = { hello : 'world' , fastify : '>=0.10.0' }
@@ -215,12 +215,7 @@ test('should check fastify dependency graph - plugin', async (t) => {
215215 dependencies : [ 'plugin1-name' , 'plugin2-name' ]
216216 } ) )
217217
218- try {
219- await fastify . ready ( )
220- t . assert . fail ( )
221- } catch ( err ) {
222- t . assert . strictEqual ( err . message , "The dependency 'plugin2-name' of plugin 'test' is not registered" )
223- }
218+ await t . assert . rejects ( fastify . ready ( ) , { message : "The dependency 'plugin2-name' of plugin 'test' is not registered" } )
224219} )
225220
226221test ( 'should check fastify dependency graph - decorate' , async ( t ) => {
@@ -238,12 +233,7 @@ test('should check fastify dependency graph - decorate', async (t) => {
238233 decorators : { fastify : [ 'plugin1' , 'plugin2' ] }
239234 } ) )
240235
241- try {
242- await fastify . ready ( )
243- t . assert . fail ( )
244- } catch ( err ) {
245- t . assert . strictEqual ( err . message , "The decorator 'plugin2' required by 'test' is not present in Fastify" )
246- }
236+ await t . assert . rejects ( fastify . ready ( ) , { message : "The decorator 'plugin2' required by 'test' is not present in Fastify" } )
247237} )
248238
249239test ( 'should check fastify dependency graph - decorateReply' , async ( t ) => {
@@ -261,11 +251,7 @@ test('should check fastify dependency graph - decorateReply', async (t) => {
261251 decorators : { reply : [ 'plugin1' , 'plugin2' ] }
262252 } ) )
263253
264- try {
265- await fastify . ready ( )
266- } catch ( err ) {
267- t . assert . strictEqual ( err . message , "The decorator 'plugin2' required by 'test' is not present in Reply" )
268- }
254+ await t . assert . rejects ( fastify . ready ( ) , { message : "The decorator 'plugin2' required by 'test' is not present in Reply" } )
269255} )
270256
271257test ( 'should accept an option to encapsulate' , async ( t ) => {
@@ -296,11 +282,8 @@ test('should accept an option to encapsulate', async (t) => {
296282 encapsulate : true
297283 } ) )
298284
299- try {
300- await fastify . ready ( )
301- } catch ( err ) {
302- t . assert . ifError ( err )
303- }
285+ await fastify . ready ( )
286+
304287 t . assert . ok ( fastify . hasDecorator ( 'accessible' ) )
305288 t . assert . ok ( fastify . hasDecorator ( 'alsoAccessible' ) )
306289 t . assert . ok ( ! fastify . hasDecorator ( 'encapsulated' ) )
@@ -316,14 +299,7 @@ test('should check dependencies when encapsulated', async (t) => {
316299 encapsulate : true
317300 } ) )
318301
319- try {
320- await fastify . ready ( )
321- } catch ( err ) {
322- t . assert . strictEqual ( err . message , "The dependency 'missing-dependency-name' of plugin 'test' is not registered" )
323- }
324- // fastify.ready(err => {
325- // t.equal(err.message, "The dependency 'missing-dependency-name' of plugin 'test' is not registered")
326- // })
302+ await t . assert . rejects ( fastify . ready ( ) , { message : "The dependency 'missing-dependency-name' of plugin 'test' is not registered" } )
327303} )
328304
329305test (
@@ -339,11 +315,7 @@ test(
339315 encapsulate : true
340316 } ) )
341317
342- try {
343- await fastify . ready ( )
344- } catch ( err ) {
345- t . assert . match ( err . message , / f a s t i f y - p l u g i n : t e s t - e x p e c t e d ' < = 2 .1 0 .0 ' f a s t i f y v e r s i o n , ' \d .\d + .\d + ' i s i n s t a l l e d / )
346- }
318+ await t . assert . rejects ( fastify . ready ( ) , { message : / f a s t i f y - p l u g i n : t e s t - e x p e c t e d ' < = 2 .1 0 .0 ' f a s t i f y v e r s i o n , ' \d .\d + .\d + ' i s i n s t a l l e d / } )
347319 }
348320)
349321
@@ -360,11 +332,7 @@ test('should check decorators when encapsulated', async (t) => {
360332 decorators : { fastify : [ 'plugin1' , 'plugin2' ] }
361333 } ) )
362334
363- try {
364- await fastify . ready ( )
365- } catch ( err ) {
366- t . assert . strictEqual ( err . message , "The decorator 'plugin2' required by 'test' is not present in Fastify" )
367- }
335+ await t . assert . rejects ( fastify . ready ( ) , { message : "The decorator 'plugin2' required by 'test' is not present in Fastify" } )
368336} )
369337
370338test ( 'plugin name when encapsulated' , async ( t ) => {
0 commit comments