使用 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();

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

在这里做错了什么??

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)