使用ESM时,如何使Istanbul识别代码覆盖率?

JGl*_*son 5 mocha.js ecma istanbul es6-module-loader

我正在使用ESM进行模块加载,然后像这样运行它们...

// 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();
Run Code Online (Sandbox Code Playgroud)

然后我像这样运行这些测试nyc mocha --delay --exit ./test/suite.js。但是当我运行Istanbul时,似乎无法识别我的进口货,因此无法提供承保范围信息...

  3 passing (14ms)

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|
Run Code Online (Sandbox Code Playgroud)

我如何才能使Istanbul识别ESM加载的代码?

lif*_*foo 0

Mocha v7.1.0(2020 年 2 月)提供本机 ESM 支持。

看: