使用 ESM 时如何让伊斯坦布尔识别代码覆盖率?
问题描述:
我正在使用 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();
我使用 nyc mocha --delay --exit ./test/suite.js
运行这些测试,但是当我运行伊斯坦布尔时,它似乎无法识别我的导入并且无法提供覆盖信息...
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 | |
----------|----------|----------|----------|----------|-------------------|
我怎样才能让伊斯坦布尔识别 ESM 加载 代码?
How can I get Istanbul to recognize the ESM loaded code?
答
从 Mocha v7.1.0(2020 年 2 月)开始提供原生 ESM 支持.
Native ESM support is available from Mocha v7.1.0 (February 2020).
见: