NodeAdapter Memory Leaks indicated with jest --detectLeaks
antho1jp opened this issue · 0 comments
antho1jp commented
Description
This appears to be similar if not the same issue as 370.
Shareable Source
describe("Simple Example", function () {
it("fetches a post", async function () {
const polly = new Polly("Simple Example", {
adapters: [NodeAdapter], // Hook into `fetch`
persister: "fs",
logLevel: "info", // Log requests to console
mode: MODES.RECORD,
});
const response = await fetch(
"https://jsonplaceholder.typicode.com/posts/1"
);
const post: PostData = (await response.json()) as PostData;
expect(response.status).toBe(200);
expect(post.id).toBe(1);
await polly.stop();
});
});
Error Message & Stack Trace
FAIL tests/pollyjs.test.ts
● Test suite failed to run
EXPERIMENTAL FEATURE!
Your test suite is leaking memory. Please ensure all references are cleaned.
There is a number of things that can leak memory:
- Async operations that have not finished (e.g. fs.readFile).
- Timers not properly mocked (e.g. setInterval, setTimeout).
- Keeping references to the global scope.
at onResult (node_modules/@jest/core/build/TestScheduler.js:150:18)
at node_modules/@jest/core/build/TestScheduler.js:254:19
at node_modules/emittery/index.js:363:13
at Array.map (<anonymous>)
at Emittery.emit (node_modules/emittery/index.js:361:23)
Config
Copy the config used to setup the Polly instance:
const polly = new Polly("Simple Example", {
adapters: [NodeAdapter], // Hook into `fetch`
persister: "fs",
logLevel: "info", // Log requests to console
mode: MODES.RECORD,
});
Dependencies
Copy the @pollyjs dependencies from package.json
:
"devDependencies": {
"@pollyjs/adapter-node-http": "^6.0.5",
"@pollyjs/core": "^6.0.5",
"@pollyjs/persister-fs": "^6.0.5",
}
Relevant Links
Environment
Node.js v16.15.1
npm v8.11.0
darwin 22.1.0