gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 05:58:17 26 4
gpt4 key购买 nike

为了生成 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com