Skip to content

Commit 657a725

Browse files
jeff-zuckerclaude
andcommitted
test: stop sol-login node test hitting the real network
'routes remote URLs through fetchFor' called auth.fetch on a real https://example.com URL. With no session, fetchFor returns the real globalThis.fetch, so the test made a live request — undici's keep-alive socket then lingered past test end, so jest force-exited the worker ("failed to exit gracefully"), intermittently marking the suite failed. Stub globalThis.fetch for the test instead; it still verifies remote URLs route via fetchFor rather than _localFetch. Full suite is now stable across repeated runs. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent d956e17 commit 657a725

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

tests/node/sol-login.test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,20 @@ describe('fetch', () => {
413413
});
414414

415415
test('routes remote URLs through fetchFor', async () => {
416-
const auth = new SolidAuth({ tokenStore: null });
417-
const resp = await auth.fetch('https://example.com');
418-
expect(resp.status).toBeDefined();
416+
// Stub globalThis.fetch so this stays a unit test — a real request to
417+
// example.com leaves an undici keep-alive socket open, which prevents
418+
// the jest worker from exiting gracefully.
419+
const realFetch = globalThis.fetch;
420+
let calledWith = null;
421+
globalThis.fetch = async (u, init) => { calledWith = u; return { status: 200 }; };
422+
try {
423+
const auth = new SolidAuth({ tokenStore: null });
424+
const resp = await auth.fetch('https://example.com');
425+
expect(calledWith).toBe('https://example.com'); // went via fetchFor, not _localFetch
426+
expect(resp.status).toBe(200);
427+
} finally {
428+
globalThis.fetch = realFetch;
429+
}
419430
});
420431
});
421432

0 commit comments

Comments
 (0)