danger-plugin-coverage
Advanced tools
Comparing version 1.3.3 to 1.4.0
@@ -228,3 +228,3 @@ "use strict"; | ||
const getRelevantFiles = (coverageXml, showAllFiles) => { | ||
const getRelevantFiles = (coverageXml, showAllFiles, warnOnMissingFiles) => { | ||
var _danger$git2, _danger$git3; | ||
@@ -234,2 +234,5 @@ | ||
const allFiles = [...(((_danger$git2 = danger.git) === null || _danger$git2 === void 0 ? void 0 : _danger$git2.created_files) || []), ...(((_danger$git3 = danger.git) === null || _danger$git3 === void 0 ? void 0 : _danger$git3.modified_files) || [])]; | ||
const filePaths = files.map(file => _path.default.relative(process.cwd(), file.$.path)); | ||
const relevantFiles = files.filter(file => allFiles.includes(_path.default.relative(process.cwd(), file.$.path))); | ||
const missingFiles = allFiles.filter(file => !filePaths.includes(file)); | ||
@@ -240,3 +243,8 @@ if (showAllFiles) { | ||
return files.filter(file => allFiles.includes(_path.default.relative(process.cwd(), file.$.path))); | ||
if (warnOnMissingFiles && missingFiles.length) { | ||
const pluralisedFiles = `file${missingFiles.length === 1 ? '' : 's'}`; | ||
warn([`The coverage report contained no data on ${missingFiles.length} ${pluralisedFiles}.`, '<details>', '<summary>View missing files</summary>', '', ...missingFiles.map(missingFile => `- ${missingFile}`), '</details>'].join(newLine)); | ||
} | ||
return relevantFiles; | ||
}; | ||
@@ -254,2 +262,4 @@ /** | ||
showAllFiles = false, | ||
warnOnNoReport = true, | ||
warnOnMissingFiles = true, | ||
threshold = { | ||
@@ -265,6 +275,10 @@ statements: 80, | ||
if (!coverageXml) { | ||
if (warnOnNoReport) { | ||
warn('No coverage report was detected. ' + 'Please output a report in the `clover.xml` format before running danger'); | ||
} | ||
return; | ||
} | ||
const relevantFiles = getRelevantFiles(coverageXml, showAllFiles); | ||
const relevantFiles = getRelevantFiles(coverageXml, showAllFiles, warnOnMissingFiles); | ||
@@ -271,0 +285,0 @@ if (!relevantFiles.length) { |
{ | ||
"name": "danger-plugin-coverage", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"description": "A Danger plugin to report code coverage.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -80,9 +80,11 @@ # danger-plugin-coverage | ||
| name | description | | ||
|--------------------|----------------------------------------------------------------------------------------------| | ||
| `successMessage` | A custom message to show when coverage is above the threshold. | | ||
| `failureMessage` | A custom message to show when coverage is bellow the threshold. | | ||
| `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. | | ||
| name | description | | ||
|----------------------|----------------------------------------------------------------------------------------------| | ||
| `successMessage` | A custom message to show when coverage is above the threshold. | | ||
| `failureMessage` | A custom message to show when coverage is bellow the threshold. | | ||
| `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. | | ||
| `warnOnNoReport` | Show a warning if no coverage report was detected. | | ||
| `warnOnMissingFiles` | Show a warning if modified files are missing from the coverage report. | | ||
@@ -97,2 +99,4 @@ **Example:** | ||
failureMessage: ':-1: Test coverage is not looking so good.', | ||
warnOnNoReport: true, | ||
warnOnMissingFiles: true, | ||
cloverReportPath: './coverage/clover.xml', | ||
@@ -99,0 +103,0 @@ maxRows: 5, |
@@ -261,3 +261,3 @@ import path from 'path'; | ||
*/ | ||
const getRelevantFiles = (coverageXml, showAllFiles) => { | ||
const getRelevantFiles = (coverageXml, showAllFiles, warnOnMissingFiles) => { | ||
const files = getFlatFiles(coverageXml); | ||
@@ -269,2 +269,10 @@ const allFiles = [ | ||
const filePaths = files.map((file) => path.relative(process.cwd(), file.$.path)); | ||
const relevantFiles = files.filter((file) => ( | ||
allFiles.includes(path.relative(process.cwd(), file.$.path)) | ||
)); | ||
const missingFiles = allFiles.filter((file) => !filePaths.includes(file)); | ||
if (showAllFiles) { | ||
@@ -274,5 +282,15 @@ return files; | ||
return files.filter((file) => allFiles.includes( | ||
path.relative(process.cwd(), file.$.path), | ||
)); | ||
if (warnOnMissingFiles && missingFiles.length) { | ||
const pluralisedFiles = `file${missingFiles.length === 1 ? '' : 's'}`; | ||
warn([ | ||
`The coverage report contained no data on ${missingFiles.length} ${pluralisedFiles}.`, | ||
'<details>', | ||
'<summary>View missing files</summary>', | ||
'', | ||
...missingFiles.map((missingFile) => `- ${missingFile}`), | ||
'</details>', | ||
].join(newLine)); | ||
} | ||
return relevantFiles; | ||
}; | ||
@@ -290,2 +308,4 @@ | ||
showAllFiles = false, | ||
warnOnNoReport = true, | ||
warnOnMissingFiles = true, | ||
threshold = { | ||
@@ -301,6 +321,10 @@ statements: 80, | ||
if (!coverageXml) { | ||
if (warnOnNoReport) { | ||
warn('No coverage report was detected. ' | ||
+ 'Please output a report in the `clover.xml` format before running danger'); | ||
} | ||
return; | ||
} | ||
const relevantFiles = getRelevantFiles(coverageXml, showAllFiles); | ||
const relevantFiles = getRelevantFiles(coverageXml, showAllFiles, warnOnMissingFiles); | ||
@@ -307,0 +331,0 @@ if (!relevantFiles.length) { |
@@ -5,2 +5,3 @@ import path from 'path'; | ||
import coverage from '../../src'; | ||
import { CLOVER_PATH, DEFAULT_METRICS, DEFAULT_LINE } from '../constants'; | ||
import { | ||
@@ -14,19 +15,2 @@ getFileXml, | ||
const cloverPath = path.join(process.cwd(), 'coverage', 'clover.xml'); | ||
const defautMetrics = { | ||
statements: 10, | ||
coveredstatements: 10, | ||
conditionals: 10, | ||
coveredconditionals: 10, | ||
methods: 10, | ||
coveredmethods: 10, | ||
}; | ||
const defaultLine = { | ||
num: 1, | ||
count: 1, | ||
type: 'stmt', | ||
}; | ||
const successMessage = '> :+1: Test coverage is looking good.'; | ||
@@ -45,7 +29,7 @@ | ||
it('reports row as passing when all metrics meet the threshold', async () => { | ||
const file = getFileXml('src/one.js', defautMetrics, [defaultLine]); | ||
const file = getFileXml('src/one.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -76,6 +60,6 @@ | ||
const file = getFileXml('src/one.js', { | ||
...defautMetrics, | ||
...DEFAULT_METRICS, | ||
[metric]: 10, | ||
[`covered${metric}`]: 0, | ||
}, [defaultLine]); | ||
}, [DEFAULT_LINE]); | ||
@@ -95,3 +79,3 @@ const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -118,3 +102,3 @@ | ||
it('reports row as failing when lines does not meet the threshold', async () => { | ||
const file = getFileXml('src/one.js', defautMetrics, [ | ||
const file = getFileXml('src/one.js', DEFAULT_METRICS, [ | ||
{ | ||
@@ -129,3 +113,3 @@ num: 1, | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -152,5 +136,5 @@ | ||
it.each(['project', 'package'])('handles multiple %ss', async (parentElement) => { | ||
const fileOne = getFileXml('src/one.js', defautMetrics, [defaultLine]); | ||
const fileTwo = getFileXml('src/two.js', defautMetrics, [defaultLine]); | ||
const fileThree = getFileXml('src/three.js', defautMetrics, [defaultLine]); | ||
const fileOne = getFileXml('src/one.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const fileTwo = getFileXml('src/two.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const fileThree = getFileXml('src/three.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
@@ -170,3 +154,3 @@ const xmlReport = wrapXmlReport(` | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -198,5 +182,5 @@ | ||
it('only includes rows that have been created or modified', async () => { | ||
const fileOne = getFileXml('src/one.js', defautMetrics, [defaultLine]); | ||
const fileTwo = getFileXml('src/two.js', defautMetrics, [defaultLine]); | ||
const fileThree = getFileXml('src/three.js', defautMetrics, [defaultLine]); | ||
const fileOne = getFileXml('src/one.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const fileTwo = getFileXml('src/two.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const fileThree = getFileXml('src/three.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const xmlReport = wrapXmlReport([ | ||
@@ -209,3 +193,3 @@ fileOne, | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -231,7 +215,9 @@ | ||
it('adds any extra rows to a details block', async () => { | ||
const files = new Array(10).fill().map((_, i) => getFileXml(i, defautMetrics, [defaultLine])); | ||
const files = new Array(10).fill().map((_, i) => ( | ||
getFileXml(i, DEFAULT_METRICS, [DEFAULT_LINE]) | ||
)); | ||
const xmlReport = wrapXmlReport(files.join('\n')); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -264,3 +250,3 @@ | ||
coveredmethods: 0, | ||
}, [defaultLine]); | ||
}, [DEFAULT_LINE]); | ||
@@ -270,3 +256,3 @@ const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -304,3 +290,3 @@ | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -328,3 +314,3 @@ | ||
const longPath = new Array(10).fill(seg).join('/'); | ||
const file = getFileXml(longPath, defautMetrics, [defaultLine]); | ||
const file = getFileXml(longPath, DEFAULT_METRICS, [DEFAULT_LINE]); | ||
@@ -334,3 +320,3 @@ const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -365,3 +351,3 @@ | ||
coveredmethods: 2, | ||
}, [defaultLine]); | ||
}, [DEFAULT_LINE]); | ||
@@ -371,3 +357,3 @@ const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -395,4 +381,4 @@ | ||
it('includes a link to the committed file', async () => { | ||
const fileOne = getFileXml('src/one.js', defautMetrics, [defaultLine]); | ||
const fileTwo = getFileXml('src/two.js', defautMetrics, [defaultLine]); | ||
const fileOne = getFileXml('src/one.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const fileTwo = getFileXml('src/two.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
@@ -405,3 +391,3 @@ const xmlReport = wrapXmlReport([ | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -436,3 +422,3 @@ | ||
it('does not report anything if no coverage reported for the files changed', async () => { | ||
const fileOne = getFileXml('src/one.js', defautMetrics, [defaultLine]); | ||
const fileOne = getFileXml('src/one.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
@@ -442,3 +428,3 @@ const xmlReport = wrapXmlReport([fileOne].join('\n')); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -460,3 +446,3 @@ | ||
it('handles relative paths correctly', async () => { | ||
const fileOne = getFileXml(path.join(process.cwd(), '/src/index.js'), defautMetrics, [defaultLine]); | ||
const fileOne = getFileXml(path.join(process.cwd(), '/src/index.js'), DEFAULT_METRICS, [DEFAULT_LINE]); | ||
@@ -466,3 +452,3 @@ const xmlReport = wrapXmlReport([fileOne].join('\n')); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -469,0 +455,0 @@ |
@@ -5,2 +5,3 @@ import path from 'path'; | ||
import coverage from '../../src'; | ||
import { CLOVER_PATH, DEFAULT_METRICS, DEFAULT_LINE } from '../constants'; | ||
import { | ||
@@ -13,19 +14,2 @@ getFileXml, | ||
const cloverPath = path.join(process.cwd(), 'coverage', 'clover.xml'); | ||
const defautMetrics = { | ||
statements: 10, | ||
coveredstatements: 10, | ||
conditionals: 10, | ||
coveredconditionals: 10, | ||
methods: 10, | ||
coveredmethods: 10, | ||
}; | ||
const defaultLine = { | ||
num: 1, | ||
count: 1, | ||
type: 'stmt', | ||
}; | ||
describe('Settings', () => { | ||
@@ -39,7 +23,7 @@ beforeEach(setupEnv); | ||
it('reports with a custom success message', async () => { | ||
const file = getFileXml('src/one.js', defautMetrics, [defaultLine]); | ||
const file = getFileXml('src/one.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -72,7 +56,7 @@ | ||
coveredmethods: 0, | ||
}, [defaultLine]); | ||
}, [DEFAULT_LINE]); | ||
const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -98,3 +82,3 @@ | ||
it('loads the report from a custom path', async () => { | ||
const file = getFileXml('from-custom-report.js', defautMetrics, [defaultLine]); | ||
const file = getFileXml('from-custom-report.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const xmlReport = wrapXmlReport(file); | ||
@@ -124,7 +108,9 @@ | ||
it('limits the number of rows', async () => { | ||
const files = new Array(10).fill().map((_, i) => getFileXml(i, defautMetrics, [defaultLine])); | ||
const files = new Array(10).fill().map((_, i) => ( | ||
getFileXml(i, DEFAULT_METRICS, [DEFAULT_LINE]) | ||
)); | ||
const xmlReport = wrapXmlReport(files.join('\n')); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -149,7 +135,7 @@ | ||
it('shows all files', async () => { | ||
const file = getFileXml('src/one.js', defautMetrics, [defaultLine]); | ||
const file = getFileXml('src/one.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -196,3 +182,3 @@ | ||
mockFs({ | ||
[cloverPath]: xmlReport, | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
@@ -199,0 +185,0 @@ |
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
53356
24
1275
110