Skip to content

Commit 148e0ef

Browse files
authored
chore: remove tspl from fetch (#4570)
1 parent 3c93bd4 commit 148e0ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1117
-1209
lines changed

test/fetch/407-statuscode-window-null.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const { fetch } = require('../..')
44
const { createServer } = require('node:http')
55
const { once } = require('node:events')
66
const { test } = require('node:test')
7-
const assert = require('node:assert')
87

98
const { closeServerAsPromise } = require('../utils/node-http')
109

@@ -19,5 +18,5 @@ test('Receiving a 407 status code w/ a window option present should reject', asy
1918

2019
// if init.window exists, the spec tells us to set request.window to 'no-window',
2120
// which later causes the request to be rejected if the status code is 407
22-
await assert.rejects(fetch(`http://localhost:${server.address().port}`, { window: null }))
21+
await t.assert.rejects(fetch(`http://localhost:${server.address().port}`, { window: null }))
2322
})

test/fetch/abort.js

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

33
const { test } = require('node:test')
4-
const assert = require('node:assert')
5-
const { tspl } = require('@matteo.collina/tspl')
64
const { fetch } = require('../..')
75
const { createServer } = require('node:http')
86
const { once } = require('node:events')
@@ -15,20 +13,20 @@ test('allows aborting with custom errors', async (t) => {
1513
await once(server, 'listening')
1614

1715
await t.test('Using AbortSignal.timeout with cause', async (t) => {
18-
const { strictEqual } = tspl(t, { plan: 2 })
16+
t.plan(2)
1917
try {
2018
await fetch(`http://localhost:${server.address().port}`, {
2119
signal: AbortSignal.timeout(50)
2220
})
23-
assert.fail('should throw')
21+
t.assert.fail('should throw')
2422
} catch (err) {
2523
if (err.name === 'TypeError') {
2624
const cause = err.cause
27-
strictEqual(cause.name, 'HeadersTimeoutError')
28-
strictEqual(cause.code, 'UND_ERR_HEADERS_TIMEOUT')
25+
t.assert.strictEqual(cause.name, 'HeadersTimeoutError')
26+
t.assert.strictEqual(cause.code, 'UND_ERR_HEADERS_TIMEOUT')
2927
} else if (err.name === 'TimeoutError') {
30-
strictEqual(err.code, DOMException.TIMEOUT_ERR)
31-
strictEqual(err.cause, undefined)
28+
t.assert.strictEqual(err.code, DOMException.TIMEOUT_ERR)
29+
t.assert.strictEqual(err.cause, undefined)
3230
} else {
3331
throw err
3432
}
@@ -39,7 +37,7 @@ test('allows aborting with custom errors', async (t) => {
3937
const ac = new AbortController()
4038
ac.abort() // no reason
4139

42-
await assert.rejects(
40+
await t.assert.rejects(
4341
fetch(`http://localhost:${server.address().port}`, {
4442
signal: ac.signal
4543
}),

test/fetch/abort2.js

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

33
const { test } = require('node:test')
4-
const assert = require('node:assert')
54
const { fetch } = require('../..')
65
const { createServer } = require('node:http')
76
const { once } = require('node:events')
@@ -52,9 +51,9 @@ test('parallel fetch with the same AbortController works as expected', async (t)
5251
return a
5352
}, { resolved: [], rejected: [] })
5453

55-
assert.strictEqual(rejected.length, 9) // out of 10 requests, only 1 should succeed
56-
assert.strictEqual(resolved.length, 1)
54+
t.assert.strictEqual(rejected.length, 9) // out of 10 requests, only 1 should succeed
55+
t.assert.strictEqual(resolved.length, 1)
5756

58-
assert.ok(rejected.every(rej => rej.reason?.code === DOMException.ABORT_ERR))
59-
assert.deepStrictEqual(resolved[0].value, body)
57+
t.assert.ok(rejected.every(rej => rej.reason?.code === DOMException.ABORT_ERR))
58+
t.assert.deepStrictEqual(resolved[0].value, body)
6059
})

test/fetch/about-uri.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
'use strict'
22

33
const { test } = require('node:test')
4-
const assert = require('node:assert')
54
const { fetch } = require('../..')
65

76
test('fetching about: uris', async (t) => {
87
await t.test('about:blank', async () => {
9-
await assert.rejects(fetch('about:blank'))
8+
await t.assert.rejects(fetch('about:blank'))
109
})
1110

1211
await t.test('All other about: urls should return an error', async () => {
1312
try {
1413
await fetch('about:config')
15-
assert.fail('fetching about:config should fail')
14+
t.assert.fail('fetching about:config should fail')
1615
} catch (e) {
17-
assert.ok(e, 'this error was expected')
16+
t.assert.ok(e, 'this error was expected')
1817
}
1918
})
2019
})

test/fetch/blob-uri.js

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

33
const { test } = require('node:test')
4-
const assert = require('node:assert')
54
const { fetch } = require('../..')
65

76
test('fetching blob: uris', async (t) => {
@@ -19,19 +18,19 @@ test('fetching blob: uris', async (t) => {
1918
await t.test('a normal fetch request works', async () => {
2019
const res = await fetch(objectURL)
2120

22-
assert.strictEqual(blobContents, await res.text())
23-
assert.strictEqual(blob.type, res.headers.get('Content-Type'))
24-
assert.strictEqual(`${blob.size}`, res.headers.get('Content-Length'))
21+
t.assert.strictEqual(blobContents, await res.text())
22+
t.assert.strictEqual(blob.type, res.headers.get('Content-Type'))
23+
t.assert.strictEqual(`${blob.size}`, res.headers.get('Content-Length'))
2524
})
2625

2726
await t.test('non-GET method to blob: fails', async () => {
2827
try {
2928
await fetch(objectURL, {
3029
method: 'POST'
3130
})
32-
assert.fail('expected POST to blob: uri to fail')
31+
t.assert.fail('expected POST to blob: uri to fail')
3332
} catch (e) {
34-
assert.ok(e, 'Got the expected error')
33+
t.assert.ok(e, 'Got the expected error')
3534
}
3635
})
3736

@@ -41,36 +40,36 @@ test('fetching blob: uris', async (t) => {
4140

4241
try {
4342
await fetch(objectURL)
44-
assert.fail('expected revoked blob: url to fail')
43+
t.assert.fail('expected revoked blob: url to fail')
4544
} catch (e) {
46-
assert.ok(e, 'Got the expected error')
45+
t.assert.ok(e, 'Got the expected error')
4746
}
4847
})
4948

5049
// https://github.com/web-platform-tests/wpt/blob/7b0ebaccc62b566a1965396e5be7bb2bc06f841f/FileAPI/url/resources/fetch-tests.js#L28-L34
5150
await t.test('works with a fragment', async () => {
5251
const res = await fetch(objectURL + '#fragment')
5352

54-
assert.strictEqual(blobContents, await res.text())
53+
t.assert.strictEqual(blobContents, await res.text())
5554
})
5655

5756
// https://github.com/web-platform-tests/wpt/blob/7b0ebaccc62b566a1965396e5be7bb2bc06f841f/FileAPI/url/resources/fetch-tests.js#L52-L56
5857
await t.test('Appending a query string to blob: url should cause fetch to fail', async () => {
5958
try {
6059
await fetch(objectURL + '?querystring')
61-
assert.fail('expected ?querystring blob: url to fail')
60+
t.assert.fail('expected ?querystring blob: url to fail')
6261
} catch (e) {
63-
assert.ok(e, 'Got the expected error')
62+
t.assert.ok(e, 'Got the expected error')
6463
}
6564
})
6665

6766
// https://github.com/web-platform-tests/wpt/blob/7b0ebaccc62b566a1965396e5be7bb2bc06f841f/FileAPI/url/resources/fetch-tests.js#L58-L62
6867
await t.test('Appending a path should cause fetch to fail', async () => {
6968
try {
7069
await fetch(objectURL + '/path')
71-
assert.fail('expected /path blob: url to fail')
70+
t.assert.fail('expected /path blob: url to fail')
7271
} catch (e) {
73-
assert.ok(e, 'Got the expected error')
72+
t.assert.ok(e, 'Got the expected error')
7473
}
7574
})
7675

@@ -79,9 +78,9 @@ test('fetching blob: uris', async (t) => {
7978
for (const method of ['HEAD', 'POST', 'DELETE', 'OPTIONS', 'PUT', 'CUSTOM']) {
8079
try {
8180
await fetch(objectURL, { method })
82-
assert.fail(`${method} fetch should have failed`)
81+
t.assert.fail(`${method} fetch should have failed`)
8382
} catch (e) {
84-
assert.ok(e, `${method} blob url - test succeeded`)
83+
t.assert.ok(e, `${method} blob url - test succeeded`)
8584
}
8685
}
8786
})

test/fetch/bundle.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
'use strict'
22

33
const { test } = require('node:test')
4-
const assert = require('node:assert')
54

65
const { Response, Request, FormData, Headers, MessageEvent, CloseEvent, ErrorEvent } = require('../../undici-fetch')
76

8-
test('bundle sets constructor.name and .name properly', () => {
9-
assert.strictEqual(new Response().constructor.name, 'Response')
10-
assert.strictEqual(Response.name, 'Response')
7+
test('bundle sets constructor.name and .name properly', (t) => {
8+
t.assert.strictEqual(new Response().constructor.name, 'Response')
9+
t.assert.strictEqual(Response.name, 'Response')
1110

12-
assert.strictEqual(new Request('http://a').constructor.name, 'Request')
13-
assert.strictEqual(Request.name, 'Request')
11+
t.assert.strictEqual(new Request('http://a').constructor.name, 'Request')
12+
t.assert.strictEqual(Request.name, 'Request')
1413

15-
assert.strictEqual(new Headers().constructor.name, 'Headers')
16-
assert.strictEqual(Headers.name, 'Headers')
14+
t.assert.strictEqual(new Headers().constructor.name, 'Headers')
15+
t.assert.strictEqual(Headers.name, 'Headers')
1716

18-
assert.strictEqual(new FormData().constructor.name, 'FormData')
19-
assert.strictEqual(FormData.name, 'FormData')
17+
t.assert.strictEqual(new FormData().constructor.name, 'FormData')
18+
t.assert.strictEqual(FormData.name, 'FormData')
2019
})
2120

22-
test('regression test for https://github.com/nodejs/node/issues/50263', () => {
21+
test('regression test for https://github.com/nodejs/node/issues/50263', (t) => {
2322
const request = new Request('https://a', {
2423
headers: {
2524
test: 'abc'
@@ -29,11 +28,11 @@ test('regression test for https://github.com/nodejs/node/issues/50263', () => {
2928

3029
const request1 = new Request(request, { body: 'does not matter' })
3130

32-
assert.strictEqual(request1.headers.get('test'), 'abc')
31+
t.assert.strictEqual(request1.headers.get('test'), 'abc')
3332
})
3433

3534
test('WebSocket related events are exported', (t) => {
36-
assert.deepStrictEqual(typeof CloseEvent, 'function')
37-
assert.deepStrictEqual(typeof MessageEvent, 'function')
38-
assert.deepStrictEqual(typeof ErrorEvent, 'function')
35+
t.assert.deepStrictEqual(typeof CloseEvent, 'function')
36+
t.assert.deepStrictEqual(typeof MessageEvent, 'function')
37+
t.assert.deepStrictEqual(typeof ErrorEvent, 'function')
3938
})
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const { test } = require('node:test')
4-
const assert = require('node:assert')
54
const { sep } = require('node:path')
65
const { fetch, setGlobalDispatcher, Agent } = require('../..')
76
const { fetch: fetchIndex } = require('../../index-fetch')
@@ -16,10 +15,10 @@ test('FETCH: request errors and prints trimmed stack trace', async (t) => {
1615
await fetch('http://a.com')
1716
} catch (error) {
1817
const stackLines = error.stack.split('\n')
19-
assert.ok(stackLines[0].includes('TypeError: fetch failed'))
20-
assert.ok(stackLines[1].includes(`undici${sep}index.js`))
21-
assert.ok(stackLines[2].includes('at process.processTicksAndRejections'))
22-
assert.ok(stackLines[3].includes(`at async TestContext.<anonymous> (${__filename}`))
18+
t.assert.ok(stackLines[0].includes('TypeError: fetch failed'))
19+
t.assert.ok(stackLines[1].includes(`undici${sep}index.js`))
20+
t.assert.ok(stackLines[2].includes('at process.processTicksAndRejections'))
21+
t.assert.ok(stackLines[3].includes(`at async TestContext.<anonymous> (${__filename}`))
2322
}
2423
})
2524

@@ -28,9 +27,9 @@ test('FETCH-index: request errors and prints trimmed stack trace', async (t) =>
2827
await fetchIndex('http://a.com')
2928
} catch (error) {
3029
const stackLines = error.stack.split('\n')
31-
assert.ok(stackLines[0].includes('TypeError: fetch failed'))
32-
assert.ok(stackLines[1].includes(`undici${sep}index-fetch.js`))
33-
assert.ok(stackLines[2].includes('at process.processTicksAndRejections'))
34-
assert.ok(stackLines[3].includes(`at async TestContext.<anonymous> (${__filename}`))
30+
t.assert.ok(stackLines[0].includes('TypeError: fetch failed'))
31+
t.assert.ok(stackLines[1].includes(`undici${sep}index-fetch.js`))
32+
t.assert.ok(stackLines[2].includes('at process.processTicksAndRejections'))
33+
t.assert.ok(stackLines[3].includes(`at async TestContext.<anonymous> (${__filename}`))
3534
}
3635
})

0 commit comments

Comments
 (0)