Skip to content

Commit 6d1dcf8

Browse files
Migration to node test runner (#495)
* chore: remove tap * chore: content type promises * chore: removed simple get * chore: listen as promise * chore: prefixAvoidTrailingSlash * fix: register /static * feat: static * feat: static static2 * chore: constraints * chore: payload path * chore: error handler * fix: not found * chore: not foundhandler * chore: serving disabled * chore: sendFile * chore: sendFile disabled * chore: allowedPath * chore: allowed path request * chore: download * chore: sendFile * chore: removed duplicated test * chore: download disabled * chore: tests * chore: send options * chore: setHeaders option * chore: maxAge * chore: errors * chore: register no prefix * chore: compress * chore: register static schema hide * chore: register static schema hide * chore: register static without schema hide * chore: exposeHeadRoutes * chore: wildcard false * chore: wildcard + trailing slash * chore: deps * chore: register with wildcard * chore: static with wildcard alternative index * chore: static with redirect * feat: static with redirect and not wildcard * chore: trailing slash behaviour * chore: dotfiles * chore: fail glob * chore: enoent * chore: premature stream close * chore: .br * chore: percent encoded * chore: static and static2 wildcard * chore: headers get * chore: erorr headers get * chore: redirect * chore: serve index false * chore: symbolik link * chore: serve hidden dir with false wildcard * chore: not found hidden * chore: wildcard * chore: content length * chore: respect .code * chore: respect .type * chore: removed simple * chore: dir list wrong * fix: dir list * fix: dir list custom options * chore: html format * chore: dir list * dir list html format * chore: dir list * chore: dir list json * chore: json format * chore: json format * chore: html format * chore: list html * chore: not existing dirs * chore: dir with dotfiles * chore: dir with dotfiles * chore: arrange * chore: static * chore: close * chore: rejects * chore: removed simple-get * chore: deepStrictEqual * chore: use c8 * chore: withResolvers polyfill * fix: pattern * Update test/static.test.js Co-authored-by: Dan Castillo <[email protected]> Signed-off-by: Matteo Pietro Dazzi <[email protected]> * chore: equal * fix: pattern test folder * chore: removed additional --test * fix: pattern * chore: switch to borp * Update package.json Co-authored-by: Dan Castillo <[email protected]> Signed-off-by: Matteo Pietro Dazzi <[email protected]> * Update package.json Co-authored-by: Dan Castillo <[email protected]> Signed-off-by: Matteo Pietro Dazzi <[email protected]> * chore: c8 --------- Signed-off-by: Matteo Pietro Dazzi <[email protected]> Co-authored-by: Dan Castillo <[email protected]>
1 parent fd2e776 commit 6d1dcf8

File tree

5 files changed

+2083
-2829
lines changed

5 files changed

+2083
-2829
lines changed

.taprc

Lines changed: 0 additions & 2 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"type": "commonjs",
77
"types": "types/index.d.ts",
88
"scripts": {
9-
"coverage": "npm run test:unit -- --coverage-report=html",
9+
"coverage": "c8 --reporter html borp --coverage --check-coverage --lines 100",
1010
"lint": "eslint",
1111
"lint:fix": "eslint --fix",
1212
"test": "npm run test:unit && npm run test:typescript",
1313
"test:typescript": "tsd",
14-
"test:unit": "tap",
14+
"test:unit": "borp -C --check-coverage --lines 100",
1515
"example": "node example/server.js"
1616
},
1717
"repository": {
@@ -69,14 +69,14 @@
6969
"@fastify/compress": "^8.0.0",
7070
"@fastify/pre-commit": "^2.1.0",
7171
"@types/node": "^22.0.0",
72+
"borp": "^0.19.0",
73+
"c8": "^10.1.3",
7274
"concat-stream": "^2.0.0",
7375
"eslint": "^9.17.0",
7476
"fastify": "^5.1.0",
7577
"neostandard": "^0.12.0",
7678
"pino": "^9.1.0",
7779
"proxyquire": "^2.1.3",
78-
"simple-get": "^4.0.1",
79-
"tap": "^18.7.1",
8080
"tsd": "^0.31.0"
8181
},
8282
"tsd": {

test/content-type.test.js

Lines changed: 97 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
/* eslint n/no-deprecated-api: "off" */
44

55
const path = require('node:path')
6-
const { test } = require('tap')
7-
const simple = require('simple-get')
6+
const { test } = require('node:test')
87
const Fastify = require('fastify')
98

109
const fastifyStatic = require('../')
1110

12-
test('register /content-type', t => {
13-
t.plan(6)
11+
test('register /content-type', async t => {
12+
t.plan(5)
1413

1514
const pluginOptions = {
1615
root: path.join(__dirname, '/content-type'),
@@ -19,72 +18,55 @@ test('register /content-type', t => {
1918
const fastify = Fastify()
2019
fastify.register(fastifyStatic, pluginOptions)
2120

22-
t.teardown(fastify.close.bind(fastify))
21+
t.after(() => fastify.close())
2322

24-
fastify.listen({ port: 0 }, (err) => {
25-
t.error(err)
23+
await fastify.listen({ port: 0 })
2624

27-
fastify.server.unref()
25+
fastify.server.unref()
2826

29-
t.test('/content-type/index.html', (t) => {
30-
t.plan(2)
31-
simple.concat({
32-
method: 'GET',
33-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.html'
34-
}, (err, response) => {
35-
t.error(err)
36-
t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
37-
})
38-
})
27+
await t.test('/content-type/index.html', async (t) => {
28+
t.plan(2)
3929

40-
t.test('/content-type/index.css', (t) => {
41-
t.plan(2)
42-
simple.concat({
43-
method: 'GET',
44-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.css'
45-
}, (err, response) => {
46-
t.error(err)
47-
t.equal(response.headers['content-type'], 'text/css; charset=utf-8')
48-
})
49-
})
30+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.html')
31+
t.assert.ok(response.ok)
32+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/html; charset=utf-8')
33+
})
5034

51-
t.test('/content-type/sample.jpg', (t) => {
52-
t.plan(2)
53-
simple.concat({
54-
method: 'GET',
55-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg'
56-
}, (err, response) => {
57-
t.error(err)
58-
t.equal(response.headers['content-type'], 'image/jpeg')
59-
})
60-
})
35+
await t.test('/content-type/index.css', async (t) => {
36+
t.plan(2)
6137

62-
t.test('/content-type/test.txt', (t) => {
63-
t.plan(2)
64-
simple.concat({
65-
method: 'GET',
66-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/test.txt'
67-
}, (err, response) => {
68-
t.error(err)
69-
t.equal(response.headers['content-type'], 'text/plain; charset=utf-8')
70-
})
71-
})
38+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.css')
39+
t.assert.ok(response.ok)
40+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/css; charset=utf-8')
41+
})
7242

73-
t.test('/content-type/binary', (t) => {
74-
t.plan(2)
75-
simple.concat({
76-
method: 'GET',
77-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/binary'
78-
}, (err, response) => {
79-
t.error(err)
80-
t.equal(response.headers['content-type'], 'application/octet-stream')
81-
})
82-
})
43+
await t.test('/content-type/sample.jpg', async (t) => {
44+
t.plan(2)
45+
46+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg')
47+
t.assert.ok(response.ok)
48+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'image/jpeg')
49+
})
50+
51+
await t.test('/content-type/test.txt', async (t) => {
52+
t.plan(2)
53+
54+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/test.txt')
55+
t.assert.ok(response.ok)
56+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/plain; charset=utf-8')
57+
})
58+
59+
await t.test('/content-type/binary', async (t) => {
60+
t.plan(2)
61+
62+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/binary')
63+
t.assert.ok(response.ok)
64+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'application/octet-stream')
8365
})
8466
})
8567

86-
test('register /content-type preCompressed', t => {
87-
t.plan(6)
68+
test('register /content-type preCompressed', async t => {
69+
t.plan(5)
8870

8971
const pluginOptions = {
9072
root: path.join(__dirname, '/content-type'),
@@ -94,81 +76,69 @@ test('register /content-type preCompressed', t => {
9476
const fastify = Fastify()
9577
fastify.register(fastifyStatic, pluginOptions)
9678

97-
t.teardown(fastify.close.bind(fastify))
98-
99-
fastify.listen({ port: 0 }, (err) => {
100-
t.error(err)
101-
102-
fastify.server.unref()
103-
104-
t.test('/content-type/index.html', (t) => {
105-
t.plan(2)
106-
simple.concat({
107-
method: 'GET',
108-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.html',
109-
headers: {
110-
'accept-encoding': 'gzip, deflate, br'
111-
}
112-
}, (err, response) => {
113-
t.error(err)
114-
t.equal(response.headers['content-type'], 'text/html; charset=utf-8')
115-
})
79+
t.after(() => fastify.close())
80+
81+
await fastify.listen({ port: 0 })
82+
83+
fastify.server.unref()
84+
85+
await t.test('/content-type/index.html', async (t) => {
86+
t.plan(2)
87+
88+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.html', {
89+
headers: {
90+
'accept-encoding': 'gzip, deflate, br'
91+
}
11692
})
93+
t.assert.ok(response.ok)
94+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/html; charset=utf-8')
95+
})
96+
97+
await t.test('/content-type/index.css', async (t) => {
98+
t.plan(2)
11799

118-
t.test('/content-type/index.css', (t) => {
119-
t.plan(2)
120-
simple.concat({
121-
method: 'GET',
122-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.css',
123-
headers: {
124-
'accept-encoding': 'gzip, deflate, br'
125-
}
126-
}, (err, response) => {
127-
t.error(err)
128-
t.equal(response.headers['content-type'], 'text/css; charset=utf-8')
129-
})
100+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.css', {
101+
headers: {
102+
'accept-encoding': 'gzip, deflate, br'
103+
}
130104
})
105+
t.assert.ok(response.ok)
106+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/css; charset=utf-8')
107+
})
108+
109+
await t.test('/content-type/sample.jpg', async (t) => {
110+
t.plan(2)
131111

132-
t.test('/content-type/sample.jpg', (t) => {
133-
t.plan(2)
134-
simple.concat({
135-
method: 'GET',
136-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg',
137-
headers: {
138-
'accept-encoding': 'gzip, deflate, br'
139-
}
140-
}, (err, response) => {
141-
t.error(err)
142-
t.equal(response.headers['content-type'], 'image/jpeg')
143-
})
112+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg', {
113+
headers: {
114+
'accept-encoding': 'gzip, deflate, br'
115+
}
144116
})
117+
t.assert.ok(response.ok)
118+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'image/jpeg')
119+
})
145120

146-
t.test('/content-type/test.txt', (t) => {
147-
t.plan(2)
148-
simple.concat({
149-
method: 'GET',
150-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/test.txt',
151-
headers: {
152-
'accept-encoding': 'gzip, deflate, br'
153-
}
154-
}, (err, response) => {
155-
t.error(err)
156-
t.equal(response.headers['content-type'], 'text/plain; charset=utf-8')
157-
})
121+
await t.test('/content-type/test.txt', async (t) => {
122+
t.plan(2)
123+
124+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/test.txt', {
125+
headers: {
126+
'accept-encoding': 'gzip, deflate, br'
127+
}
158128
})
129+
t.assert.ok(response.ok)
130+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/plain; charset=utf-8')
131+
})
132+
133+
await t.test('/content-type/binary', async (t) => {
134+
t.plan(2)
159135

160-
t.test('/content-type/binary', (t) => {
161-
t.plan(2)
162-
simple.concat({
163-
method: 'GET',
164-
url: 'http://localhost:' + fastify.server.address().port + '/content-type/binary',
165-
headers: {
166-
'accept-encoding': 'gzip, deflate, br'
167-
}
168-
}, (err, response) => {
169-
t.error(err)
170-
t.equal(response.headers['content-type'], 'application/octet-stream')
171-
})
136+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/binary', {
137+
headers: {
138+
'accept-encoding': 'gzip, deflate, br'
139+
}
172140
})
141+
t.assert.ok(response.ok)
142+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'application/octet-stream')
173143
})
174144
})

0 commit comments

Comments
 (0)