-
-
Notifications
You must be signed in to change notification settings - Fork 759
Expand file tree
/
Copy pathclient-error-stack-trace.js
More file actions
36 lines (32 loc) · 1.29 KB
/
client-error-stack-trace.js
File metadata and controls
36 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict'
const { test } = require('node:test')
const assert = require('node:assert')
const { sep } = require('node:path')
const { fetch, setGlobalDispatcher, Agent } = require('../..')
const { fetch: fetchIndex } = require('../../index-fetch')
setGlobalDispatcher(new Agent({
headersTimeout: 500,
connectTimeout: 500
}))
test('FETCH: request errors and prints trimmed stack trace', async (t) => {
try {
await fetch('http://a.com')
} catch (error) {
const stackLines = error.stack.split('\n')
assert.ok(stackLines[0].includes('TypeError: fetch failed'))
assert.ok(stackLines[1].includes(`undici${sep}index.js`))
assert.ok(stackLines[2].includes('at process.processTicksAndRejections'))
assert.ok(stackLines[3].includes(`at async TestContext.<anonymous> (${__filename}`))
}
})
test('FETCH-index: request errors and prints trimmed stack trace', async (t) => {
try {
await fetchIndex('http://a.com')
} catch (error) {
const stackLines = error.stack.split('\n')
assert.ok(stackLines[0].includes('TypeError: fetch failed'))
assert.ok(stackLines[1].includes(`undici${sep}index-fetch.js`))
assert.ok(stackLines[2].includes('at process.processTicksAndRejections'))
assert.ok(stackLines[3].includes(`at async TestContext.<anonymous> (${__filename}`))
}
})