Skip to content

Commit cec29a1

Browse files
committed
move the wait outside
Signed-off-by: Matteo Collina <[email protected]>
1 parent 5231e55 commit cec29a1

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

lib/plugin.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { readFile } from 'node:fs/promises'
22
import { basename } from 'node:path'
3-
import { setTimeout as sleep } from 'node:timers/promises'
43

54
const HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'TRACE']
65

@@ -29,10 +28,6 @@ export async function plugin (server, opts) {
2928
done(null, body)
3029
})
3130

32-
server.addHook('onClose', async () => {
33-
await sleep(1000)
34-
})
35-
3631
for (const method of HTTP_METHODS) {
3732
server.route({
3833
method,

test/plugin.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { resolve, join } from 'node:path'
55
import { test } from 'node:test'
66
import { stackable } from '../lib/index.js'
77
import formAutoContet from 'form-auto-content'
8+
import { setTimeout as sleep } from 'node:timers/promises'
89

910
async function startStackable (t, docroot = join(import.meta.dirname, './fixtures/hello'), opts = {}) {
1011
const config = {
@@ -21,9 +22,11 @@ async function startStackable (t, docroot = join(import.meta.dirname, './fixture
2122
}
2223
}
2324

24-
const server = await buildServer(config, stackable)
25+
let server = await buildServer(config, stackable)
2526
t.after(async () => {
2627
await server.close()
28+
server = null
29+
await sleep(1000) // wait for the server to close
2730
})
2831

2932
return server

0 commit comments

Comments
 (0)