zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.71k stars 365 forks source link

Open promise handle reported by Jest (Closed: False positive) #319

Closed kallaspriit closed 6 years ago

kallaspriit commented 6 years ago

When using json2csv in my project alsongside with Jest, I'm getting the warning:

Jest did not exit one second after the test run has completed.

Running jest with --detectOpenHandles gives me:

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  PROMISE

       9 | } from "express-schema-server";
      10 | import { JSONSchema4 } from "json-schema";
    > 11 | import { Parser } from "json2csv";
         | ^
      12 | import moment from "moment";
      13 | import { AppContext } from "../../config";
      14 | import { Scope } from "../../constants";

          at Function.resolve (<anonymous>)
      at node_modules/json2csv/dist/json2csv.cjs.js:3126:32
      at createCommonjsModule (node_modules/json2csv/dist/json2csv.cjs.js:13:35)
      at Object.<anonymous> (node_modules/json2csv/dist/json2csv.cjs.js:1939:24)
      at Object.<anonymous> (src/routes/invoices/get-invoices.ts:11:1)

So it seems that the library creates some promise that does not get resolved/rejected so Jest continues to wait for it for a while and then quits. I tried removing the use of the library and the problem goes away.

The code I'm using:

import { Parser } from "json2csv";

const json2csvParser = new Parser<InvoiceInfo[]>({ fields: fieldNames });
const data = json2csvParser.parse(invoices);
juanjoDiaz commented 6 years ago

The line is (Promise && getTag(Promise.resolve()) != promiseTag).

I don't see how that is not resolving a promise.

Maybe your issue is related to https://github.com/facebook/jest/issues/6639 and all you need is to update jest?

juanjoDiaz commented 6 years ago

Also, just for the record, the line erroring is not json2csv's code but babel polyfills code.

kallaspriit commented 6 years ago

Ok, probably a false positive then. I'm using the latest jest@23.4.2.

juanjoDiaz commented 6 years ago

Closing this since we haven't heard about it for a while.

@kallaspriit it might be good for the next person getting here if you could share how you got rid of the error.