danger-plugin-coverage
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -228,3 +228,3 @@ "use strict"; | ||
const getRelevantFiles = (coverageXml, showAllFiles, warnOnMissingFiles) => { | ||
const getRelevantFiles = (coverageXml, showAllFiles) => { | ||
var _danger$git2, _danger$git3; | ||
@@ -234,5 +234,3 @@ | ||
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)); | ||
@@ -243,7 +241,2 @@ if (showAllFiles) { | ||
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; | ||
@@ -263,3 +256,2 @@ }; | ||
warnOnNoReport = true, | ||
warnOnMissingFiles = true, | ||
threshold = { | ||
@@ -282,3 +274,3 @@ statements: 80, | ||
const relevantFiles = getRelevantFiles(coverageXml, showAllFiles, warnOnMissingFiles); | ||
const relevantFiles = getRelevantFiles(coverageXml, showAllFiles); | ||
@@ -285,0 +277,0 @@ if (!relevantFiles.length) { |
{ | ||
"name": "danger-plugin-coverage", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "A Danger plugin to report code coverage.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -88,3 +88,2 @@ # danger-plugin-coverage | ||
| `warnOnNoReport` | Show a warning if no coverage report was detected. | | ||
| `warnOnMissingFiles` | Show a warning if modified files are missing from the coverage report. | | ||
@@ -100,3 +99,2 @@ **Example:** | ||
warnOnNoReport: true, | ||
warnOnMissingFiles: true, | ||
cloverReportPath: './coverage/clover.xml', | ||
@@ -103,0 +101,0 @@ maxRows: 5, |
@@ -261,3 +261,3 @@ import path from 'path'; | ||
*/ | ||
const getRelevantFiles = (coverageXml, showAllFiles, warnOnMissingFiles) => { | ||
const getRelevantFiles = (coverageXml, showAllFiles) => { | ||
const files = getFlatFiles(coverageXml); | ||
@@ -269,4 +269,2 @@ const allFiles = [ | ||
const filePaths = files.map((file) => path.relative(process.cwd(), file.$.path)); | ||
const relevantFiles = files.filter((file) => ( | ||
@@ -276,4 +274,2 @@ allFiles.includes(path.relative(process.cwd(), file.$.path)) | ||
const missingFiles = allFiles.filter((file) => !filePaths.includes(file)); | ||
if (showAllFiles) { | ||
@@ -283,14 +279,2 @@ return files; | ||
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; | ||
@@ -310,3 +294,2 @@ }; | ||
warnOnNoReport = true, | ||
warnOnMissingFiles = true, | ||
threshold = { | ||
@@ -329,3 +312,3 @@ statements: 80, | ||
const relevantFiles = getRelevantFiles(coverageXml, showAllFiles, warnOnMissingFiles); | ||
const relevantFiles = getRelevantFiles(coverageXml, showAllFiles); | ||
@@ -332,0 +315,0 @@ if (!relevantFiles.length) { |
import mockFs from 'mock-fs'; | ||
import coverage from '../../src'; | ||
import { CLOVER_PATH, DEFAULT_METRICS, DEFAULT_LINE } from '../constants'; | ||
import { | ||
getFileXml, | ||
setupEnv, | ||
wrapXmlReport, | ||
} from '../utils'; | ||
import { setupEnv } from '../utils'; | ||
@@ -52,47 +47,2 @@ describe('Warnings', () => { | ||
}); | ||
it('warns if files missing from report', async () => { | ||
const file = getFileXml('src/one.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
Object.assign(danger, { | ||
git: { | ||
created_files: ['src/one.js', 'src/two.js'], | ||
modified_files: ['src/three.js'], | ||
}, | ||
}); | ||
await coverage(); | ||
const [warning] = warn.mock.calls?.[0] || []; | ||
expect(warning).toMatch(/.*no data on 2 files.*/); | ||
expect(warning).toMatchSnapshot(); | ||
}); | ||
it('does not log any warnings on missing files if disabled', async () => { | ||
const file = getFileXml('src/one.js', DEFAULT_METRICS, [DEFAULT_LINE]); | ||
const xmlReport = wrapXmlReport(file); | ||
mockFs({ | ||
[CLOVER_PATH]: xmlReport, | ||
}); | ||
Object.assign(danger, { | ||
git: { | ||
created_files: ['src/one.js', 'src/two.js'], | ||
modified_files: ['src/three.js'], | ||
}, | ||
}); | ||
await coverage({ warnOnMissingFiles: false }); | ||
const [warning] = warn.mock.calls?.[0] || []; | ||
expect(warning).toBeUndefined(); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
50526
1216
108