Skip to content
Myr

memory-leak.ts

This file

Path

test/memory-leak.ts

52 lines · 1.4 KiB · TypeScript

Last changed by

Add `NetworkError` class and tighten retry logic (#842)Sindre Sorhusbefore adoptioneaf0b80

History of this file

Take it

The walk stopped after 200 commits: lines older than 37fc250 point at it.

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 1–3why, one step back
1import {ReadableStream} from 'node:stream/web';
2import test from 'ava';3import LeakDetector from 'jest-leak-detector';

Add `NetworkError` class and tighten retry logic (#842)Sindre Sorhusbefore adoptioneaf0b80

line 4why, one step back
4import ky, {NetworkError, type KyInstance} from '../source/index.js';

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 5–7why, one step back
5import {createHttpTestServer} from './helpers/create-http-test-server.js';
67test('shared abort signal must not cause memory leak of input', async t => {

Simplify testsSindre Sorhusbefore adoptiondfa3f59

line 8why, one step back
8 const server = await createHttpTestServer(t);

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 9–13why, one step back
9 server.get('/', (_request, response) => {
10 response.end('ok');11 });1213 async function isKyLeaking(api: KyInstance) {

Require Node.js 22Sindre Sorhusbefore adoptionf1da0fc

line 14why, one step back
14 let url: URL | undefined = new URL(`${server.url.toString()}?id=${Math.random()}`);

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 15–43why, one step back
15 const detector = new LeakDetector(url);
1617 await api.get(url);1819 url = undefined;2021 return detector.isLeaking();22 }2324 const abortController = new AbortController();2526 try {27 t.false(await isKyLeaking(ky.extend({})));28 t.false(await isKyLeaking(ky.extend({signal: abortController.signal})));29 } finally {30 abortController.abort();31 }32});3334test('failed stream request must not cause memory leak', async t => {35 async function isStreamLeaking() {36 const stream: ReadableStream | undefined = ReadableStream.from([new TextEncoder().encode('Bell is Ringing.')]);37 const detector = new LeakDetector(stream);3839 await t.throwsAsync(40 ky.post('invalid:', {41 body: stream,42 }),43 {

Add `NetworkError` class and tighten retry logic (#842)Sindre Sorhusbefore adoptioneaf0b80

line 44why, one step back
44 instanceOf: NetworkError,

Add retry count to `afterResponse` and `beforeError` hooks (#763)Sindre Sorhusbefore adoption37fc250

lines 45–52why, one step back
45 },
46 );4748 return detector.isLeaking();49 }5051 t.false(await isStreamLeaking());52});