如何使用 vscode 扩展测试生成覆盖率报告
我正在实现 VSCode 扩展。我按照此链接设置了项目。
它生成一个带有 src/test/runTest.ts
文件的入门项目:
import * as path from 'path';
import { runTests } from '@vscode/test-electron';
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, './suite/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();
以及 package.json
中的命令:
{
"compile": "tsc -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
}
有没有办法用它生成覆盖率报告?
I'm implementing a VSCode extension. I set up the project following this link.
It generates a starter project with a src/test/runTest.ts
file:
import * as path from 'path';
import { runTests } from '@vscode/test-electron';
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, './suite/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();
And a command in the package.json
:
{
"compile": "tsc -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
}
Is there a way to generate a coverage report with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
VSCODE扩展Unitesting使用 mocha> mocha 在引擎盖下。您可以使用许多可用框架之一,例如 c8 , jest , istanbul 等。
安装您选择的框架,在这里我使用
c8
,添加到脚本中
并根据您的扩展名 检查覆盖范围。在这里,我们正在检查
.js
文件放置在out/
dir下的文件,我们还排除了负责UniteSting IEOUT/TEST/TEST/
的文件(通常)。.c8rc
运行
coverage
脚本,您应该获得覆盖范围的输出使用上述工作回购: https://github.com/fortran-lang/vscode-fortran-support
VSCode extension unittesting uses Mocha under the hood. You can generate coverage reports like in any other Typescript/Javascript project using one of the many available frameworks, e.g. c8, jest, istanbul, etc.
Install the framework of your choice, here I use
c8
and add to scripts
Depending on your extension you might need to create a configuration file with the files you want to check for coverage. Here we are checking the compiled
.js
files placed under theout/
dir and we also excluding the files responsible for unittesting i.e.out/test/
(usually)..c8rc
Run the
coverage
script and you should get an output of your coverageA working repo making use of the above: https://github.com/fortran-lang/vscode-fortran-support
如果您使用 vscode-test-cli 现在,它是创建一个默认值通过
yo Code
的新扩展,这很容易。安装
@vscode/test-cli
的依赖项,如果尚未在项目中。然后,您可以使用以下命令生成覆盖范围。
注意:您的版本至少应为0.0.6。
您还可以使用
- Coverage-Output
(默认: os 的温度)和- coverage-reporter
(任何可能的Mocha Reporters)。这意味着,如果您想使用文本和HTML记者在覆盖范围目录中生成覆盖范围,则可以使用以下内容。
@vscode/test-CLI版本0.0.4
package.json
:npm Run Coverage <
: /代码>。就我而言,不需要其他配置。
If you are using vscode-test-cli, which is now the default when creating a new extension via
yo code
, it is very easy.Install the dependency of
@vscode/test-cli
, if not already in the project.Then you can generate the coverage with the following command.
Note: Your version should be at least 0.0.6.
You can also set the output directory of the coverage with
--coverage-output
(default: temp dir of OS) and--coverage-reporter
(any mocha reporters possible).That means if you want to generate the coverage in your coverage directory with text and html reporter, you can use the following.
old solution with @vscode/test-cli version 0.0.4
package.json
:npm run coverage
.In my case, additional configuration was not needed.