Skip to content

Commit 79674d3

Browse files
committed
Make fetch-dependent tests resilient to generic FetchErrors
1 parent a09d294 commit 79674d3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

test/test-utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ export function nodeOnly(body: Function) {
9898
}
9999

100100
// Wrap a test promise that might fail due to irrelevant remote network issues, and it'll skip the test
101-
// if there's a timeout or 502 response (but still throw any other errors). This allows us to write tests
102-
// that will fail if a remote server explicitly rejects something, but make them resilient to the remote
103-
// server simply being entirely unavailable.
101+
// if there's a timeout, connection error or 502 response (but still throw any other errors). This allows
102+
// us to write tests that will fail if a remote server explicitly rejects something, but make them
103+
// resilient to the remote server simply being entirely unavailable.
104104
export async function ignoreNetworkError<T extends RequestPromise | Promise<Response>>(request: T, options: {
105105
context: Mocha.Context,
106106
timeout?: number
@@ -112,7 +112,7 @@ export async function ignoreNetworkError<T extends RequestPromise | Promise<Resp
112112
delay(options.timeout ?? 1000).then(() => { throw TimeoutError; })
113113
]).catch(error => {
114114
console.log(error);
115-
if (error === TimeoutError) {
115+
if (error === TimeoutError || error.name === 'FetchError') {
116116
console.warn(`Skipping test due to network error: ${error.message || error}`);
117117
if ('abort' in request) request.abort();
118118
throw options.context.skip();

0 commit comments

Comments
 (0)