mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 14:27:10 +01:00
good start
This commit is contained in:
parent
08c81a1fd6
commit
713455873c
6 changed files with 301 additions and 0 deletions
45
__tests__/__outputs__/lcov-report-results.md
Normal file
45
__tests__/__outputs__/lcov-report-results.md
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|

|
||||||
|
## ❌ <a id="user-content-r0" href="#r0">fixtures/lcov.json</a>
|
||||||
|
**15** tests were completed in **0ms** with **7** passed, **8** failed and **0** skipped.
|
||||||
|
|Test suite|Passed|Failed|Skipped|Time|
|
||||||
|
|:---|---:|---:|---:|---:|
|
||||||
|
|[src/core/dao.service.ts](#r0s0)|3✅|||0ms|
|
||||||
|
|[src/domains/auth/auth.controller.ts](#r0s1)|2✅|1❌||0ms|
|
||||||
|
|[src/shared/notif/providers/fcm/fcm.service.spec.ts](#r0s2)||3❌||0ms|
|
||||||
|
|[src/shared/notif/providers/fcm/fcm.service.ts](#r0s3)|1✅|2❌||0ms|
|
||||||
|
|[src/shared/notif/providers/mail/mail-service.ts](#r0s4)|1✅|2❌||0ms|
|
||||||
|
### ✅ <a id="user-content-r0s0" href="#r0s0">src/core/dao.service.ts</a>
|
||||||
|
```
|
||||||
|
src/core/dao.service.ts
|
||||||
|
✅ statement
|
||||||
|
✅ fonction
|
||||||
|
✅ branche
|
||||||
|
```
|
||||||
|
### ❌ <a id="user-content-r0s1" href="#r0s1">src/domains/auth/auth.controller.ts</a>
|
||||||
|
```
|
||||||
|
src/domains/auth/auth.controller.ts
|
||||||
|
✅ statement
|
||||||
|
❌ fonction
|
||||||
|
✅ branche
|
||||||
|
```
|
||||||
|
### ❌ <a id="user-content-r0s2" href="#r0s2">src/shared/notif/providers/fcm/fcm.service.spec.ts</a>
|
||||||
|
```
|
||||||
|
src/shared/notif/providers/fcm/fcm.service.spec.ts
|
||||||
|
❌ statement
|
||||||
|
❌ fonction
|
||||||
|
❌ branche
|
||||||
|
```
|
||||||
|
### ❌ <a id="user-content-r0s3" href="#r0s3">src/shared/notif/providers/fcm/fcm.service.ts</a>
|
||||||
|
```
|
||||||
|
src/shared/notif/providers/fcm/fcm.service.ts
|
||||||
|
❌ statement
|
||||||
|
❌ fonction
|
||||||
|
✅ branche
|
||||||
|
```
|
||||||
|
### ❌ <a id="user-content-r0s4" href="#r0s4">src/shared/notif/providers/mail/mail-service.ts</a>
|
||||||
|
```
|
||||||
|
src/shared/notif/providers/mail/mail-service.ts
|
||||||
|
❌ statement
|
||||||
|
❌ fonction
|
||||||
|
✅ branche
|
||||||
|
```
|
||||||
140
__tests__/__snapshots__/lcov.test.ts.snap
Normal file
140
__tests__/__snapshots__/lcov.test.ts.snap
Normal file
|
|
@ -0,0 +1,140 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`lcov report coverage report from facebook/jest test results matches snapshot 1`] = `
|
||||||
|
TestRunResult {
|
||||||
|
"path": "fixtures/lcov.json",
|
||||||
|
"suites": Array [
|
||||||
|
TestSuiteResult {
|
||||||
|
"groups": Array [
|
||||||
|
TestGroupResult {
|
||||||
|
"name": "src/core/dao.service.ts",
|
||||||
|
"tests": Array [
|
||||||
|
Object {
|
||||||
|
"name": "statement",
|
||||||
|
"result": "success",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "fonction",
|
||||||
|
"result": "success",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "branche",
|
||||||
|
"result": "success",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "src/core/dao.service.ts",
|
||||||
|
"totalTime": undefined,
|
||||||
|
},
|
||||||
|
TestSuiteResult {
|
||||||
|
"groups": Array [
|
||||||
|
TestGroupResult {
|
||||||
|
"name": "src/domains/auth/auth.controller.ts",
|
||||||
|
"tests": Array [
|
||||||
|
Object {
|
||||||
|
"name": "statement",
|
||||||
|
"result": "success",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "fonction",
|
||||||
|
"result": "failed",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "branche",
|
||||||
|
"result": "success",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "src/domains/auth/auth.controller.ts",
|
||||||
|
"totalTime": undefined,
|
||||||
|
},
|
||||||
|
TestSuiteResult {
|
||||||
|
"groups": Array [
|
||||||
|
TestGroupResult {
|
||||||
|
"name": "src/shared/notif/providers/fcm/fcm.service.spec.ts",
|
||||||
|
"tests": Array [
|
||||||
|
Object {
|
||||||
|
"name": "statement",
|
||||||
|
"result": "failed",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "fonction",
|
||||||
|
"result": "failed",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "branche",
|
||||||
|
"result": "failed",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "src/shared/notif/providers/fcm/fcm.service.spec.ts",
|
||||||
|
"totalTime": undefined,
|
||||||
|
},
|
||||||
|
TestSuiteResult {
|
||||||
|
"groups": Array [
|
||||||
|
TestGroupResult {
|
||||||
|
"name": "src/shared/notif/providers/fcm/fcm.service.ts",
|
||||||
|
"tests": Array [
|
||||||
|
Object {
|
||||||
|
"name": "statement",
|
||||||
|
"result": "failed",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "fonction",
|
||||||
|
"result": "failed",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "branche",
|
||||||
|
"result": "success",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "src/shared/notif/providers/fcm/fcm.service.ts",
|
||||||
|
"totalTime": undefined,
|
||||||
|
},
|
||||||
|
TestSuiteResult {
|
||||||
|
"groups": Array [
|
||||||
|
TestGroupResult {
|
||||||
|
"name": "src/shared/notif/providers/mail/mail-service.ts",
|
||||||
|
"tests": Array [
|
||||||
|
Object {
|
||||||
|
"name": "statement",
|
||||||
|
"result": "failed",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "fonction",
|
||||||
|
"result": "failed",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"name": "branche",
|
||||||
|
"result": "success",
|
||||||
|
"time": 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"name": "src/shared/notif/providers/mail/mail-service.ts",
|
||||||
|
"totalTime": undefined,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"totalTime": undefined,
|
||||||
|
}
|
||||||
|
`;
|
||||||
6
__tests__/fixtures/lcov.json
Normal file
6
__tests__/fixtures/lcov.json
Normal file
File diff suppressed because one or more lines are too long
25
__tests__/lcov.test.ts
Normal file
25
__tests__/lcov.test.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import * as path from 'path'
|
||||||
|
|
||||||
|
import {getReport} from '../src/report/get-report'
|
||||||
|
import {normalizeFilePath} from '../src/utils/path-utils'
|
||||||
|
import { LcovParser } from "../src/parsers/lcov-json/lcov-parser";
|
||||||
|
|
||||||
|
describe('lcov report coverage', () => {
|
||||||
|
|
||||||
|
it('report from facebook/jest test results matches snapshot', async () => {
|
||||||
|
const fixturePath = path.join(__dirname, 'fixtures', 'lcov.json')
|
||||||
|
const outputPath = path.join(__dirname, '__outputs__', 'lcov-report-results.md')
|
||||||
|
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
|
||||||
|
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})
|
||||||
|
|
||||||
|
|
||||||
|
const parser = new LcovParser()
|
||||||
|
const result = await parser.parse(filePath, fileContent)
|
||||||
|
expect(result).toMatchSnapshot()
|
||||||
|
|
||||||
|
const report = getReport([result])
|
||||||
|
fs.mkdirSync(path.dirname(outputPath), {recursive: true})
|
||||||
|
fs.writeFileSync(outputPath, report)
|
||||||
|
})
|
||||||
|
})
|
||||||
64
src/parsers/lcov-json/lcov-parser.ts
Normal file
64
src/parsers/lcov-json/lcov-parser.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import {ParseOptions, TestParser} from '../../test-parser'
|
||||||
|
|
||||||
|
import {TestCaseResult, TestGroupResult, TestRunResult, TestSuiteResult} from '../../test-results'
|
||||||
|
import {CovParsedStat, CovStats, LcovReport} from './lcov-types'
|
||||||
|
|
||||||
|
export class LcovParser implements TestParser {
|
||||||
|
async parse(path: string, content: string): Promise<TestRunResult> {
|
||||||
|
const report = this.parseFile(path, content)
|
||||||
|
return this.getTestRunResult(path, report)
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseFile(path: string, content: string): LcovReport {
|
||||||
|
try {
|
||||||
|
return JSON.parse(content) as LcovReport
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`Invalid JSON at ${path}\n\n${e}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private async getTestRunResult(path: string, report: LcovReport): Promise<TestRunResult> {
|
||||||
|
const suites: TestSuiteResult[] = []
|
||||||
|
|
||||||
|
for (const key of Object.keys(report)) {
|
||||||
|
const s: CovParsedStat = this.getParsedStat(report[key].s)
|
||||||
|
const f: CovParsedStat = this.getParsedStat(report[key].f)
|
||||||
|
const b: CovParsedStat = this.getParsedStat(report[key].b)
|
||||||
|
|
||||||
|
const statementCaseResult: TestCaseResult = {
|
||||||
|
name: 'statement',
|
||||||
|
time: 0,
|
||||||
|
result: s.percentage >= 80 ? 'success' : 'failed'
|
||||||
|
}
|
||||||
|
const fonctionCaseResult: TestCaseResult = {
|
||||||
|
name: 'fonction',
|
||||||
|
time: 0,
|
||||||
|
result: f.percentage >= 80 ? 'success' : 'failed'
|
||||||
|
}
|
||||||
|
const brancheCaseResult: TestCaseResult = {
|
||||||
|
name: 'branche',
|
||||||
|
time: 0,
|
||||||
|
result: b.percentage >= 80 ? 'success' : 'failed'
|
||||||
|
}
|
||||||
|
|
||||||
|
const testCases: TestCaseResult[] = [statementCaseResult, fonctionCaseResult, brancheCaseResult]
|
||||||
|
const goups: TestGroupResult[] = [new TestGroupResult(key, testCases)]
|
||||||
|
const suite: TestSuiteResult = new TestSuiteResult(key, goups)
|
||||||
|
|
||||||
|
suites.push(suite)
|
||||||
|
console.log({key, s, f, b})
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TestRunResult(path, suites)
|
||||||
|
}
|
||||||
|
|
||||||
|
private getParsedStat(stat: CovStats): CovParsedStat {
|
||||||
|
const max = Object.keys(stat).length
|
||||||
|
const nonCovered = this.zeroLength(stat)
|
||||||
|
const percentage = ((max - nonCovered) / max) * 100
|
||||||
|
|
||||||
|
return {max, nonCovered, percentage}
|
||||||
|
}
|
||||||
|
private zeroLength(report: CovStats): number {
|
||||||
|
return Object.keys(report).filter(key => report[key] === 0).length
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/parsers/lcov-json/lcov-types.ts
Normal file
21
src/parsers/lcov-json/lcov-types.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
export interface LcovReport {
|
||||||
|
[str: string]: {
|
||||||
|
path: string
|
||||||
|
statementMap: unknown
|
||||||
|
fnMap: unknown
|
||||||
|
branchMap: unknown
|
||||||
|
s: CovStats
|
||||||
|
f: CovStats
|
||||||
|
b: CovStats
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CovStats {
|
||||||
|
[str: string]: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CovParsedStat {
|
||||||
|
max: number
|
||||||
|
nonCovered: number
|
||||||
|
percentage: number
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue