- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试使用 Istanbul 在 karma 框架中获取我的 typescript 代码的代码覆盖率在 karma.conf 中包含 typescript 文件,通过 karma typescript-preprocessor,我们能够对 typescript 代码进行单元测试和代码覆盖,但是代码覆盖率报告用于转码的 JavaScript 代码
如何获取 typescript 代码的覆盖率报告?
这是我的 karma.conf
文件。
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['jasmine'],
preprocessors: {
'src/**/*.ts': ['typescript', 'coverage'],
'test/**/*.ts': ['typescript']
},
typescriptPreprocessor: {
options: {
sourceMap: false, // (optional) Generates corresponding .map file.
target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
module: 'amd', // (optional) Specify module code generation: 'commonjs' or 'amd'
noImplicitAny: true, // (optional) Warn on expressions and declarations with an implied 'any' type.
noResolve: false, // (optional) Skip resolution and preprocessing.
removeComments: true, // (optional) Do not emit comments to output.
concatenateOutput: false // (optional) Concatenate and emit output to single file. By default true if module option is omited, otherwise false.
},
// extra typing definitions to pass to the compiler (globs allowed)
// transforming the filenames
transformPath: function (path) {
return path.replace(/\.ts$/, '.js');
}
//options: {
// sourceMap: true,
//}
},
// list of files / patterns to load in the browser
files: [
'src/**/*.ts',
'test/**/*.ts'
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress','coverage'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['PhantomJS'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
plugins: [
'karma-jasmine',
'karma-chrome-launcher',
'karma-phantomjs-launcher',
'karma-typescript-preprocessor',
'karma-coverage'
//require('../../../node_modules/karma-typescript-preprocessor/index.js')
]
});
};
最佳答案
安装 karma-typescript
:
npm install karma-typescript --save-dev
将其放入您的 karma.conf.js 中:
frameworks: ["jasmine", "karma-typescript"],
files: [
{ pattern: "src/**/*.ts" }
],
preprocessors: {
"**/*.ts": ["karma-typescript"]
},
reporters: ["progress", "karma-typescript"],
browsers: ["Chrome"]
这将即时运行您的 Typescript 单元测试并生成如下所示的 Istanbul html 覆盖范围:
要运行上面的例子,你需要安装一些包:
npm install @types/jasmine jasmine-core karma karma-chrome-launcher karma-cli karma-jasmine karma-typescript typescript
这是单元测试 vanilla Typescript 代码的完整配置,在这种情况下不需要 tsconfig.json
。对于 Angular、React 等更复杂的设置,您可以在 examples folder
中找到示例在integration tests
.
关于typescript - 使用 karma-jasmine 和 istanbul 的 Typescript 代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38764929/
在旧版 Web 应用程序中,我们没有对 javascript 部分进行任何单元测试。 我们希望提高代码质量并删除死代码。 有什么方法可以在人工测试期间在浏览器中进行逐行 Javascript 代码覆盖
我已经为我的 python 代码编写了测试,并且想检查测试覆盖了多少百分比,所以我决定使用 python 覆盖。但是我启动它时遇到问题。我用这个 bash 命令启动我的测试: export PYTHO
我正在使用 python 覆盖工具来运行我的单元测试。从结果中可以看出,它包括所有“站点包”。我怎样才能将它们排除在报告之外?我只想显示项目源代码的报告。 (ctrp) ubuntu@ubuntu-x
我正在尝试使用 Opencover 来运行 NUnit 测试用例的代码覆盖率。我得到了预期的结果,但问题是在执行 opencover 时它再次运行测试。我们不希望发生这种情况,因为我们单独运行测试。下
我正在尝试使用 Opencover 来运行 NUnit 测试用例的代码覆盖率。我得到了预期的结果,但问题是在执行 opencover 时它再次运行测试。我们不希望发生这种情况,因为我们单独运行测试。下
我有一个 python 项目,我使用: pipenv 毒性 pytest 还有更多。 基本上,我想将 tox 添加到我的 gitlab 管道中。几乎一切似乎都有效,从 tox 调用 mypy、flak
我使用Coverity来分析代码C。 配置命令: cov-configure --compiler /opt/toolchains/stbgcc-4.5.4-2.9/bin/mipsel-linux-
是否可以在运行时测量 python 代码覆盖率并在生成结果时查看结果?我尝试使用 coverage但找不到有帮助的选项。我最初的实验表明,.coverage 文件直到程序执行结束才被保存,这意味着我们
我有一个文件,test_basic.py: class TestCalculator(): def test_calculator(self): from basic impo
我有一个小型 PHP 项目,它使用 PHPUnit 进行单元测试和覆盖。我想生成 cobertura XML 格式的覆盖率报告。 我可以使用任何工具或插件来实现这一目标吗? 感谢任何帮助.. 最佳答案
我正在研究一个小 gem 并包含 simplecov到 spec_helper.rb 两行: require 'simplecov' SimpleCov.start 当我运行 rspec 测试时,si
go -cover 或 -coverprofile 在运行 go 测试时非常有用,并且可以在 html 或纯文本中很好地显示。但是是否有 api 以编程方式访问它或处理文件? 最佳答案 你可以试试ax
当我遇到代码覆盖问题时,我目前开始在 PHPUnit 中使用 strict 模式: 如果我使用setUp-方法创建我的类的新实例,__constructor-方法在我运行测试。 这是我的测试设置: p
我正在运行 EclEmma,它是 Eclipse 的 Emma 插件,覆盖率报告仅显示我定义的 Enum 的部分覆盖率,即使它显示 Enum 中唯一的值被覆盖。我假设支持 Enum 的隐含方法存在覆盖
我正在将 ANT 构建转换为 Maven。我不使用声纳。 在 Maven 中,Jacoco 似乎没有报告有关单元测试本身的覆盖率,而 ANT 则报告了。我也一直在尝试为我的 Maven 构建获取这个,
我正在努力为我正在处理的库实现 100% 的代码覆盖率,但我似乎对 switch 语句和覆盖率有一些问题,我根本不明白。 我目前使用的是 Jacoco 0.7.2,因为每个新版本似乎都与 Robole
有没有在intelliJ中不用浏览器运行代码覆盖率的方法? http://www.jetbrains.com/webstorm/webhelp/monitoring-code-coverage-for
我想确保我的 Django 测试套件涵盖我的 URL 配置中列出的所有 URL。有没有办法将 URL 配置中的列表与测试套件中命中的 URL 列表进行比较? 最佳答案 我能够通过定义自定义测试套件运行
哇,好乱啊。这是场景。 主干驱动的 JS 应用。 用于 AMD 功能的 RequireJS,初始化如下: 然后在 main.js 中添加以下配置代码: require.config( { p
我的问题很简单,但答案仍然难以捉摸。假设我有一个包裹 package mypackage func DoTheThing() int { return 5 } 现在假设我在 mypackage_t
我是一名优秀的程序员,十分优秀!