winstonjs/winston

jest is detecting memory leaks when creating a logger with a `File` transport

Open

#1445 opened on Aug 22, 2018

View on GitHub
 (12 comments) (0 reactions) (0 assignees)JavaScript (21,967 stars) (1,789 forks)batch import
Help WantedNeeds Investigation

Description

Please tell us about your environment:

  • _winston version? winston@3
  • _node -v outputs: v10.9.0
  • _Operating System? macOS 10.13.6
  • _Language? Typescript 3.0.1

What is the problem?

Jest --detectLeaks (experimental flag) is reporting that winston is leaking when using the File transport.

import winston from "winston";

describe("winston", () => {
    it(`should not leak memory with a file transport`, async () => {
        const logger = winston.createLogger({
            transports: [
                new winston.transports.File({
                    filename: "logs/error.log",
                    level: "error"
                })
            ]
        });
        logger.close();
        expect(logger).toBeTruthy();
    });
});
jest --detectLeaks
 FAIL  ./file-transport.spec.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).
init
      - Timers not properly mocked (e.g. setInterval, setTimeout).
      - Keeping references to the global scope.

      at node_modules/jest-cli/build/TestScheduler.js:275:22

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.654s

Other information

Can be reproduced on this repository: https://github.com/shusson/winston-leak

Contributor guide