|
1 | 1 | /* v8 ignore next 1000 */ |
2 | 2 |
|
3 | | -import { parseString } from 'xml2js'; |
4 | | -import { readFile } from 'fs'; |
5 | | - |
6 | | -function parseXMLFile(): Promise<any> { |
7 | | - return new Promise((resolve, reject) => { |
8 | | - readFile('.github/coverageData.xml', 'utf8', (err, data) => { |
9 | | - if (err) { |
10 | | - reject('File Dose not exist!'); |
11 | | - return; |
12 | | - } |
13 | | - |
14 | | - parseString(data, (err, result) => { |
15 | | - if (err) { |
16 | | - reject('Something Went wrong!'); |
17 | | - return; |
18 | | - } |
19 | | - |
20 | | - resolve(result); |
21 | | - }); |
22 | | - }); |
23 | | - }); |
24 | | -} |
| 3 | +import { parseStringPromise } from 'xml2js'; |
| 4 | +import { readFileSync } from 'fs'; |
| 5 | + |
| 6 | +const coverageDataFile = readFileSync('./coverage/clover.xml', 'utf-8'); |
| 7 | +const parsed = await parseStringPromise(coverageDataFile); |
25 | 8 |
|
26 | | -const data = await parseXMLFile(); |
27 | | -const codeStats = data.coverage.project[0].metrics[0].$; |
| 9 | +const codeStats = parsed.coverage.project[0].metrics[0].$; |
28 | 10 | const info = { |
29 | 11 | statements: Number(codeStats.statements), |
30 | | - coveredstatements: Number(codeStats.coveredstatements), |
| 12 | + coveredStatements: Number(codeStats.coveredstatements), |
31 | 13 | conditionals: Number(codeStats.conditionals), |
32 | | - coveredconditionals: Number(codeStats.coveredconditionals), |
| 14 | + coveredConditionals: Number(codeStats.coveredconditionals), |
33 | 15 | methods: Number(codeStats.methods), |
34 | | - coveredmethods: Number(codeStats.coveredmethods) |
| 16 | + coveredMethods: Number(codeStats.coveredmethods) |
35 | 17 | }; |
36 | 18 |
|
37 | | -if ((info.coveredstatements / info.statements) * 100 < 95) { |
38 | | - throw new Error('Statements is required to be 95% or higher'); |
| 19 | +const baseline = 95; |
| 20 | + |
| 21 | +const statementsCoverage = (info.coveredStatements / info.statements) * 100; |
| 22 | +if (statementsCoverage <= baseline) { |
| 23 | + console.log(`Statements is required to be ${baseline}% or higher. Currently ${statementsCoverage.toFixed(2)}`); |
| 24 | + process.exit(); |
39 | 25 | } |
40 | 26 |
|
41 | | -if ((info.coveredconditionals / info.conditionals) * 100 < 95) { |
42 | | - throw new Error('Conditionals is required to be 95% or higher'); |
| 27 | +const conditionalsCoverage = (info.coveredConditionals / info.conditionals) * 100; |
| 28 | +if (conditionalsCoverage <= baseline) { |
| 29 | + console.log(`Conditionals is required to be ${baseline}% or higher. Currently ${conditionalsCoverage.toFixed(2)}`); |
| 30 | + process.exit(); |
43 | 31 | } |
44 | 32 |
|
45 | | -if ((info.coveredmethods / info.methods) * 100 < 95) { |
46 | | - throw new Error('Methods is required to be 95% or higher'); |
| 33 | +const methodsCoverage = (info.coveredMethods / info.methods) * 100; |
| 34 | +if (methodsCoverage <= baseline) { |
| 35 | + console.log(`Methods is required to be ${baseline}% or higher. Currently ${methodsCoverage.toFixed(2)}`); |
| 36 | + process.exit(); |
47 | 37 | } |
48 | 38 |
|
49 | | -if ( |
50 | | - ((info.coveredstatements + info.coveredconditionals + info.coveredmethods) / |
51 | | - (info.statements + info.conditionals + info.methods)) * |
52 | | - 100 < |
53 | | - 95 |
54 | | -) { |
55 | | - throw new Error('Everythng Combinded is required to be 95% or higher'); |
| 39 | +const combinedCoverage = statementsCoverage + conditionalsCoverage + methodsCoverage; |
| 40 | +if (combinedCoverage <= baseline) { |
| 41 | + console.log(`Everything Combined is required to be ${baseline}% or higher. Currently ${combinedCoverage.toFixed(2)}`); |
| 42 | + process.exit(); |
56 | 43 | } |
0 commit comments