微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 nyc

如何解决使用 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 举报,一经查实,本站将立刻删除。