danger-plugin-coverage
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -8,7 +8,5 @@ "use strict"; | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _xml2js = require("xml2js"); | ||
var _report = require("./report"); | ||
@@ -214,23 +212,2 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* Get the parsed coverage XML. | ||
*/ | ||
const getCoverageXml = async cloverPath => { | ||
const absolutePath = _path.default.join(process.cwd(), cloverPath); | ||
const xmlParser = new _xml2js.Parser(); | ||
if (!_fs.default.existsSync(absolutePath)) { | ||
return null; | ||
} | ||
const data = _fs.default.readFileSync(absolutePath); | ||
const { | ||
coverage: coverageXml | ||
} = await xmlParser.parseStringPromise(data); | ||
return coverageXml; | ||
}; | ||
/** | ||
* Get the relevant files. | ||
@@ -260,3 +237,3 @@ */ | ||
failureMessage = 'Test coverage is looking a little low for the files created ' + 'or modified in this PR, perhaps we need to improve this.', | ||
cloverReportPath = _path.default.join('coverage', 'clover.xml'), | ||
cloverReportPath, | ||
maxRows = 5, | ||
@@ -270,3 +247,3 @@ showAllFiles = false, | ||
} = {}) => { | ||
const coverageXml = await getCoverageXml(cloverReportPath); | ||
const coverageXml = await (0, _report.getCoverageReport)(cloverReportPath); | ||
@@ -273,0 +250,0 @@ if (!coverageXml) { |
{ | ||
"name": "danger-plugin-coverage", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A Danger plugin to report code coverage.", | ||
@@ -48,4 +48,5 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"fast-glob": "^3.2.4", | ||
"xml2js": "^0.4.23" | ||
} | ||
} |
@@ -10,6 +10,35 @@ # danger-plugin-coverage | ||
This plugin reads coverage report in the `clover.xml` format. This format is | ||
output by various JavaScript testing libraries, such as [Jest](https://jestjs.io/), | ||
as well as testing libraries for other languages, such as [PHPUnit](https://phpunit.de/). | ||
This plugin detects and parses coverage reports, posting the results as a | ||
Markdown table back to the pull request. | ||
It uses the `clover.xml` format, which is output by [Istanbul](https://istanbul.js.org/), | ||
a coverage reporter integrated with JavaScript testing tools such as | ||
[Jest](https://jestjs.io/) and [Karma](https://karma-runner.github.io/). | ||
This format can also be output by testing libraries for other languages, such as | ||
[PHPUnit](https://phpunit.de/). So, while this is primarily intended as a tool | ||
to run against JavaScript packages it would technically work as a coverage | ||
reporter for other languages too. | ||
<details> | ||
<summary>View an example report</summary> | ||
## Coverage Report | ||
> Test coverage is looking a little low for the files created or modified in this PR, perhaps we need to improve this. | ||
``` | ||
Coverage threshold for branches (80%) not met: 33.33% | ||
Coverage threshold for functions (80%) not met: 66.67% | ||
``` | ||
|Impacted Files|% Stmts|% Branch|% Funcs|| | ||
|---|:-:|:-:|:-:|:-:| | ||
|[src/module-one.js]()|100|100|100|:white_check_mark:| | ||
|[src/module-two.js]()|95.24|33.33|66.67|:x:| | ||
|[src/module-three.js]()|82.33|100|44.55|:x:| | ||
|[src/module-four.js]()|95.24|82.55|81.55|:white_check_mark:| | ||
</details> | ||
## Usage | ||
@@ -36,24 +65,2 @@ | ||
Coverage will be reported as in the example below. | ||
--- | ||
## Coverage Report | ||
> Test coverage is looking a little low for the files created or modified in this PR, perhaps we need to improve this. | ||
``` | ||
Coverage threshold for branches (80%) not met: 33.33% | ||
Coverage threshold for functions (80%) not met: 66.67% | ||
``` | ||
|Impacted Files|% Stmts|% Branch|% Funcs|| | ||
|---|:-:|:-:|:-:|:-:| | ||
|[src/module-one.js]()|100|100|100|:white_check_mark:| | ||
|[src/module-two.js]()|95.24|33.33|66.67|:x:| | ||
|[src/module-three.js]()|82.33|100|44.55|:x:| | ||
|[src/module-four.js]()|95.24|82.55|81.55|:white_check_mark:| | ||
--- | ||
## Settings | ||
@@ -67,5 +74,5 @@ | ||
| `failureMessage` | A custom message to show when coverage is bellow the threshold. | | ||
| `cloverReportPath` | The relative path to the `clover.xml` file. | | ||
| `cloverReportPath` | Override automatic coverage report detection to provide the relative path to a report. | | ||
| `maxRows` | The number of rows to show (additional rows will be collapsed within a `<details>` element). | | ||
| `threshold` | The thresholds at which to show the failure messaging. s | | ||
| `threshold` | The thresholds at which to show the failure messaging. | | ||
@@ -72,0 +79,0 @@ **Example:** |
@@ -1,5 +0,5 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { Parser as XMLParser } from 'xml2js'; | ||
import { getCoverageReport } from './report'; | ||
const newLine = '\n'; | ||
@@ -239,19 +239,2 @@ | ||
/** | ||
* Get the parsed coverage XML. | ||
*/ | ||
const getCoverageXml = async (cloverPath) => { | ||
const absolutePath = path.join(process.cwd(), cloverPath); | ||
const xmlParser = new XMLParser(); | ||
if (!fs.existsSync(absolutePath)) { | ||
return null; | ||
} | ||
const data = fs.readFileSync(absolutePath); | ||
const { coverage: coverageXml } = await xmlParser.parseStringPromise(data); | ||
return coverageXml; | ||
}; | ||
/** | ||
* Get the relevant files. | ||
@@ -280,3 +263,3 @@ */ | ||
+ 'or modified in this PR, perhaps we need to improve this.', | ||
cloverReportPath = path.join('coverage', 'clover.xml'), | ||
cloverReportPath, | ||
maxRows = 5, | ||
@@ -290,3 +273,3 @@ showAllFiles = false, | ||
} = {}) => { | ||
const coverageXml = await getCoverageXml(cloverReportPath); | ||
const coverageXml = await getCoverageReport(cloverReportPath); | ||
@@ -293,0 +276,0 @@ if (!coverageXml) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43634
21
1059
93
2
+ Addedfast-glob@^3.2.4
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)