【问题标题】:No coverage information is generated for vscode extension using nyc没有使用 nyc 为 vscode 扩展生成覆盖信息
【发布时间】:2021-07-28 09:22:48
【问题描述】:

为了生成 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();

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

我在这里做错了什么??

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-11-26
      • 2019-10-11
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-29
      相关资源
      最近更新 更多