Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

danger-plugin-coverage

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

danger-plugin-coverage - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

dist/report.js

29

dist/plugin.js

@@ -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) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc