Deployed the page to Github Pages.

This commit is contained in:
Batuhan Berk Başoğlu 2024-11-03 21:30:09 -05:00
parent 1d79754e93
commit 2c89899458
Signed by: batuhan-basoglu
SSH key fingerprint: SHA256:kEsnuHX+qbwhxSAXPUQ4ox535wFHu/hIRaa53FzxRpo
62797 changed files with 6551425 additions and 15279 deletions

View file

@ -0,0 +1,241 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [3.0.3](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v3.0.2...v3.0.3) (2020-05-28)
### Bug Fixes
* duplicated files when "skipFilesWithNoCoverage=false" on windows ([052f6ab](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/052f6abca9a3039fca2a65e9e8488f39f9072b26))
### [3.0.2](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v3.0.1...v3.0.2) (2020-05-05)
### Bug Fixes
* return correct exit code when thresholds are not met (that works with the karma api) ([a0cbdd8](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/a0cbdd80a2268586b62ef72e5541a36b1b46396a)), closes [#80](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/80)
### [3.0.1](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v3.0.0...v3.0.1) (2020-05-04)
### Bug Fixes
* set correct process exit code when thresholds are not met ([9ba3fe0](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/9ba3fe0acf3ee778518c154a8dd050584f47bc13)), closes [#80](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/80)
## [3.0.0](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v2.1.1...v3.0.0) (2020-05-01)
### ⚠ BREAKING CHANGES
* node 6 and node 8 are no longer supported. To use this package you must upgrade to node 10 or higher.
### Features
* upgrade to latest istanbul api ([28cbbfb](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/28cbbfb2cf8bd5b9533ceb489cc5047ff3def730))
<a name="2.1.1"></a>
## [2.1.1](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v2.1.0...v2.1.1) (2019-11-21)
### Bug Fixes
* add npm funding link ([ee9fb51](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/ee9fb51))
<a name="2.1.0"></a>
# [2.1.0](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v2.0.6...v2.1.0) (2019-07-24)
### Features
* **config:** support istanbul-api instrumentation configuration ([c4f7a9c](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/c4f7a9c)), closes [#73](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/73)
<a name="2.0.6"></a>
## [2.0.6](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v2.0.5...v2.0.6) (2019-07-20)
### Bug Fixes
* get source code from sourceMapStore on write report ([619d90d](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/619d90d)), closes [#72](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/72)
<a name="2.0.5"></a>
## [2.0.5](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v2.0.4...v2.0.5) (2019-02-17)
### Bug Fixes
* correctly strip source file prefixes when no webpack.context is defined ([3c48bf8](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/3c48bf8))
* don't double-report files with mixed slashes in their names on windows ([38087c2](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/38087c2))
<a name="2.0.4"></a>
## [2.0.4](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v2.0.3...v2.0.4) (2018-09-08)
### Bug Fixes
* handle source roots being undefined on windows ([8eba911](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/8eba911)), closes [#55](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/55)
<a name="2.0.3"></a>
## [2.0.3](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v2.0.2...v2.0.3) (2018-09-01)
### Bug Fixes
* update istanbuljs to 2.x ([a835e22](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/a835e22)), closes [#52](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/52)
* use correct source file path separators on windows ([938e93c](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/938e93c)), closes [#47](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/47)
<a name="2.0.2"></a>
## [2.0.2](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v2.0.1...v2.0.2) (2018-08-24)
### Bug Fixes
* files with no coverage should be preserved by default ([#54](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/54)) ([e5a5545](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/e5a5545)), closes [#53](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/53)
<a name="2.0.1"></a>
## [2.0.1](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v2.0.0...v2.0.1) (2018-05-23)
### Bug Fixes
* don't log errors twice when using multiple reporters ([a17b6ca](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/a17b6ca)), closes [#44](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/44)
<a name="2.0.0"></a>
# [2.0.0](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.4.3...v2.0.0) (2018-05-17)
### Features
* drop support for node 4 ([26ad3af](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/26ad3af))
### BREAKING CHANGES
* node 4 is no longer supported
<a name="1.4.3"></a>
## [1.4.3](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.4.2...v1.4.3) (2018-05-17)
### Bug Fixes
* **verbose:** pass the verbose option to istanbul if set ([9473517](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/9473517)), closes [#43](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/43)
<a name="1.4.2"></a>
## [1.4.2](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.4.1...v1.4.2) (2018-03-06)
### Bug Fixes
* all browsers should have their own output folder when not combined ([4aad40b](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/4aad40b)), closes [#39](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/39)
<a name="1.4.1"></a>
## [1.4.1](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.4.0...v1.4.1) (2018-01-24)
### Bug Fixes
* handle no config being set ([5483e2b](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/5483e2b)), closes [#36](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/36)
<a name="1.4.0"></a>
# [1.4.0](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.3.3...v1.4.0) (2018-01-23)
### Features
* add combineBrowserReports option ([2ae16ee](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/2ae16ee)), closes [#34](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/34)
<a name="1.3.3"></a>
## [1.3.3](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.3.1...v1.3.3) (2017-12-26)
### Bug Fixes
* don't prepend the webpack context to absolute source roots ([138e8f8](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/138e8f8)), closes [#33](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/33)
<a name="1.3.1"></a>
## [1.3.1](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.3.0...v1.3.1) (2017-12-23)
### Bug Fixes
* prepend the webpack context to the source root if not set ([4138b80](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/4138b80)), closes [#32](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/32)
<a name="1.3.0"></a>
# [1.3.0](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.2.1...v1.3.0) (2017-05-26)
### Features
* **thresholds:** allow overriding per file thresholds ([1a894f0](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/1a894f0)), closes [#20](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/20)
* **thresholds:** allow threshold logs not to be emitted as errors ([2de647c](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/2de647c)), closes [#19](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/19)
<a name="1.2.1"></a>
## [1.2.1](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.2.0...v1.2.1) (2017-04-30)
### Bug Fixes
* don't throw when there are no sources as part of the sourcemap ([4fc5311](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/4fc5311)), closes [#15](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/15)
<a name="1.2.0"></a>
# [1.2.0](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/compare/v1.1.0...v1.2.0) (2017-04-15)
### Features
* **thresholds:** allow per file enforcement of threshold reporting ([f6d71b3](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/commit/f6d71b3)), closes [#12](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/12)
# 1.1.0
* Add the skipFilesWithNoCoverage option
# 1.0.0
* Add the %browser% placeholder in the dir option to allow multiple browsers to output coverage
# 0.3.0
* Add coverage thresold enforcement via the thresholds option
# 0.2.0
* Add the `fixWebpackSourcePaths` option
# 0.1.0
* Initial release

21
node_modules/karma-coverage-istanbul-reporter/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Matt Lewis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

118
node_modules/karma-coverage-istanbul-reporter/README.md generated vendored Normal file
View file

@ -0,0 +1,118 @@
# karma-coverage-istanbul-reporter
[![Sponsorship](https://img.shields.io/badge/funding-github-%23EA4AAA)](https://github.com/users/mattlewis92/sponsorship)
[![Build Status](https://travis-ci.org/mattlewis92/karma-coverage-istanbul-reporter.svg?branch=master)](https://travis-ci.org/mattlewis92/karma-coverage-istanbul-reporter)
[![codecov](https://codecov.io/gh/mattlewis92/karma-coverage-istanbul-reporter/branch/master/graph/badge.svg)](https://codecov.io/gh/mattlewis92/karma-coverage-istanbul-reporter)
[![npm version](https://badge.fury.io/js/karma-coverage-istanbul-reporter.svg)](http://badge.fury.io/js/karma-coverage-istanbul-reporter)
[![npm](https://img.shields.io/npm/dm/karma-coverage-istanbul-reporter.svg)](http://badge.fury.io/js/karma-coverage-istanbul-reporter)
[![Twitter Follow](https://img.shields.io/twitter/follow/mattlewis92_.svg)](https://twitter.com/mattlewis92_)
> A karma reporter that uses the latest istanbul 1.x APIs (with full sourcemap support) to report coverage.
## About
This is a reporter only and does not perform the actual instrumentation of your code. Babel users should use the [istanbul babel plugin](https://github.com/istanbuljs/babel-plugin-istanbul) to instrument your code and webpack + typescript users should use the [coverage-istanbul-loader](https://github.com/JS-DevTools/coverage-istanbul-loader) and then use this karma reporter to do the actual reporting. See the [test config](https://github.com/mattlewis92/karma-coverage-istanbul-reporter/blob/master/test/karma.conf.js) for an e2e example of how to combine them.
## Installation
```bash
npm install karma-coverage-istanbul-reporter --save-dev
```
## Configuration
```js
// karma.conf.js
const path = require('path');
module.exports = function(config) {
config.set({
// ... rest of karma config
// anything named karma-* is normally auto included so you probably dont need this
plugins: ['karma-coverage-istanbul-reporter'],
reporters: ['coverage-istanbul'],
coverageIstanbulReporter: {
// reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib
reports: ['html', 'lcovonly', 'text-summary'],
// base output directory. If you include %browser% in the path it will be replaced with the karma browser name
dir: path.join(__dirname, 'coverage'),
// Combines coverage information from multiple browsers into one report rather than outputting a report
// for each browser.
combineBrowserReports: true,
// if using webpack and pre-loaders, work around webpack breaking the source path
fixWebpackSourcePaths: true,
// Omit files with no statements, no functions and no branches covered from the report
skipFilesWithNoCoverage: true,
// Most reporters accept additional config options. You can pass these through the `report-config` option
'report-config': {
// all options available at: https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/html/index.js#L257-L261
html: {
// outputs the report in ./coverage/html
subdir: 'html'
}
},
// enforce percentage thresholds
// anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
thresholds: {
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
// thresholds for all files
global: {
statements: 100,
lines: 100,
branches: 100,
functions: 100
},
// thresholds per file
each: {
statements: 100,
lines: 100,
branches: 100,
functions: 100,
overrides: {
'baz/component/**/*.js': {
statements: 98
}
}
}
},
verbose: true // output config used by istanbul for debugging
}
});
};
```
### List of reporters and options
- [clover](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/clover/index.js#L14-L15)
- [cobertura](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/cobertura/index.js#L16-L17)
- [html-spa](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/html-spa/index.js#L47-L61)
- [html](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/html/index.js#L257-L261)
- [json-summary](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/json-summary/index.js#L12)
- [json](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/json/index.js#L12)
- [lcov](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/lcov/index.js#L13)
- [lcovonly](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/lcovonly/index.js#L11-L12)
- none
- [teamcity](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/teamcity/index.js#L13-L14)
- [text-lcov](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/text-lcov/index.js#L11)
- [text-summary](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/text-summary/index.js#L13)
- [text](https://github.com/istanbuljs/istanbuljs/blob/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib/text/index.js#L231-L237)
## Credits
- [Original karma-coverage source](https://github.com/karma-runner/karma-coverage/blob/master/lib/reporter.js)
- [Example of using the new reporter API](https://github.com/facebook/jest/blob/master/scripts/mapCoverage.js)
- [Karma remap istanbul](https://github.com/marcules/karma-remap-istanbul)
## License
MIT

View file

@ -0,0 +1,121 @@
{
"name": "karma-coverage-istanbul-reporter",
"version": "3.0.3",
"description": "A karma reporter that uses the latest istanbul 1.x APIs (with full sourcemap support) to report coverage.",
"funding": {
"url": "https://github.com/sponsors/mattlewis92"
},
"main": "src/reporter.js",
"files": [
"src"
],
"scripts": {
"start": "npm run test:watch",
"lint": "xo",
"pretest": "npm run lint",
"test": "nyc mocha",
"test:watch": "mocha --watch",
"codecov": "cat coverage/lcov.info | codecov",
"commit": "git-cz",
"prerelease": "npm test",
"release": "standard-version && git push --follow-tags origin master",
"postrelease": "npm publish"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mattlewis92/karma-coverage-istanbul-reporter.git"
},
"keywords": [
"karma-plugin",
"karma-reporter",
"coverage",
"istanbul",
"istanbuljs"
],
"author": "Matt Lewis",
"license": "MIT",
"bugs": {
"url": "https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues"
},
"homepage": "https://github.com/mattlewis92/karma-coverage-istanbul-reporter#readme",
"dependencies": {
"istanbul-lib-coverage": "^3.0.0",
"istanbul-lib-report": "^3.0.0",
"istanbul-lib-source-maps": "^3.0.6",
"istanbul-reports": "^3.0.2",
"minimatch": "^3.0.4"
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@commitlint/prompt": "^8.3.5",
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"chai": "^4.2.0",
"codecov": "^3.6.5",
"commitizen": "^4.0.5",
"coverage-istanbul-loader": "^3.0.3",
"husky": "^4.2.5",
"karma": "^5.0.4",
"karma-mocha": "^2.0.1",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^4.0.2",
"mocha": "^7.1.2",
"nyc": "^15.0.1",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"rimraf": "^3.0.2",
"sinon": "^9.0.2",
"standard-version": "^7.1.0",
"ts-loader": "^7.0.2",
"tslint": "^6.1.2",
"tslint-loader": "^3.6.0",
"typescript": "^3.8.3",
"webpack": "^4.43.0",
"xo": "^0.30.0"
},
"nyc": {
"reporter": [
"html",
"text-summary",
"lcovonly"
]
},
"xo": {
"space": true,
"prettier": true,
"envs": [
"node",
"mocha"
],
"rules": {
"space-before-function-paren": 0,
"object-curly-spacing": 0,
"operator-linebreak": 0,
"indent": 0
},
"ignore": [
"{test,tests,spec,__tests__}/fixture{s,}/**"
]
},
"config": {
"commitizen": {
"path": "@commitlint/prompt"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"husky": {
"hooks": {
"commit-msg": "commitlint -e",
"pre-commit": "pretty-quick --staged"
}
},
"mocha": {
"timeout": 10000
}
}

View file

@ -0,0 +1,257 @@
const path = require('path');
const libCoverage = require('istanbul-lib-coverage');
const libSourceMaps = require('istanbul-lib-source-maps');
const libReport = require('istanbul-lib-report');
const libReports = require('istanbul-reports');
const util = require('./util');
const BROWSER_PLACEHOLDER = '%browser%';
function checkThresholds(thresholds, summary) {
const failedTypes = [];
Object.keys(thresholds).forEach((key) => {
const coverage = summary[key].pct;
if (coverage < thresholds[key]) {
failedTypes.push(key);
}
});
return failedTypes;
}
function CoverageIstanbulReporter(baseReporterDecorator, logger, config) {
baseReporterDecorator(this);
// Copied from https://github.com/angular/angular-cli/pull/9529/files
// Fixes https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/44
const reporterName = 'coverage-istanbul';
const hasTrailingReporters =
config.reporters.slice(-1).pop() !== reporterName;
if (hasTrailingReporters) {
this.writeCommonMsg = () => {};
}
const log = logger.create('reporter.coverage-istanbul');
const browserCoverage = new WeakMap();
const coverageConfig = Object.assign({}, config.coverageIstanbulReporter);
function addCoverage(coverageMap, browser) {
const coverage = browserCoverage.get(browser);
browserCoverage.delete(browser);
if (!coverage) {
return;
}
Object.keys(coverage).forEach((filename) => {
const fileCoverage = coverage[filename];
if (fileCoverage.inputSourceMap && coverageConfig.fixWebpackSourcePaths) {
fileCoverage.inputSourceMap = util.fixWebpackSourcePaths(
fileCoverage.inputSourceMap,
config.webpack
);
}
if (
coverageConfig.skipFilesWithNoCoverage &&
Object.keys(fileCoverage.statementMap).length === 0 &&
Object.keys(fileCoverage.fnMap).length === 0 &&
Object.keys(fileCoverage.branchMap).length === 0
) {
log.debug(`File [${filename}] ignored, nothing could be mapped`);
} else {
coverageMap.addFileCoverage(fileCoverage);
}
});
}
function logThresholdMessage(thresholds, message) {
if (thresholds.emitWarning) {
log.warn(message);
} else {
log.error(message);
}
}
function createReport(browserOrBrowsers, results) {
const reportConfigOverride =
!coverageConfig.combineBrowserReports && coverageConfig.dir
? {
dir: coverageConfig.dir.replace(
BROWSER_PLACEHOLDER,
browserOrBrowsers.name
),
}
: {};
const reportConfig = {
instrumentation: Object.assign({}, coverageConfig.instrumentation),
verbose: coverageConfig.verbose === true,
reporting: Object.assign({}, coverageConfig, reportConfigOverride),
summarizer: coverageConfig.summarizer,
};
const reportTypes = reportConfig.reporting.reports;
const coverageMap = libCoverage.createCoverageMap();
const sourceMapStore = libSourceMaps.createSourceMapStore();
if (coverageConfig.combineBrowserReports) {
browserOrBrowsers.forEach((browser) => addCoverage(coverageMap, browser));
} else {
addCoverage(coverageMap, browserOrBrowsers);
}
const {
sourceFinder,
map: remappedCoverageMap,
} = sourceMapStore.transformCoverage(coverageMap);
if (!coverageConfig.skipFilesWithNoCoverage) {
// On Windows, istanbul returns files with mixed forward/backslashes in them
const fixedFilePaths = {};
remappedCoverageMap.files().forEach((path) => {
fixedFilePaths[util.fixPathSeparators(path)] = true;
});
coverageMap.files().forEach((path) => {
if (!(util.fixPathSeparators(path) in fixedFilePaths)) {
// Re-add empty coverage record
remappedCoverageMap.addFileCoverage(path);
}
});
}
log.debug('Writing coverage reports:', reportTypes);
writeReports(reportConfig, remappedCoverageMap, sourceFinder);
const userThresholds = coverageConfig.thresholds;
const thresholds = {
emitWarning: false,
global: {
statements: 0,
lines: 0,
branches: 0,
functions: 0,
},
each: {
statements: 0,
lines: 0,
branches: 0,
functions: 0,
overrides: {},
},
};
if (userThresholds) {
if (userThresholds.global || userThresholds.each) {
Object.assign(thresholds.global, userThresholds.global);
Object.assign(thresholds.each, userThresholds.each);
if (userThresholds.emitWarning === true) {
thresholds.emitWarning = true;
}
} else {
Object.assign(thresholds.global, userThresholds);
}
}
let thresholdCheckFailed = false;
// Adapted from https://github.com/istanbuljs/nyc/blob/98ebdff573be91e1098bb7259776a9082a5c1ce1/index.js#L463-L478
const globalSummary = remappedCoverageMap.getCoverageSummary();
const failedGlobalTypes = checkThresholds(thresholds.global, globalSummary);
failedGlobalTypes.forEach((type) => {
thresholdCheckFailed = true;
logThresholdMessage(
thresholds,
`Coverage for ${type} (${globalSummary[type].pct}%) does not meet global threshold (${thresholds.global[type]}%)`
);
});
remappedCoverageMap.files().forEach((file) => {
const fileThresholds = Object.assign(
{},
thresholds.each,
util.overrideThresholds(
file,
thresholds.each.overrides,
config.basePath
)
);
delete fileThresholds.overrides;
const fileSummary = remappedCoverageMap.fileCoverageFor(file).toSummary()
.data;
const failedFileTypes = checkThresholds(fileThresholds, fileSummary);
failedFileTypes.forEach((type) => {
thresholdCheckFailed = true;
if (coverageConfig.fixWebpackSourcePaths) {
file = util.fixWebpackFilePath(file);
}
logThresholdMessage(
thresholds,
`Coverage for ${type} (${fileSummary[type].pct}%) in file ${file} does not meet per file threshold (${fileThresholds[type]}%)`
);
});
});
if (thresholdCheckFailed && !thresholds.emitWarning && config.singleRun) {
results.exitCode = 1;
}
}
function writeReports(config, coverageMap, sourceFinder) {
const reportingConfig = {
...{
dir: 'coverage',
reports: [],
watermarks: [],
'report-config': [],
},
...config.reporting,
};
const dir = path.resolve(reportingConfig.dir);
const contextOptions = {
dir,
watermarks: reportingConfig.watermarks,
sourceFinder,
coverageMap,
};
const context = libReport.createContext(contextOptions);
const tree = context.getTree(config.summarizer);
reportingConfig.reports.forEach((name) => {
const reportConfig = reportingConfig['report-config'][name];
const report = libReports.create(name, reportConfig);
tree.visit(report, context);
});
}
this.onBrowserComplete = function (browser, result) {
if (result && result.coverage) {
browserCoverage.set(browser, result.coverage);
}
};
const baseReporterOnRunComplete = this.onRunComplete;
this.onRunComplete = function (browsers, results) {
Reflect.apply(baseReporterOnRunComplete, this, arguments);
if (coverageConfig.combineBrowserReports) {
createReport(browsers, results);
} else {
browsers.forEach((browser) => createReport(browser, results));
}
};
}
CoverageIstanbulReporter.$inject = [
'baseReporterDecorator',
'logger',
'config',
];
module.exports = {
'reporter:coverage-istanbul': ['type', CoverageIstanbulReporter],
};

View file

@ -0,0 +1,99 @@
const path = require('path');
const minimatch = require('minimatch');
function fixWebpackFilePath(filePath) {
if (filePath.includes('!')) {
filePath = filePath.split('!').pop();
}
if (filePath.includes('?')) {
filePath = filePath.split('?')[0];
}
return filePath;
}
function fixPathSeparators(filePath) {
const isWin = process.platform.startsWith('win');
// Workaround for https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/9
if (isWin && filePath) {
return filePath.replace(/\//g, '\\').replace(/\\\\/g, '\\');
}
return filePath;
}
function fixWebpackSourcePaths(sourceMap, webpackConfig) {
let { sourceRoot } = sourceMap;
// As per https://webpack.js.org/configuration/entry-context/#context, if no context is specified, the current
// directory that the process is running from should be assumed instead
const context = (webpackConfig && webpackConfig.context) || process.cwd();
// Fix for https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/32
// The sourceRoot is relative to the project directory and not an absolute path, so add the webpack context to it if set
if (
context &&
sourceRoot &&
!sourceRoot.startsWith(context) &&
!path.isAbsolute(sourceRoot)
) {
sourceRoot = path.join(context, sourceRoot);
}
sourceRoot = fixPathSeparators(sourceRoot);
const result = Object.assign({}, sourceMap, {
file: fixPathSeparators(sourceMap.file),
sources: (sourceMap.sources || []).map((source) => {
source = fixWebpackFilePath(source);
if (sourceRoot && source.startsWith(sourceRoot)) {
source = source.replace(sourceRoot, '');
}
return source;
}),
});
if (sourceRoot) {
result.sourceRoot = sourceRoot;
}
return result;
}
function isAbsolute(file) {
if (path.isAbsolute) {
return path.isAbsolute(file);
}
return path.resolve(file) === path.normalize(file);
}
function normalize(key, basePath) {
// Exclude keys will always be relative, but covObj keys can be absolute or relative
let excludeKey = isAbsolute(key) ? path.relative(basePath, key) : key;
// Also normalize for files that start with `./`, etc.
excludeKey = path.normalize(excludeKey);
return excludeKey;
}
function overrideThresholds(key, overrides, basePath) {
let thresholds = {};
// First match wins
Object.keys(overrides).some((pattern) => {
if (minimatch(normalize(key, basePath), pattern, { dot: true })) {
thresholds = overrides[pattern];
return true;
}
return false;
});
return thresholds;
}
module.exports.fixPathSeparators = fixPathSeparators;
module.exports.fixWebpackSourcePaths = fixWebpackSourcePaths;
module.exports.fixWebpackFilePath = fixWebpackFilePath;
module.exports.overrideThresholds = overrideThresholds;