我无法让伊斯坦布尔与茉莉花合作:
这是我的目录结构
ttm-jira
- package.json
- spec
- jira-spec.js
Run Code Online (Sandbox Code Playgroud)
我的package.json看起来像这样:
{
"name": "ttm-jira",
"version": "1.0.0",
"description": "nodeJS module to provide access to the JIRA REST API",
"author": {
"name": "...",
"url" : "...."
},
"main": "jira.js",
"private": true,
"repository": {
"type": "git",
"url" : "https://........git"
},
"bugs": {
"url" : "https://jira2........."
},
"scripts": {
"test" : "npm run code-coverage && npm run unit-test",
"unit-test" : "jasmine-node . --autotest --captureExceptions --watch",
"code-coverage": "istanbul cover --include-all-sources"
},
"devDependencies": {
"istanbul" : "^0.4.0", …Run Code Online (Sandbox Code Playgroud) 我在https://github.com/danielbush/webpack-babel-karma-sourcemap-coverage有一个测试项目。
\n\n它由两个简单的源文件组成src/,其中一个有一个故意错误(src/lib2.js )。
我想使用 babel 进行 webpack 和从 ES6 到 ES5 的转译,并使用 Karma 在此包上运行 Mocha 测试。
\n\n我已经添加了源映射并对此进行了测试,以便我可以看到原始文件的行号。
\n\n对我来说,堆栈跟踪如下所示:
\n\n21 02 2016 16:03:15.445:INFO [karma]: Karma v0.13.21 server started at http://localhost:9876/\n21 02 2016 16:03:15.451:INFO [launcher]: Starting browser Chrome\n21 02 2016 16:03:16.551:INFO [Chrome 48.0.2564 (Linux 0.0.0)]: Connected on socket /#yRS32ons0_2HGhrwAAAA with id 3072946\n\nSTART:\n lib1\n \xe2\x9c\x96 should return 1\n\nFinished in 0.015 secs / 0.001 secs\n\nSUMMARY:\n\xe2\x9c\x94 0 tests completed\n\xe2\x9c\x96 1 test failed\n\nFAILED TESTS:\n lib1\n \xe2\x9c\x96 …Run Code Online (Sandbox Code Playgroud) 尽管我可以使代码覆盖率测量(单元测试覆盖的文件和代码行的百分比)正常工作,但我无法使其在编辑器中突出显示所覆盖的代码。
我有业力覆盖
提前致谢。
编辑:根据要求添加了屏幕截图。抱歉我不得不模糊一些信息。
我目前正在使用 Karma 作为 Webpack 的测试运行器。我注意到,不包含测试的简单测试文件为我提供了 92.86% 的语句覆盖率、50% 的分支覆盖率、100% 的函数覆盖率和 92.86% 的行覆盖率。
describe('tests.js', function () {
});
Run Code Online (Sandbox Code Playgroud)
当我检查缺少覆盖的位置时,我看到了以下代码(第 10 行),该代码由 Webpack 注入到我的模块中,因为没有被测试覆盖:
if(installedModules[moduleId])
return installedModules[moduleId].exports;
Run Code Online (Sandbox Code Playgroud)
我无法对此进行测试,因为 Webpack 正在将此代码注入到模块中。那么如何阻止此类信息被包含在覆盖率报告中呢?
覆盖率报告给我的整个渲染文件如下:
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ Iif(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module …Run Code Online (Sandbox Code Playgroud) 我正在使用Karma处理Angular 2的单元测试用例,我遇到了一个函数,我在下面运行测试
expect(component.subscribeToEvents()).toBeTruthy();
Run Code Online (Sandbox Code Playgroud)
我查看我的覆盖代码,测试文件中的行似乎没有覆盖订阅内的任何内容.我曾尝试使用MockBackend模拟服务函数内的api调用,但我不确定如何对订阅对象进行模拟,有人可以帮助我吗?
以下是test.component.ts
subscribeToEvents() {
this.subscription = this.czData.$selectedColorZone
.subscribe(items => {
this.resourceLoading = true;
if (!this.resourceData || (this.resourceData && this.resourceData.length === 0)) {
this.settings.layout.flypanel.display = false;
this.getAllResources(this.pagination.start, this.pagination.size);
}
else {
this.pagination.start = 1;
this.pagination.end = this.pagination.size;
this.getAllResources(1, this.pagination.size);
this.settings.layout.flypanel.display = true;
}
});
return true;
Run Code Online (Sandbox Code Playgroud)
}
unit-testing karma-jasmine karma-coverage angular2-services angular
我们面临一个问题,即我们的测试在某个时间点后开始失败或运行速度极慢。我在网上看到其他人也面临问题的文章。这些失败的主要原因是浏览器在处理 DOM 时消耗了内存。我们正在使用种子项目,它使用 SystemJS 构建我们的应用程序。我们当前的 Angular 版本是 2.2.3。
所以,我正在考虑一种解决方法,我可以并行处理我们的测试运行(即运行多个 karma 服务器,我确实尝试过,但它开始消耗 100% CPU)或批处理。因此,批量小测试运行将确保业力停止并再次启动。
有办法吗?
另外,如果我们能够做到这一点,如何获得一致的覆盖范围?我们正在使用伊斯坦布尔。
如果您还有其他问题,请告诉我。
例如,我们的服务和模型相关测试在 3 秒内运行(500 多个测试),但我们的组件测试(900 多个)需要 15分钟。
unit-testing karma-runner karma-jasmine karma-coverage angular
我正在开发一个Angular4项目.
我正在尝试设置代码覆盖率.我创建了一个非常简单的小应用程序.
我读了我能找到的每一个可能的页面,但我迷失了.
如何在Angular4中设置代码覆盖率?
更新2: 我现在决定使用业力报道报道 https://www.npmjs.com/package/karma-coverage ,因此根据描述重写了业力配置文件.
包json更新到了.
测试正在运行并通过:
这是我的包json.
{
"name": "angular2-webpack",
"version": "0.0.1",
"description": "A webpack starter for Angular",
"scripts": {
"pretest": "npm run lint",
"start": "webpack-dev-server --inline --progress --port 8080",
"test": "karma start",
"build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail",
"lint": "tslint --force \"src/**/*.ts\""
},
"license": "MIT",
"dependencies": {
"@angular/common": "4.1.2",
"@angular/compiler": "4.1.2",
"@angular/core": "4.1.2",
"@angular/forms": "4.1.2",
"@angular/http": "4.1.2",
"@angular/platform-browser": "4.1.2",
"@angular/platform-browser-dynamic": "4.1.2",
"@angular/router": "4.1.2",
"bootstrap": "^3.3.7",
"core-js": "2.4.1", …Run Code Online (Sandbox Code Playgroud) 我目前遇到问题。我开始为我的 Angular 应用程序编写测试并想要调试它们。现在我已经用谷歌搜索了很多,我尝试了来自微软的食谱(https://github.com/Microsoft/vscode-recipes/tree/master/Angular-CLI),而我最接近使它工作的是这个BlogPost
http://blog.mlewandowski.com/Debugging-Karma-tests-with-VSCode.html
现在至少我可以将调试器附加到 VS-Code。然而,VS Code 仍然不会在断点处停止,而是测试继续运行。VS Code 中的断点也将保持未经验证的状态(见图)
这就是我到目前为止所拥有的(我只提供我更改过的部分,以免发布太多代码)。
知道我做错了什么吗?除此之外,调试工作正常。我可以调试我的 Node.js 应用程序,并且调试 ng 服务也可以正常工作。
启动.json
{
"type": "chrome",
"request": "attach",
"name": "MyApp - Tests",
"address": "localhost",
"port": 9222,
"pathMapping": {
"/": "${workspaceRoot}",
"/base/": "${workspaceRoot}"
}
}
Run Code Online (Sandbox Code Playgroud)
karma.conf.js
browsers: [
'ChromeDebugging'
],
customLaunchers: {
ChromeDebugging: {
base: 'Chrome',
flags: ['--remote-debugging-port=9222']
}
}
Run Code Online (Sandbox Code Playgroud) 我正在开发 Angular 应用程序,并使用 Jasmine 来测试该应用程序。
我想要的是用一种方法测试两个相似的HTTP 请求,例如ngOnInit().
我有一个 HTTP 请求,在方法中调用了两次ngOnInit(),现在编写我使用的测试用例,抛出如下错误:
错误:预期条件“匹配 URL:http://localhost:8080/api/demoList ”有 1 个匹配请求,但发现 2 个请求。
例如,
// method to test
ngOnInit() {
this.httpGetRequest();
// some other code
this.httpGetRequest();
}
this.httpGetRequest() {
this.httpClient.get(http://localhost:8080/api/getSomeList);
}
//test case for ngOnInit()
it('should do something', () => {
spyOn(component, 'ngOnInit').and.callThrough();
component.ngOnInit();
const req = httpTestingController.expectOne(`http://localhost:8080/api/getSomeList`);
expect(req.request.method).toEqual('GET');
req.flush(mockList);
});
Run Code Online (Sandbox Code Playgroud)
如何测试类似 URL 的多个请求?
我有 746 个测试用例,但是当我尝试使用以下命令运行测试用例时:
"ng test --browsers='CustomChromeHeadless' --code-coverage=true --watch=false --source-map=false",
Run Code Online (Sandbox Code Playgroud)
在执行一些随机数量的测试用例后,它给出如下错误。
Chrome Headless 83.0.4103.116 (Linux x86_64) ERROR
Disconnected, because no message in 30000 ms.
Run Code Online (Sandbox Code Playgroud)
包.json
"karma": "^5.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-cli": "^2.0.0",
"karma-coverage": "^2.0.2",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "^3.3.1",
"karma-jasmine-html-reporter": "^1.5.4",
"karma-junit-reporter": "^1.2.0",
Run Code Online (Sandbox Code Playgroud)
业力配置文件
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-junit-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine …Run Code Online (Sandbox Code Playgroud) karma-coverage ×10
angular ×6
istanbul ×3
javascript ×3
unit-testing ×3
jasmine ×2
karma-runner ×2
node.js ×2
webpack ×2
debugging ×1
isparta ×1
webstorm ×1