winstonjs/winston

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

Open

#1445 aperta il 22 ago 2018

Vedi su GitHub
 (12 commenti) (0 reazioni) (0 assegnatari)JavaScript (1789 fork)batch import
Help WantedNeeds Investigation

Metriche repository

Star
 (21.967 star)
Metriche merge PR
 (Merge medio 68g 4h) (9 PR mergiate in 30 g)

Descrizione

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

Guida contributor