JGleason
JGleason

Reputation: 3946

How do I get Istanbul to recognize code coverage when using ESM?

I'm using ESM to loading my modules and I use them in this way:

// More info on why this is needed see (https://github.com/mochajs/mocha/issues/3006)
async function wire(){
    await import("./Sanity.spec.mjs"); 
    await import("./Other.spec.mjs");
    run();
}
wire();

I run these tests using nyc mocha --delay --exit ./test/suite.js, but when I run Istanbul it does not seems to recognize my imports and fails to provide coverage information...

  3 passing (14ms)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|

How can I get Istanbul to recognize the ESM loaded code?

Upvotes: 10

Views: 745

Answers (1)

lifeisfoo
lifeisfoo

Reputation: 16334

Native ESM support is available from Mocha v7.1.0 (February 2020).

See:

Upvotes: 0

Related Questions