- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个项目,我使用 webpack 进行开发/测试,并使用 karma 作为我的测试运行器。该项目的源文件一半用 js 编写,一半用 ts/tsx 编写。测试套件完全用 js 编写。我目前使用 karma-coverage,它显示我所有 js 源文件的覆盖率报告,但它不支持 typescript 文件。我所有的测试都运行,那里没有问题,我只想要我所有测试文件的覆盖率报告。谁能指出我正确的方向?
如果有帮助,这是我的 karma.conf.js。
'use strict';
const webpackCfg = require('./webpack.config')('test');
module.exports = function karmaConfig(config) {
config.set({
browsers: ['Chrome'],
files: [
'test/loadtests.js'
],
port: 8080,
captureTimeout: 60000,
frameworks: [
'mocha',
'chai',
'sinon'
],
client: {
mocha: {}
},
singleRun: true,
reporters: ['mocha', 'coverage', 'junit'],
mochaReporter: {
output: 'autowatch'
},
preprocessors: {
'test/loadtests.js': ['webpack', 'sourcemap']
},
webpack: webpackCfg,
webpackServer: {
noInfo: true
},
junitReporter: {
outputDir: 'coverage',
outputFile: 'junit-result.xml',
useBrowserName: false
},
coverageReporter: {
dir: 'coverage/',
watermarks: {
statements: [70, 80],
functions: [70, 80],
branches: [70, 80],
lines: [70, 80]
},
reporters: [
{ type: 'text' },
{
type: 'html',
subdir: 'html'
},
{
type: 'cobertura',
subdir: 'cobertura'
},
{
type: 'lcovonly',
subdir: 'lcov'
}
]
}
});
};
以及我的 webpack 测试配置的相关部分
{
devtool: 'inline-source-map',
externals: {
cheerio: 'window',
'react/lib/ExecutionEnvironment': true,
'react/addons': true,
'react/lib/ReactContext': true,
},
module: {
preLoaders: [
{
test: /\.(js|jsx)$/,
loader: 'isparta-loader',
include: [
this.srcPathAbsolute
]
}
],
loaders: [
{
test: /\.cssmodule\.css$/,
loaders: [
'style',
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]'
]
},
{
test: /^.((?!cssmodule).)*\.css$/,
loader: 'null-loader'
},
{
test: /\.(sass|scss|less|styl|png|jpg|gif|mp4|ogg|svg|woff|woff2)$/,
loader: 'null-loader'
},
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
loader: ['babel', 'ts-loader']
},
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
query: {
presets: ['airbnb']
},
include: [].concat(
this.includedPackages,
[
this.srcPathAbsolute,
this.testPathAbsolute
]
)
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"test"'
})
]
}
最佳答案
在数百个浏览器选项卡中进行了几天的灵魂和谷歌搜索后,我找到了一个可行的解决方案。这是使用 TypeScript 2.x 和 Webpack 2.x。 test.js
是我的切入点。它可以很容易地成为 test.ts
(最终会是)。在该入口点,我加载了我的 *.spec.js
和 *.spec.ts
文件。然后这些文件导入他们需要从中测试的任何来源。我已将所有 webpack 配置放在 karma.conf.js
中,以便更容易查看:
let myArgs = require('yargs').argv;
let path = require('path');
let webpack = require('webpack');
module.exports = function(config) {
const REPORTS_PATH = myArgs.reportsPath ? myArgs.reportsPath :path.join(__dirname, 'build');
config.set({
basePath: '',
frameworks: ['jasmine', 'es6-shim'],
files: [
'./test.js'
],
exclude: [],
reporters: ['progress', 'spec', 'coverage', 'junit', 'coverage-istanbul'],
preprocessors: {
'./test.js': ['webpack', 'sourcemap']
},
webpackServer: {
noInfo: true // prevent console spamming when running in Karma!
},
webpack: {
devtool: 'inline-source-map',
resolve: {
modules: [
path.resolve('./node_modules'),
path.resolve('./')
],
extensions: ['.js', '.ts', '.css', '.scss']
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
],
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
use: 'source-map-loader',
exclude: [/node_modules/]
},
{
test: /\.ts$/,
use: [{
loader: 'awesome-typescript-loader',
options: {
module: 'commonjs'
},
}]
},
{
test: /\.js$/,
use: [{
loader: 'awesome-typescript-loader',
options: {
entryFileIsJs: true,
transpileOnly: true
}
}],
exclude: [/node_modules/],
},
{
enforce: 'post',
test: /\.(js|ts)$/,
use: [{
loader: 'istanbul-instrumenter-loader',
options: {
esModules: true
}
}],
exclude: [/node_modules/, /\.spec\.(js|ts)$/, /test/]
},
{ test: /\.html/, use: 'raw-loader' },
{ test: /\.(s)?css$/, use: 'null-loader' },
{ test: /\.(png|jpg|jpeg|gif|svg|pdf)$/, use: 'null-loader' },
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'null-loader' },
{ test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'null-loader' },
{ test: /\.json$/, use: 'null-loader' }
]
}
},
coverageReporter: {
type: 'in-memory'
},
coverageIstanbulReporter: {
//TODO: Figure out why the 'html' reporter blows up with istanbul-reports (something with absolute path copying files)
reports: ['text-summary', 'cobertura'],
// base output directory
dir: REPORTS_PATH,
fixWebpackSourcePaths: true,
'report-config': {
cobertura: {
file: 'coverage.xml'
},
'text-summary': {
file: null
}
}
},
junitReporter: {
outputDir: `${REPORTS_PATH}/junit/`,
outputFile: 'jasmine-results.xml'
},
// Hide webpack build information from output
webpackMiddleware: {
stats: {
chunkModules: false,
colors: true
},
noInfo: 'errors-only'
},
colors: true,
logLevel: config.LOG_ERROR,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
autoWatchBatchDelay: 400
});
};
所以,这里的关键部分是 awesome-typescript-loader
、karma-coverage-istanbul-reporter
、source-map-loader
,并且在 tsconfig.json
中,您想在 compilerOptions
中设置这些:
"inlineSourceMap": true,
"sourceMap": false,
我指出了关于 html 报告的 TODO。它确实有效,但我无法将其输出到包含 TypeScript 文件的自定义目录(子目录)。 JavaScript 只能正常工作。可能是 istanbul-reports
的特定于 Windows 的问题。如果将 html
添加到 coverageIstanbulReporter
下的 reports
数组,您应该会在项目目录中看到它,但将它放入 中可能会遇到问题REPORTS_PATH
.
还值得注意的是,我很幸运地使用了 karma-remap-coverage
而不是 karma-coverage-istanbul-reporter
但前者无法正确生成cobertura 报道报道,这正是我对 Jenkins 所需要的。
关于javascript - 带有业力的覆盖率报告以及 javascript 和 typescript src 文件的混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40633826/
在旧版 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
我是一名优秀的程序员,十分优秀!