github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/web/src/mixins/report.ts (about) 1 import { Component } from 'vue-property-decorator'; 2 import Vue from '@/vue'; 3 4 @Component 5 export default class ReportMixin extends Vue { 6 get $report(): Report | undefined { 7 return this.$store.state.report.current; 8 } 9 10 get $coverage(): number { 11 if (this.$report === undefined) { 12 return 0; 13 } 14 if (this.$report.coverages === undefined || this.$report.coverages.length <= 0) { 15 return 0; 16 } 17 let sum = 0; 18 for (const coverage of this.$report.coverages) { 19 sum += coverage.statementCoverage; 20 } 21 return Math.round(sum / this.$report.coverages.length * 10000) / 100; 22 } 23 24 get $sourceFiles(): Record<string, SourceFile> { 25 if (this.$report?.coverages === undefined) { 26 return {}; 27 } 28 const records = {} as Record<string, SourceFile>; 29 for (const coverage of this.$report?.coverages) { 30 if (coverage.files === undefined) { 31 continue; 32 } 33 for (const file of coverage.files) { 34 records[file.Name] = file; 35 } 36 } 37 return records; 38 } 39 40 findSourceFile(name: string): SourceFile | undefined { 41 return this.$sourceFiles[name]; 42 } 43 }