Skip to content

Commit e2b7a88

Browse files
committed
test: remove unnecessary async from test functions
1 parent 72cd887 commit e2b7a88

7 files changed

Lines changed: 34 additions & 66 deletions

File tree

test/bundlers.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test('webpack removes require.main.filename', t => {
2424
})
2525
})
2626

27-
test('support faux modules', async (t) => {
27+
test('support faux modules', (t) => {
2828
const plugin = fp((fastify, opts, next) => {
2929
next()
3030
})
@@ -44,7 +44,7 @@ test('support faux modules does not override existing default field in babel mod
4444
t.assert.strictEqual(plugin.default, 'Existing default field')
4545
})
4646

47-
test('support ts named imports', async (t) => {
47+
test('support ts named imports', (t) => {
4848
const plugin = fp((fastify, opts, next) => {
4949
next()
5050
}, {
@@ -54,7 +54,7 @@ test('support ts named imports', async (t) => {
5454
t.assert.strictEqual(plugin.hello, plugin)
5555
})
5656

57-
test('from kebab-case to camelCase', async (t) => {
57+
test('from kebab-case to camelCase', (t) => {
5858
const plugin = fp((fastify, opts, next) => {
5959
next()
6060
}, {
@@ -64,7 +64,7 @@ test('from kebab-case to camelCase', async (t) => {
6464
t.assert.strictEqual(plugin.helloWorld, plugin)
6565
})
6666

67-
test('from @-prefixed named imports', async (t) => {
67+
test('from @-prefixed named imports', (t) => {
6868
const plugin = fp((fastify, opts, next) => {
6969
next()
7070
}, {
@@ -74,7 +74,7 @@ test('from @-prefixed named imports', async (t) => {
7474
t.assert.strictEqual(plugin.helloWorld, plugin)
7575
})
7676

77-
test('from @-prefixed named kebab-case to camelCase', async (t) => {
77+
test('from @-prefixed named kebab-case to camelCase', (t) => {
7878
const plugin = fp((fastify, opts, next) => {
7979
next()
8080
}, {
@@ -84,7 +84,7 @@ test('from @-prefixed named kebab-case to camelCase', async (t) => {
8484
t.assert.strictEqual(plugin.helloMyWorld, plugin)
8585
})
8686

87-
test('from kebab-case to camelCase multiple words', async (t) => {
87+
test('from kebab-case to camelCase multiple words', (t) => {
8888
const plugin = fp((fastify, opts, next) => {
8989
next()
9090
}, {
@@ -94,7 +94,7 @@ test('from kebab-case to camelCase multiple words', async (t) => {
9494
t.assert.strictEqual(plugin.helloLongWorld, plugin)
9595
})
9696

97-
test('from kebab-case to camelCase multiple words does not override', async (t) => {
97+
test('from kebab-case to camelCase multiple words does not override', (t) => {
9898
const fn = (fastify, opts, next) => {
9999
next()
100100
}

test/composite.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const { test } = require('node:test')
44
const fp = require('../plugin')
55

6-
test('anonymous function should be named composite.test0', async (t) => {
6+
test('anonymous function should be named composite.test0', (t) => {
77
t.plan(2)
88
const fn = fp((fastify, opts, next) => {
99
next()

test/esm/esm.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test } from 'node:test'
22
import fp from '../../plugin.js'
33

4-
test('esm base support', async (t) => {
4+
test('esm base support', (t) => {
55
fp((fastify, opts, next) => {
66
next()
77
}, {

test/extractPluginName.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ at TAP.test (/home/leonardo/desktop/fastify-plugin/node_modules/tap/lib/test.js:
4141

4242
const anonymousStack = 'Unable to parse this'
4343

44-
test('extractPluginName tests', async (t) => {
44+
test('extractPluginName tests', (t) => {
4545
t.plan(3)
4646
t.assert.strictEqual(extractPluginName(winStack), 'hello.test')
4747
t.assert.strictEqual(extractPluginName(nixStack), 'this.is.a.test')

test/mu1tip1e.composite.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const { test } = require('node:test')
44
const fp = require('../plugin')
55

6-
test('anonymous function should be named mu1tip1e.composite.test', async (t) => {
6+
test('anonymous function should be named mu1tip1e.composite.test', (t) => {
77
t.plan(2)
88

99
const fn = fp((fastify, opts, next) => {

test/test.js

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const Fastify = require('fastify')
77

88
const 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

226221
test('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

249239
test('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

271257
test('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

329305
test(
@@ -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, /fastify-plugin: test - expected '<=2.10.0' fastify version, '\d.\d+.\d+' is installed/)
346-
}
318+
await t.assert.rejects(fastify.ready(), { message: /fastify-plugin: test - expected '<=2.10.0' fastify version, '\d.\d+.\d+' is installed/ })
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

370338
test('plugin name when encapsulated', async (t) => {

test/toCamelCase.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const { test } = require('node:test')
44
const toCamelCase = require('../lib/toCamelCase')
55

6-
test('from kebab-case to camelCase', async (t) => {
6+
test('from kebab-case to camelCase', (t) => {
77
t.plan(1)
88
t.assert.strictEqual(toCamelCase('hello-world'), 'helloWorld')
99
})

0 commit comments

Comments
 (0)