Skip to content

Commit 0a069ab

Browse files
authored
chore: remove mocha and chai (#2696)
* chore: remove mocha and chai, fix bug in fetch request * fix test * uncomment test cases * remove p-timeout * fix * add back removed line
1 parent 1661540 commit 0a069ab

File tree

7 files changed

+739
-755
lines changed

7 files changed

+739
-755
lines changed

package.json

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"lint:fix": "standard --fix | snazzy",
7979
"test": "node scripts/generate-pem && npm run test:tap && npm run test:node-fetch && npm run test:fetch && npm run test:cookies && npm run test:eventsource && npm run test:wpt && npm run test:websocket && npm run test:jest && npm run test:typescript && npm run test:node-test",
8080
"test:cookies": "borp --coverage -p \"test/cookie/*.js\"",
81-
"test:node-fetch": "mocha --exit test/node-fetch",
81+
"test:node-fetch": "borp --coverage -p \"test/node-fetch/**/*.js\"",
8282
"test:eventsource": "npm run build:node && borp --expose-gc --coverage -p \"test/eventsource/*.js\"",
8383
"test:fetch": "npm run build:node && borp --expose-gc --coverage -p \"test/fetch/*.js\" && borp --coverage -p \"test/webidl/*.js\"",
8484
"test:jest": "jest",
@@ -104,48 +104,42 @@
104104
"@sinonjs/fake-timers": "^11.1.0",
105105
"@types/node": "^18.0.3",
106106
"abort-controller": "^3.0.0",
107+
"axios": "^1.6.5",
107108
"borp": "^0.9.1",
108-
"chai": "^4.3.4",
109-
"chai-as-promised": "^7.1.1",
110-
"chai-iterator": "^3.0.2",
111-
"chai-string": "^1.5.0",
112109
"concurrently": "^8.0.1",
113110
"cronometro": "^2.0.2",
114111
"dns-packet": "^5.4.0",
115112
"docsify-cli": "^4.4.3",
116113
"form-data": "^4.0.0",
117114
"formdata-node": "^6.0.3",
115+
"got": "^14.0.0",
118116
"https-pem": "^3.0.0",
119117
"husky": "^9.0.7",
120118
"import-fresh": "^3.3.0",
121119
"jest": "^29.0.2",
122120
"jsdom": "^24.0.0",
123121
"jsfuzz": "^1.0.15",
124122
"mitata": "^0.1.8",
125-
"mocha": "^10.0.0",
126-
"p-timeout": "^3.2.0",
123+
"node-fetch": "^3.3.2",
127124
"pre-commit": "^1.2.2",
128125
"proxy": "^1.0.2",
129126
"proxyquire": "^2.1.3",
127+
"request": "^2.88.2",
130128
"sinon": "^17.0.1",
131129
"snazzy": "^9.0.0",
132130
"standard": "^17.0.0",
133131
"tap": "^16.1.0",
134132
"tsd": "^0.30.1",
135133
"typescript": "^5.0.2",
136134
"wait-on": "^7.0.1",
137-
"ws": "^8.11.0",
138-
"axios": "^1.6.5",
139-
"got": "^14.0.0",
140-
"node-fetch": "^3.3.2",
141-
"request": "^2.88.2"
135+
"ws": "^8.11.0"
142136
},
143137
"engines": {
144138
"node": ">=18.0"
145139
},
146140
"standard": {
147141
"env": [
148-
"mocha"
142+
"jest"
149143
],
150144
"ignore": [
151145
"lib/llhttp/constants.js",

test/node-fetch/headers.js

Lines changed: 106 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
/* eslint no-unused-expressions: "off" */
1+
'use strict'
22

3+
const assert = require('node:assert')
4+
const { describe, it } = require('node:test')
35
const { format } = require('node:util')
4-
const chai = require('chai')
5-
const chaiIterator = require('chai-iterator')
6-
const { Headers } = require('../../lib/fetch/headers.js')
7-
8-
chai.use(chaiIterator)
9-
10-
const { expect } = chai
6+
const { Headers } = require('../../index.js')
117

128
describe('Headers', () => {
139
it('should have attributes conforming to Web IDL', () => {
1410
const headers = new Headers()
15-
expect(Object.getOwnPropertyNames(headers)).to.be.empty
11+
assert.strictEqual(Object.getOwnPropertyNames(headers).length, 0)
1612
const enumerableProperties = []
1713

1814
for (const property in headers) {
@@ -30,7 +26,7 @@ describe('Headers', () => {
3026
'set',
3127
'values'
3228
]) {
33-
expect(enumerableProperties).to.contain(toCheck)
29+
assert.strictEqual(enumerableProperties.includes(toCheck), true)
3430
}
3531
})
3632

@@ -41,14 +37,14 @@ describe('Headers', () => {
4137
['b', '3'],
4238
['a', '1']
4339
])
44-
expect(headers).to.have.property('forEach')
40+
assert.strictEqual(typeof headers.forEach, 'function')
4541

4642
const result = []
4743
for (const [key, value] of headers.entries()) {
4844
result.push([key, value])
4945
}
5046

51-
expect(result).to.deep.equal([
47+
assert.deepStrictEqual(result, [
5248
['a', '1'],
5349
['b', '2, 3'],
5450
['c', '4']
@@ -66,23 +62,23 @@ describe('Headers', () => {
6662
results.push({ value, key, object })
6763
})
6864

69-
expect(results.length).to.equal(2)
70-
expect({ key: 'accept', value: 'application/json, text/plain', object: headers }).to.deep.equal(results[0])
71-
expect({ key: 'content-type', value: 'text/html', object: headers }).to.deep.equal(results[1])
65+
assert.strictEqual(results.length, 2)
66+
assert.deepStrictEqual(results[0], { key: 'accept', value: 'application/json, text/plain', object: headers })
67+
assert.deepStrictEqual(results[1], { key: 'content-type', value: 'text/html', object: headers })
7268
})
7369

74-
xit('should set "this" to undefined by default on forEach', () => {
70+
it.skip('should set "this" to undefined by default on forEach', () => {
7571
const headers = new Headers({ Accept: 'application/json' })
7672
headers.forEach(function () {
77-
expect(this).to.be.undefined
73+
assert.strictEqual(this, undefined)
7874
})
7975
})
8076

8177
it('should accept thisArg as a second argument for forEach', () => {
8278
const headers = new Headers({ Accept: 'application/json' })
8379
const thisArg = {}
8480
headers.forEach(function () {
85-
expect(this).to.equal(thisArg)
81+
assert.strictEqual(this, thisArg)
8682
}, thisArg)
8783
})
8884

@@ -93,14 +89,14 @@ describe('Headers', () => {
9389
['a', '1']
9490
])
9591
headers.append('b', '3')
96-
expect(headers).to.be.iterable
92+
assert.strictEqual(typeof headers[Symbol.iterator], 'function')
9793

9894
const result = []
9995
for (const pair of headers) {
10096
result.push(pair)
10197
}
10298

103-
expect(result).to.deep.equal([
99+
assert.deepStrictEqual(result, [
104100
['a', '1'],
105101
['b', '2, 3'],
106102
['c', '4']
@@ -115,12 +111,22 @@ describe('Headers', () => {
115111
])
116112
headers.append('b', '3')
117113

118-
expect(headers.entries()).to.be.iterable
119-
.and.to.deep.iterate.over([
120-
['a', '1'],
121-
['b', '2, 3'],
122-
['c', '4']
123-
])
114+
assert.strictEqual(typeof headers.entries, 'function')
115+
assert.strictEqual(typeof headers.entries()[Symbol.iterator], 'function')
116+
117+
const entries = headers.entries()
118+
assert.strictEqual(typeof entries.next, 'function')
119+
assert.deepStrictEqual(entries.next().value, ['a', '1'])
120+
assert.strictEqual(typeof entries.next, 'function')
121+
assert.deepStrictEqual(entries.next().value, ['b', '2, 3'])
122+
assert.strictEqual(typeof entries.next, 'function')
123+
assert.deepStrictEqual(entries.next().value, ['c', '4'])
124+
125+
assert.deepStrictEqual([...headers.entries()], [
126+
['a', '1'],
127+
['b', '2, 3'],
128+
['c', '4']
129+
])
124130
})
125131

126132
it('should allow iterating through all headers with keys()', () => {
@@ -131,8 +137,18 @@ describe('Headers', () => {
131137
])
132138
headers.append('b', '3')
133139

134-
expect(headers.keys()).to.be.iterable
135-
.and.to.iterate.over(['a', 'b', 'c'])
140+
assert.strictEqual(typeof headers.keys, 'function')
141+
assert.strictEqual(typeof headers.keys()[Symbol.iterator], 'function')
142+
143+
const keys = headers.keys()
144+
assert.strictEqual(typeof keys.next, 'function')
145+
assert.strictEqual(keys.next().value, 'a')
146+
assert.strictEqual(typeof keys.next, 'function')
147+
assert.strictEqual(keys.next().value, 'b')
148+
assert.strictEqual(typeof keys.next, 'function')
149+
assert.strictEqual(keys.next().value, 'c')
150+
151+
assert.deepStrictEqual([...headers.keys()], ['a', 'b', 'c'])
136152
})
137153

138154
it('should allow iterating through all headers with values()', () => {
@@ -143,26 +159,37 @@ describe('Headers', () => {
143159
])
144160
headers.append('b', '3')
145161

146-
expect(headers.values()).to.be.iterable
147-
.and.to.iterate.over(['1', '2, 3', '4'])
162+
assert.strictEqual(typeof headers.values, 'function')
163+
assert.strictEqual(typeof headers.values()[Symbol.iterator], 'function')
164+
165+
const values = headers.values()
166+
assert.strictEqual(typeof values.next, 'function')
167+
assert.strictEqual(values.next().value, '1')
168+
assert.strictEqual(typeof values.next, 'function')
169+
assert.strictEqual(values.next().value, '2, 3')
170+
assert.strictEqual(typeof values.next, 'function')
171+
assert.strictEqual(values.next().value, '4')
172+
173+
assert.deepStrictEqual([...headers.values()], ['1', '2, 3', '4'])
148174
})
149175

150176
it('should reject illegal header', () => {
151177
const headers = new Headers()
152-
expect(() => new Headers({ 'He y': 'ok' })).to.throw(TypeError)
153-
expect(() => new Headers({ 'Hé-y': 'ok' })).to.throw(TypeError)
154-
expect(() => new Headers({ 'He-y': 'ăk' })).to.throw(TypeError)
155-
expect(() => headers.append('Hé-y', 'ok')).to.throw(TypeError)
156-
expect(() => headers.delete('Hé-y')).to.throw(TypeError)
157-
expect(() => headers.get('Hé-y')).to.throw(TypeError)
158-
expect(() => headers.has('Hé-y')).to.throw(TypeError)
159-
expect(() => headers.set('Hé-y', 'ok')).to.throw(TypeError)
178+
179+
assert.throws(() => new Headers({ 'He y': 'ok' }), TypeError)
180+
assert.throws(() => new Headers({ 'Hé-y': 'ok' }), TypeError)
181+
assert.throws(() => new Headers({ 'He-y': 'ăk' }), TypeError)
182+
assert.throws(() => headers.append('Hé-y', 'ok'), TypeError)
183+
assert.throws(() => headers.delete('Hé-y'), TypeError)
184+
assert.throws(() => headers.get('Hé-y'), TypeError)
185+
assert.throws(() => headers.has('Hé-y'), TypeError)
186+
assert.throws(() => headers.set('Hé-y', 'ok'), TypeError)
160187
// Should reject empty header
161-
expect(() => headers.append('', 'ok')).to.throw(TypeError)
188+
assert.throws(() => headers.append('', 'ok'), TypeError)
162189
})
163190

164-
xit('should ignore unsupported attributes while reading headers', () => {
165-
const FakeHeader = function () {}
191+
it.skip('should ignore unsupported attributes while reading headers', () => {
192+
const FakeHeader = function () { }
166193
// Prototypes are currently ignored
167194
// This might change in the future: #181
168195
FakeHeader.prototype.z = 'fake'
@@ -188,26 +215,26 @@ describe('Headers', () => {
188215

189216
const h1Raw = h1.raw()
190217

191-
expect(h1Raw.a).to.include('string')
192-
expect(h1Raw.b).to.include('1,2')
193-
expect(h1Raw.c).to.include('')
194-
expect(h1Raw.d).to.include('')
195-
expect(h1Raw.e).to.include('1')
196-
expect(h1Raw.f).to.include('1,2')
197-
expect(h1Raw.g).to.include('[object Object]')
198-
expect(h1Raw.h).to.include('undefined')
199-
expect(h1Raw.i).to.include('null')
200-
expect(h1Raw.j).to.include('NaN')
201-
expect(h1Raw.k).to.include('true')
202-
expect(h1Raw.l).to.include('false')
203-
expect(h1Raw.m).to.include('test')
204-
expect(h1Raw.n).to.include('1,2')
205-
expect(h1Raw.n).to.include('3,4')
206-
207-
expect(h1Raw.z).to.be.undefined
218+
assert.strictEqual(h1Raw.a.includes('string'), true)
219+
assert.strictEqual(h1Raw.b.includes('1,2'), true)
220+
assert.strictEqual(h1Raw.c.includes(''), true)
221+
assert.strictEqual(h1Raw.d.includes(''), true)
222+
assert.strictEqual(h1Raw.e.includes('1'), true)
223+
assert.strictEqual(h1Raw.f.includes('1,2'), true)
224+
assert.strictEqual(h1Raw.g.includes('[object Object]'), true)
225+
assert.strictEqual(h1Raw.h.includes('undefined'), true)
226+
assert.strictEqual(h1Raw.i.includes('null'), true)
227+
assert.strictEqual(h1Raw.j.includes('NaN'), true)
228+
assert.strictEqual(h1Raw.k.includes('true'), true)
229+
assert.strictEqual(h1Raw.l.includes('false'), true)
230+
assert.strictEqual(h1Raw.m.includes('test'), true)
231+
assert.strictEqual(h1Raw.n.includes('1,2'), true)
232+
assert.strictEqual(h1Raw.n.includes('3,4'), true)
233+
234+
assert.strictEqual(h1Raw.z, undefined)
208235
})
209236

210-
xit('should wrap headers', () => {
237+
it.skip('should wrap headers', () => {
211238
const h1 = new Headers({
212239
a: '1'
213240
})
@@ -221,16 +248,16 @@ describe('Headers', () => {
221248
h3.append('a', '2')
222249
const h3Raw = h3.raw()
223250

224-
expect(h1Raw.a).to.include('1')
225-
expect(h1Raw.a).to.not.include('2')
251+
assert.strictEqual(h1Raw.a.includes('1'), true)
252+
assert.strictEqual(h1Raw.a.includes('2'), false)
226253

227-
expect(h2Raw.a).to.include('1')
228-
expect(h2Raw.a).to.not.include('2')
229-
expect(h2Raw.b).to.include('1')
254+
assert.strictEqual(h2Raw.a.includes('1'), true)
255+
assert.strictEqual(h2Raw.a.includes('2'), false)
256+
assert.strictEqual(h2Raw.b.includes('1'), true)
230257

231-
expect(h3Raw.a).to.include('1')
232-
expect(h3Raw.a).to.include('2')
233-
expect(h3Raw.b).to.include('1')
258+
assert.strictEqual(h3Raw.a.includes('1'), true)
259+
assert.strictEqual(h3Raw.a.includes('2'), true)
260+
assert.strictEqual(h3Raw.b.includes('1'), true)
234261
})
235262

236263
it('should accept headers as an iterable of tuples', () => {
@@ -241,33 +268,33 @@ describe('Headers', () => {
241268
['b', '2'],
242269
['a', '3']
243270
])
244-
expect(headers.get('a')).to.equal('1, 3')
245-
expect(headers.get('b')).to.equal('2')
271+
assert.strictEqual(headers.get('a'), '1, 3')
272+
assert.strictEqual(headers.get('b'), '2')
246273

247274
headers = new Headers([
248275
new Set(['a', '1']),
249276
['b', '2'],
250277
new Map([['a', null], ['3', null]]).keys()
251278
])
252-
expect(headers.get('a')).to.equal('1, 3')
253-
expect(headers.get('b')).to.equal('2')
279+
assert.strictEqual(headers.get('a'), '1, 3')
280+
assert.strictEqual(headers.get('b'), '2')
254281

255282
headers = new Headers(new Map([
256283
['a', '1'],
257284
['b', '2']
258285
]))
259-
expect(headers.get('a')).to.equal('1')
260-
expect(headers.get('b')).to.equal('2')
286+
assert.strictEqual(headers.get('a'), '1')
287+
assert.strictEqual(headers.get('b'), '2')
261288
})
262289

263290
it('should throw a TypeError if non-tuple exists in a headers initializer', () => {
264-
expect(() => new Headers([['b', '2', 'huh?']])).to.throw(TypeError)
265-
expect(() => new Headers(['b2'])).to.throw(TypeError)
266-
expect(() => new Headers('b2')).to.throw(TypeError)
267-
expect(() => new Headers({ [Symbol.iterator]: 42 })).to.throw(TypeError)
291+
assert.throws(() => new Headers([['b', '2', 'huh?']]), TypeError)
292+
assert.throws(() => new Headers(['b2']), TypeError)
293+
assert.throws(() => new Headers('b2'), TypeError)
294+
assert.throws(() => new Headers({ [Symbol.iterator]: 42 }), TypeError)
268295
})
269296

270-
xit('should use a custom inspect function', () => {
297+
it.skip('should use a custom inspect function', () => {
271298
const headers = new Headers([
272299
['Host', 'thehost'],
273300
['Host', 'notthehost'],
@@ -277,6 +304,6 @@ describe('Headers', () => {
277304
])
278305

279306
// eslint-disable-next-line quotes
280-
expect(format(headers)).to.equal("{ a: [ '1', '3' ], b: '2', host: 'thehost' }")
307+
assert.strictEqual(format(headers), "{ a: [ '1', '3' ], b: '2', host: 'thehost' }")
281308
})
282309
})

0 commit comments

Comments
 (0)