Skip to content

Commit a7439d6

Browse files
committed
chore: pass signal and timeout correctly in tests
1 parent 2222010 commit a7439d6

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

packages/utils/src/internals/robots.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ export class RobotsTxtFile {
6565
): Promise<RobotsTxtFile> {
6666
const { proxyUrl, httpClient = new FetchHttpClient() } = options || {};
6767

68-
const response = await httpClient.sendRequest(new Request(url, { method: 'GET', signal: options?.signal }), {
68+
const response = await httpClient.sendRequest(new Request(url, { method: 'GET' }), {
6969
proxyUrl,
7070
timeoutMillis: options?.timeoutMillis,
71+
signal: options?.signal,
7172
});
7273

7374
if (response.status < 200 || response.status >= 300) {

packages/utils/src/internals/sitemap.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,11 @@ export async function* discoverValidSitemaps(
536536
return false;
537537
}
538538
try {
539-
const response = await httpClient.sendRequest(new Request(url, { method: 'HEAD' }), { proxyUrl });
539+
const response = await httpClient.sendRequest(new Request(url, { method: 'HEAD' }), {
540+
proxyUrl,
541+
timeoutMillis: requestTimeoutMillis,
542+
signal,
543+
});
540544
return response.status >= 200 && response.status < 400;
541545
} catch {
542546
return false;

packages/utils/test/robots.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('RobotsTxtFile', () => {
6363

6464
it('respects user-set timeout', async () => {
6565
const start = +Date.now();
66-
const robots = RobotsTxtFile.find('http://not-exists.com/robots.txt', undefined, { timeoutMillis: 200 });
66+
const robots = RobotsTxtFile.find('http://not-exists.com/robots.txt', { timeoutMillis: 200 });
6767

6868
await expect(robots).rejects.toThrow(/timeout/i);
6969
const end = +Date.now();
@@ -77,7 +77,7 @@ describe('RobotsTxtFile', () => {
7777
setTimeout(() => controller.abort(), 200);
7878

7979
const start = +Date.now();
80-
const robots = RobotsTxtFile.find('http://not-exists.com/robots.txt', undefined, { signal: controller.signal });
80+
const robots = RobotsTxtFile.find('http://not-exists.com/robots.txt', { signal: controller.signal });
8181

8282
await expect(robots).rejects.toThrow(/aborted/i);
8383
const end = +Date.now();
@@ -90,7 +90,7 @@ describe('RobotsTxtFile', () => {
9090
const controller = new AbortController();
9191

9292
const start = +Date.now();
93-
const robots = RobotsTxtFile.find('http://not-exists.com/robots.txt', undefined, {
93+
const robots = RobotsTxtFile.find('http://not-exists.com/robots.txt', {
9494
signal: controller.signal,
9595
timeoutMillis: 200,
9696
});

0 commit comments

Comments
 (0)