node.js - 没有为使用 nyc 的 vscode 扩展生成覆盖信息

标签 node.js typescript visual-studio-code code-coverage nyc

为了生成 vscode 扩展的代码覆盖率报告,我使用 nyc 并通过 vscode 测试运行器运行它们。

来源:https://code.visualstudio.com/api/working-with-extensions/testing-extension

项目结构:

out
    -test
         -unit
              -testcases.js
              -index.js
    - runTest.js

``

   "test": "rm -rf .nyc_output/ && nyc node ./out/test/runTest.js",

   "nyc": {
        "extends": "@istanbuljs/nyc-config-typescript",
        "require": [
        "ts-node/register",
        "source-map-support/register"
        ],
       "report-dir": ".",
       "reporter": [
       "text",
       "html",
       "lcov"
      ],
      "exclude": ["out/test/**"],
       "include": [ "out/**/*.js" ],
      "check-coverage": true
       },

index.ts 文件:

import * as path from 'path';
import * as Mocha from 'mocha';
import * as glob from 'glob';

export function run(): Promise<void> {
 const mocha = new Mocha({
ui: 'tdd',
color: true,
timeout: 20000,});

 const testsRoot = path.resolve(__dirname, '../unit');

 return new Promise((c, e) => {

glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
  if (err) {
    return e(err);
  }

  // Add files to the test suite
  files.forEach(f => {
    mocha.addFile(path.resolve(testsRoot, f));
  });

  try {
    // Run the mocha test
    mocha.run(failures => {
      if (failures > 0) {
        e(new Error(`${failures} tests failed.`));
      } else {
        c();
      }
    });
  } catch (err) {
    // eslint-disable-next-line no-console
    console.error(err);
    e(err);
  }
 });
});
}

runTest.ts 文件:

import * as path from 'path';

import { runTests } from 'vscode-test';

async function main() {
 try {
    // The folder containing the Extension Manifest package.json
    // Passed to `--extensionDevelopmentPath`
    const extensionDevelopmentPath = path.resolve(__dirname, '../../');

    // The path to test runner
    // Passed to --extensionTestsPath
    //const extensionTestsPath = path.resolve(__dirname, './unit/index-coverage');
    const extensionTestsPath = path.resolve(__dirname, './unit/index');

    // Download VS Code, unzip it and run the integration test
    await runTests({ extensionDevelopmentPath, extensionTestsPath });
 } catch (err) {
    //console.error('Failed to run tests');
    process.exit(1);
 }
}

main();

我无法生成代码覆盖率报告。它生成报告但没有任何信息。

我在这里做错了什么??

最佳答案

有几种方法可以做到这一点。我在查看以下链接时发现了一些有值(value)的信息: How do a generate vscode TypeScript extension coverage report

似乎最简单的一个来自用户frenya。但另外两个也提供了有值(value)的信息。

关于node.js - 没有为使用 nyc 的 vscode 扩展生成覆盖信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68557701/

相关文章:

typescript - 如何将已知的接口(interface)属性与自定义索引签名相结合?

ruby - VScode 上的 rubocop 不起作用。错误 "rubocop is not executable"

ruby-on-rails - 如何从 Visual Studio Code 运行和调试 Ruby on Rails?

javascript - 错误 : Failed to initialize react-native-reanimated library

javascript - 带有 node.js 中数据的 POST 请求

node.js - 如何模拟来自 http.request 的响应(nodejs、jasmine、sinon)

node.js - 如何只返回一部分数据?

c# - 来自 IActionResult 的打字机 ReturnType

javascript - 为什么在javascript中出现未处理的 'error'事件

javascript - 创建 Q Promise 并稍后调用它