Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b05ca2

Browse files
authored
chore: migrate to node test runner (#46)
1 parent d98fc41 commit 2b05ca2

File tree

2 files changed

+85
-85
lines changed

2 files changed

+85
-85
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
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": "c8 --100 node --test"
1515
},
1616
"keywords": [
1717
"content-type",
@@ -61,10 +61,10 @@
6161
"@fastify/pre-commit": "^2.1.0",
6262
"benchmark": "^2.1.4",
6363
"busboy": "^1.6.0",
64+
"c8": "^10.1.3",
6465
"content-type": "^1.0.4",
6566
"eslint": "^9.17.0",
6667
"neostandard": "^0.12.0",
67-
"tap": "^19.2.5",
6868
"tsd": "^0.31.0"
6969
},
7070
"pre-commit": [

test/index.test.js

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { test } = require('tap')
3+
const { test } = require('node:test')
44
const { parse, safeParse } = require('..')
55

66
const invalidTypes = [
@@ -17,232 +17,232 @@ const invalidTypes = [
1717
'text/plain,wrong'
1818
]
1919

20-
test('parse', function (t) {
20+
test('parse', async function (t) {
2121
t.plan(13 + invalidTypes.length)
22-
t.test('should parse basic type', function (t) {
22+
await t.test('should parse basic type', function (t) {
2323
t.plan(1)
2424
const type = parse('text/html')
25-
t.strictSame(type.type, 'text/html')
25+
t.assert.deepStrictEqual(type.type, 'text/html')
2626
})
2727

28-
t.test('should parse with suffix', function (t) {
28+
await t.test('should parse with suffix', function (t) {
2929
t.plan(1)
3030
const type = parse('image/svg+xml')
31-
t.strictSame(type.type, 'image/svg+xml')
31+
t.assert.deepStrictEqual(type.type, 'image/svg+xml')
3232
})
3333

34-
t.test('should parse basic type with surrounding OWS', function (t) {
34+
await t.test('should parse basic type with surrounding OWS', function (t) {
3535
t.plan(1)
3636
const type = parse(' text/html ')
37-
t.strictSame(type.type, 'text/html')
37+
t.assert.deepStrictEqual(type.type, 'text/html')
3838
})
3939

40-
t.test('should parse parameters', function (t) {
40+
await t.test('should parse parameters', function (t) {
4141
t.plan(2)
4242
const type = parse('text/html; charset=utf-8; foo=bar')
43-
t.strictSame(type.type, 'text/html')
44-
t.same(type.parameters, {
43+
t.assert.deepStrictEqual(type.type, 'text/html')
44+
t.assert.deepEqual(type.parameters, {
4545
charset: 'utf-8',
4646
foo: 'bar'
4747
})
4848
})
4949

50-
t.test('should parse parameters with extra LWS', function (t) {
50+
await t.test('should parse parameters with extra LWS', function (t) {
5151
t.plan(2)
5252
const type = parse('text/html ; charset=utf-8 ; foo=bar')
53-
t.strictSame(type.type, 'text/html')
54-
t.same(type.parameters, {
53+
t.assert.deepStrictEqual(type.type, 'text/html')
54+
t.assert.deepEqual(type.parameters, {
5555
charset: 'utf-8',
5656
foo: 'bar'
5757
})
5858
})
5959

60-
t.test('should lower-case type', function (t) {
60+
await t.test('should lower-case type', function (t) {
6161
t.plan(1)
6262
const type = parse('IMAGE/SVG+XML')
63-
t.strictSame(type.type, 'image/svg+xml')
63+
t.assert.deepStrictEqual(type.type, 'image/svg+xml')
6464
})
6565

66-
t.test('should lower-case parameter names', function (t) {
66+
await t.test('should lower-case parameter names', function (t) {
6767
t.plan(2)
6868
const type = parse('text/html; Charset=UTF-8')
69-
t.strictSame(type.type, 'text/html')
70-
t.same(type.parameters, {
69+
t.assert.deepStrictEqual(type.type, 'text/html')
70+
t.assert.deepEqual(type.parameters, {
7171
charset: 'UTF-8'
7272
})
7373
})
7474

75-
t.test('should unquote parameter values', function (t) {
75+
await t.test('should unquote parameter values', function (t) {
7676
t.plan(2)
7777
const type = parse('text/html; charset="UTF-8"')
78-
t.strictSame(type.type, 'text/html')
79-
t.same(type.parameters, {
78+
t.assert.deepStrictEqual(type.type, 'text/html')
79+
t.assert.deepEqual(type.parameters, {
8080
charset: 'UTF-8'
8181
})
8282
})
8383

84-
t.test('should unquote parameter values with escapes', function (t) {
84+
await t.test('should unquote parameter values with escapes', function (t) {
8585
t.plan(2)
8686
const type = parse('text/html; charset="UT\\F-\\\\\\"8\\""')
87-
t.strictSame(type.type, 'text/html')
88-
t.same(type.parameters, {
87+
t.assert.deepStrictEqual(type.type, 'text/html')
88+
t.assert.deepEqual(type.parameters, {
8989
charset: 'UTF-\\"8"'
9090
})
9191
})
9292

93-
t.test('should handle balanced quotes', function (t) {
93+
await t.test('should handle balanced quotes', function (t) {
9494
t.plan(2)
9595
const type = parse('text/html; param="charset=\\"utf-8\\"; foo=bar"; bar=foo')
96-
t.strictSame(type.type, 'text/html')
97-
t.same(type.parameters, {
96+
t.assert.deepStrictEqual(type.type, 'text/html')
97+
t.assert.deepEqual(type.parameters, {
9898
param: 'charset="utf-8"; foo=bar',
9999
bar: 'foo'
100100
})
101101
})
102102

103-
invalidTypes.forEach(function (type) {
104-
t.test('should throw on invalid media type ' + type, function (t) {
103+
invalidTypes.forEach(async function (type) {
104+
await t.test('should throw on invalid media type ' + type, function (t) {
105105
t.plan(1)
106-
t.throws(parse.bind(null, type), 'invalid media type')
106+
t.assert.throws(parse.bind(null, type), new TypeError('invalid media type'))
107107
})
108108
})
109109

110-
t.test('should throw on invalid parameter format', function (t) {
110+
await t.test('should throw on invalid parameter format', function (t) {
111111
t.plan(3)
112-
t.throws(parse.bind(null, 'text/plain; foo="bar'), 'invalid parameter format')
113-
t.throws(parse.bind(null, 'text/plain; profile=http://localhost; foo=bar'), 'invalid parameter format')
114-
t.throws(parse.bind(null, 'text/plain; profile=http://localhost'), 'invalid parameter format')
112+
t.assert.throws(parse.bind(null, 'text/plain; foo="bar'), new TypeError('invalid parameter format'))
113+
t.assert.throws(parse.bind(null, 'text/plain; profile=http://localhost; foo=bar'), new TypeError('invalid parameter format'))
114+
t.assert.throws(parse.bind(null, 'text/plain; profile=http://localhost'), new TypeError('invalid parameter format'))
115115
})
116116

117-
t.test('should require argument', function (t) {
117+
await t.test('should require argument', function (t) {
118118
t.plan(1)
119119
// @ts-expect-error should reject non-strings
120-
t.throws(parse.bind(null), 'argument header is required and must be a string')
120+
t.assert.throws(parse.bind(null), new TypeError('argument header is required and must be a string'))
121121
})
122122

123-
t.test('should reject non-strings', function (t) {
123+
await t.test('should reject non-strings', function (t) {
124124
t.plan(1)
125125
// @ts-expect-error should reject non-strings
126-
t.throws(parse.bind(null, 7), 'argument header is required and must be a string')
126+
t.assert.throws(parse.bind(null, 7), new TypeError('argument header is required and must be a string'))
127127
})
128128
})
129129

130-
test('safeParse', function (t) {
130+
test('safeParse', async function (t) {
131131
t.plan(13 + invalidTypes.length)
132-
t.test('should safeParse basic type', function (t) {
132+
await t.test('should safeParse basic type', function (t) {
133133
t.plan(1)
134134
const type = safeParse('text/html')
135-
t.strictSame(type.type, 'text/html')
135+
t.assert.deepStrictEqual(type.type, 'text/html')
136136
})
137137

138-
t.test('should safeParse with suffix', function (t) {
138+
await t.test('should safeParse with suffix', function (t) {
139139
t.plan(1)
140140
const type = safeParse('image/svg+xml')
141-
t.strictSame(type.type, 'image/svg+xml')
141+
t.assert.deepStrictEqual(type.type, 'image/svg+xml')
142142
})
143143

144-
t.test('should safeParse basic type with surrounding OWS', function (t) {
144+
await t.test('should safeParse basic type with surrounding OWS', function (t) {
145145
t.plan(1)
146146
const type = safeParse(' text/html ')
147-
t.strictSame(type.type, 'text/html')
147+
t.assert.deepStrictEqual(type.type, 'text/html')
148148
})
149149

150-
t.test('should safeParse parameters', function (t) {
150+
await t.test('should safeParse parameters', function (t) {
151151
t.plan(2)
152152
const type = safeParse('text/html; charset=utf-8; foo=bar')
153-
t.strictSame(type.type, 'text/html')
154-
t.same(type.parameters, {
153+
t.assert.deepStrictEqual(type.type, 'text/html')
154+
t.assert.deepEqual(type.parameters, {
155155
charset: 'utf-8',
156156
foo: 'bar'
157157
})
158158
})
159159

160-
t.test('should safeParse parameters with extra LWS', function (t) {
160+
await t.test('should safeParse parameters with extra LWS', function (t) {
161161
t.plan(2)
162162
const type = safeParse('text/html ; charset=utf-8 ; foo=bar')
163-
t.strictSame(type.type, 'text/html')
164-
t.same(type.parameters, {
163+
t.assert.deepStrictEqual(type.type, 'text/html')
164+
t.assert.deepEqual(type.parameters, {
165165
charset: 'utf-8',
166166
foo: 'bar'
167167
})
168168
})
169169

170-
t.test('should lower-case type', function (t) {
170+
await t.test('should lower-case type', function (t) {
171171
t.plan(1)
172172
const type = safeParse('IMAGE/SVG+XML')
173-
t.strictSame(type.type, 'image/svg+xml')
173+
t.assert.deepStrictEqual(type.type, 'image/svg+xml')
174174
})
175175

176-
t.test('should lower-case parameter names', function (t) {
176+
await t.test('should lower-case parameter names', function (t) {
177177
t.plan(2)
178178
const type = safeParse('text/html; Charset=UTF-8')
179-
t.strictSame(type.type, 'text/html')
180-
t.same(type.parameters, {
179+
t.assert.deepStrictEqual(type.type, 'text/html')
180+
t.assert.deepEqual(type.parameters, {
181181
charset: 'UTF-8'
182182
})
183183
})
184184

185-
t.test('should unquote parameter values', function (t) {
185+
await t.test('should unquote parameter values', function (t) {
186186
t.plan(2)
187187
const type = safeParse('text/html; charset="UTF-8"')
188-
t.strictSame(type.type, 'text/html')
189-
t.same(type.parameters, {
188+
t.assert.deepStrictEqual(type.type, 'text/html')
189+
t.assert.deepEqual(type.parameters, {
190190
charset: 'UTF-8'
191191
})
192192
})
193193

194-
t.test('should unquote parameter values with escapes', function (t) {
194+
await t.test('should unquote parameter values with escapes', function (t) {
195195
t.plan(2)
196196
const type = safeParse('text/html; charset="UT\\F-\\\\\\"8\\""')
197-
t.strictSame(type.type, 'text/html')
198-
t.same(type.parameters, {
197+
t.assert.deepStrictEqual(type.type, 'text/html')
198+
t.assert.deepEqual(type.parameters, {
199199
charset: 'UTF-\\"8"'
200200
})
201201
})
202202

203-
t.test('should handle balanced quotes', function (t) {
203+
await t.test('should handle balanced quotes', function (t) {
204204
t.plan(2)
205205
const type = safeParse('text/html; param="charset=\\"utf-8\\"; foo=bar"; bar=foo')
206-
t.strictSame(type.type, 'text/html')
207-
t.same(type.parameters, {
206+
t.assert.deepStrictEqual(type.type, 'text/html')
207+
t.assert.deepEqual(type.parameters, {
208208
param: 'charset="utf-8"; foo=bar',
209209
bar: 'foo'
210210
})
211211
})
212212

213-
invalidTypes.forEach(function (type) {
214-
t.test('should return dummyContentType on invalid media type ' + type, function (t) {
213+
invalidTypes.forEach(async function (type) {
214+
await t.test('should return dummyContentType on invalid media type ' + type, function (t) {
215215
t.plan(2)
216-
t.equal(safeParse(type).type, '')
217-
t.equal(Object.keys(safeParse(type).parameters).length, 0)
216+
t.assert.deepStrictEqual(safeParse(type).type, '')
217+
t.assert.deepStrictEqual(Object.keys(safeParse(type).parameters).length, 0)
218218
})
219219
})
220220

221-
t.test('should return dummyContentType on invalid parameter format', function (t) {
221+
await t.test('should return dummyContentType on invalid parameter format', function (t) {
222222
t.plan(6)
223-
t.equal(safeParse('text/plain; foo="bar').type, '')
224-
t.equal(Object.keys(safeParse('text/plain; foo="bar').parameters).length, 0)
223+
t.assert.deepStrictEqual(safeParse('text/plain; foo="bar').type, '')
224+
t.assert.deepStrictEqual(Object.keys(safeParse('text/plain; foo="bar').parameters).length, 0)
225225

226-
t.equal(safeParse('text/plain; profile=http://localhost; foo=bar').type, '')
227-
t.equal(Object.keys(safeParse('text/plain; profile=http://localhost; foo=bar').parameters).length, 0)
226+
t.assert.deepStrictEqual(safeParse('text/plain; profile=http://localhost; foo=bar').type, '')
227+
t.assert.deepStrictEqual(Object.keys(safeParse('text/plain; profile=http://localhost; foo=bar').parameters).length, 0)
228228

229-
t.equal(safeParse('text/plain; profile=http://localhost').type, '')
230-
t.equal(Object.keys(safeParse('text/plain; profile=http://localhost').parameters).length, 0)
229+
t.assert.deepStrictEqual(safeParse('text/plain; profile=http://localhost').type, '')
230+
t.assert.deepStrictEqual(Object.keys(safeParse('text/plain; profile=http://localhost').parameters).length, 0)
231231
})
232232

233-
t.test('should return dummyContentType on missing argument', function (t) {
233+
await t.test('should return dummyContentType on missing argument', function (t) {
234234
t.plan(2)
235235
// @ts-expect-error should reject non-strings
236-
t.equal(safeParse().type, '')
236+
t.assert.deepStrictEqual(safeParse().type, '')
237237
// @ts-expect-error should reject non-strings
238-
t.equal(Object.keys(safeParse().parameters).length, 0)
238+
t.assert.deepStrictEqual(Object.keys(safeParse().parameters).length, 0)
239239
})
240240

241-
t.test('should return dummyContentType on non-strings', function (t) {
241+
await t.test('should return dummyContentType on non-strings', function (t) {
242242
t.plan(2)
243243
// @ts-expect-error should reject non-strings
244-
t.equal(safeParse(null).type, '')
244+
t.assert.deepStrictEqual(safeParse(null).type, '')
245245
// @ts-expect-error should reject non-strings
246-
t.equal(Object.keys(safeParse(null).parameters).length, 0)
246+
t.assert.deepStrictEqual(Object.keys(safeParse(null).parameters).length, 0)
247247
})
248248
})

0 commit comments

Comments
 (0)