@@ -39,19 +15,26 @@ export function Line({ lines, newlines }) {
key={index}
style={{ display: 'flex', marginRight: '10px', color: '#00000080' }}
>
-
+
{newlines.includes(index + 1) ? '+' : null}
{line.executionNumber > 0 ? line.executionNumber + 'x' : null}
{index + 1}
diff --git a/packages/canyon-report/src/Report/components/helpers.ts b/packages/canyon-report/src/Report/components/helpers.ts
index 85b3bbd2..4263aa29 100644
--- a/packages/canyon-report/src/Report/components/helpers.ts
+++ b/packages/canyon-report/src/Report/components/helpers.ts
@@ -1,5 +1,4 @@
export function CoreFn({ fileCoverage, fileContent }) {
- console.log(fileCoverage,fileContent)
if (!fileCoverage.s) {
return {
times: [],
@@ -55,8 +54,6 @@ export function CoreFn({ fileCoverage, fileContent }) {
// 这边计算出了行的次数!!!!!!
});
- // console.log(rows,numberOfRows,'rows')
-
const zuizhong = [];
for (let i = 0; i < rows.length; i++) {
diff --git a/packages/canyon-report/src/Report/init.tsx b/packages/canyon-report/src/Report/init.tsx
index d4b87cad..d989b441 100644
--- a/packages/canyon-report/src/Report/init.tsx
+++ b/packages/canyon-report/src/Report/init.tsx
@@ -2,15 +2,8 @@ import { render } from 'preact';
import IstanbulReport from './components/IstanbulReport';
import { loadCssCode } from './loadcss';
-import { OnSelectFile, Watermarks } from './types';
-function noop(
- path: string,
-): Promise<{ fileContent: string; fileCoverage: any }> {
- console.log(path, 'path');
- return new Promise((resolve) => {
- resolve({ fileCoverage: {}, fileContent: `` });
- });
-}
+import { OnSelectFile } from './types';
+
const configWatermarks = {
statements: [50, 80],
functions: [50, 80],
@@ -19,14 +12,14 @@ const configWatermarks = {
};
const init = (
dom: HTMLElement,
- {
- onSelectFile = noop,
- watermarks = configWatermarks,
- }: { onSelectFile: OnSelectFile; watermarks: Watermarks },
+ { onSelectFile }: { onSelectFile: OnSelectFile },
) => {
loadCssCode();
render(
-
,
+
,
dom!,
);
return {
diff --git a/packages/canyon-report/src/helper.ts b/packages/canyon-report/src/helper.ts
new file mode 100644
index 00000000..b92b481e
--- /dev/null
+++ b/packages/canyon-report/src/helper.ts
@@ -0,0 +1,19 @@
+import { Dims } from './Report';
+
+export const classForPercent = (
+ type: Dims,
+ value: number,
+ _watermarks: any,
+) => {
+ const watermarks = _watermarks[type];
+ if (!watermarks) {
+ return 'unknown';
+ }
+ if (value < watermarks[0]) {
+ return 'low';
+ }
+ if (value >= watermarks[1]) {
+ return 'high';
+ }
+ return 'medium';
+};
diff --git a/packages/canyon-report/src/main.tsx b/packages/canyon-report/src/main.tsx
index 516ccaae..bef3bb26 100644
--- a/packages/canyon-report/src/main.tsx
+++ b/packages/canyon-report/src/main.tsx
@@ -1,9 +1,9 @@
-import './reset.css'
-import { formatCoverageMap, genSummaryMapByCoverageMap } from '@canyon/data';
+import './reset.css';
+
+import { genSummaryMapByCoverageMap } from '@canyon/data';
import { init } from './index';
-import mockCoverageData from './mock-coverage-data.json';
-import {__coverage__, __filecontent__} from "./mock.ts";
+import { __coverage__, __filecontent__ } from './mock.ts';
function getDecode(str: string) {
return decodeURIComponent(
@@ -16,26 +16,18 @@ function getDecode(str: string) {
);
}
-const configWatermarks = {
- statements: [50, 80],
- functions: [50, 80],
- branches: [50, 80],
- lines: [50, 80],
-};
const report = init(document.querySelector('#root') as any, {
onSelectFile(path: string) {
- console.log(path, 'path');
return new Promise((resolve) => {
resolve({
- fileCoverage: __coverage__[path.replace('~/', '')],
- fileContent: getDecode(__filecontent__[path.replace('~/', '')]),
+ // @ts-ignore
+ fileCoverage: __coverage__[path],
+ // @ts-ignore
+ fileContent: getDecode(__filecontent__[path]),
});
});
},
- watermarks: configWatermarks,
});
report.setOption({
- summary: genSummaryMapByCoverageMap(
- formatCoverageMap(mockCoverageData, '/builds/canyon/canyon-demo'),
- ),
+ summary: genSummaryMapByCoverageMap(__coverage__),
});
diff --git a/packages/canyon-report/src/mock-coverage-data.json b/packages/canyon-report/src/mock-coverage-data.json
deleted file mode 100644
index bfcdff24..00000000
--- a/packages/canyon-report/src/mock-coverage-data.json
+++ /dev/null
@@ -1,536 +0,0 @@
-{
- "/builds/canyon/canyon-demo/src/pages/Welcome.tsx": {
- "path": "/builds/canyon/canyon-demo/src/pages/Welcome.tsx",
- "statementMap": {
- "0": {
- "start": {
- "line": 3,
- "column": 16
- },
- "end": {
- "line": 10,
- "column": 1
- }
- },
- "1": {
- "start": {
- "line": 4,
- "column": 17
- },
- "end": {
- "line": 4,
- "column": 30
- }
- },
- "2": {
- "start": {
- "line": 5,
- "column": 0
- },
- "end": {
- "line": 9,
- "column": 6
- }
- },
- "3": {
- "start": {
- "line": 7,
- "column": 8
- },
- "end": {
- "line": 7,
- "column": 20
- }
- }
- },
- "fnMap": {
- "0": {
- "name": "(anonymous_0)",
- "decl": {
- "start": {
- "line": 3,
- "column": 16
- },
- "end": {
- "line": 3,
- "column": 17
- }
- },
- "loc": {
- "start": {
- "line": 3,
- "column": 22
- },
- "end": {
- "line": 10,
- "column": 1
- }
- },
- "line": 3
- },
- "1": {
- "name": "(anonymous_1)",
- "decl": {
- "start": {
- "line": 6,
- "column": 21
- },
- "end": {
- "line": 6,
- "column": 22
- }
- },
- "loc": {
- "start": {
- "line": 6,
- "column": 25
- },
- "end": {
- "line": 8,
- "column": 5
- }
- },
- "line": 6
- }
- },
- "branchMap": {},
- "s": {
- "0": 1,
- "1": 0,
- "2": 0,
- "3": 0
- },
- "f": {
- "0": 0,
- "1": 0
- },
- "b": {},
- "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
- "hash": "44a06ed36306fbbfd189234db0541dd6d0488999"
- },
- "/builds/canyon/canyon-demo/src/pages/Home.tsx": {
- "path": "/builds/canyon/canyon-demo/src/pages/Home.tsx",
- "statementMap": {
- "0": {
- "start": {
- "line": 4,
- "column": 30
- },
- "end": {
- "line": 4,
- "column": 41
- }
- },
- "1": {
- "start": {
- "line": 6,
- "column": 4
- },
- "end": {
- "line": 6,
- "column": 27
- }
- },
- "2": {
- "start": {
- "line": 8,
- "column": 8
- },
- "end": {
- "line": 13,
- "column": 9
- }
- },
- "3": {
- "start": {
- "line": 9,
- "column": 12
- },
- "end": {
- "line": 9,
- "column": 39
- }
- },
- "4": {
- "start": {
- "line": 11,
- "column": 12
- },
- "end": {
- "line": 11,
- "column": 37
- }
- },
- "5": {
- "start": {
- "line": 12,
- "column": 12
- },
- "end": {
- "line": 12,
- "column": 31
- }
- },
- "6": {
- "start": {
- "line": 15,
- "column": 4
- },
- "end": {
- "line": 35,
- "column": 5
- }
- },
- "7": {
- "start": {
- "line": 18,
- "column": 64
- },
- "end": {
- "line": 18,
- "column": 94
- }
- },
- "8": {
- "start": {
- "line": 18,
- "column": 84
- },
- "end": {
- "line": 18,
- "column": 93
- }
- },
- "9": {
- "start": {
- "line": 24,
- "column": 20
- },
- "end": {
- "line": 24,
- "column": 53
- }
- },
- "10": {
- "start": {
- "line": 29,
- "column": 20
- },
- "end": {
- "line": 29,
- "column": 43
- }
- }
- },
- "fnMap": {
- "0": {
- "name": "Home",
- "decl": {
- "start": {
- "line": 3,
- "column": 9
- },
- "end": {
- "line": 3,
- "column": 13
- }
- },
- "loc": {
- "start": {
- "line": 3,
- "column": 16
- },
- "end": {
- "line": 36,
- "column": 1
- }
- },
- "line": 3
- },
- "1": {
- "name": "tips",
- "decl": {
- "start": {
- "line": 7,
- "column": 13
- },
- "end": {
- "line": 7,
- "column": 17
- }
- },
- "loc": {
- "start": {
- "line": 7,
- "column": 28
- },
- "end": {
- "line": 14,
- "column": 5
- }
- },
- "line": 7
- },
- "2": {
- "name": "(anonymous_2)",
- "decl": {
- "start": {
- "line": 18,
- "column": 58
- },
- "end": {
- "line": 18,
- "column": 59
- }
- },
- "loc": {
- "start": {
- "line": 18,
- "column": 64
- },
- "end": {
- "line": 18,
- "column": 94
- }
- },
- "line": 18
- },
- "3": {
- "name": "(anonymous_3)",
- "decl": {
- "start": {
- "line": 18,
- "column": 73
- },
- "end": {
- "line": 18,
- "column": 74
- }
- },
- "loc": {
- "start": {
- "line": 18,
- "column": 84
- },
- "end": {
- "line": 18,
- "column": 93
- }
- },
- "line": 18
- },
- "4": {
- "name": "(anonymous_4)",
- "decl": {
- "start": {
- "line": 23,
- "column": 45
- },
- "end": {
- "line": 23,
- "column": 46
- }
- },
- "loc": {
- "start": {
- "line": 23,
- "column": 49
- },
- "end": {
- "line": 25,
- "column": 17
- }
- },
- "line": 23
- },
- "5": {
- "name": "(anonymous_5)",
- "decl": {
- "start": {
- "line": 28,
- "column": 46
- },
- "end": {
- "line": 28,
- "column": 47
- }
- },
- "loc": {
- "start": {
- "line": 28,
- "column": 50
- },
- "end": {
- "line": 30,
- "column": 17
- }
- },
- "line": 28
- }
- },
- "branchMap": {
- "0": {
- "loc": {
- "start": {
- "line": 8,
- "column": 8
- },
- "end": {
- "line": 13,
- "column": 9
- }
- },
- "type": "if",
- "locations": [
- {
- "start": {
- "line": 8,
- "column": 8
- },
- "end": {
- "line": 13,
- "column": 9
- }
- },
- {
- "start": {
- "line": 10,
- "column": 15
- },
- "end": {
- "line": 13,
- "column": 9
- }
- }
- ],
- "line": 8
- }
- },
- "s": {
- "0": 1,
- "1": 1,
- "2": 1,
- "3": 0,
- "4": 1,
- "5": 1,
- "6": 1,
- "7": 0,
- "8": 0,
- "9": 0,
- "10": 0
- },
- "f": {
- "0": 1,
- "1": 1,
- "2": 0,
- "3": 0,
- "4": 0,
- "5": 0
- },
- "b": {
- "0": [
- 0,
- 1
- ]
- },
- "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
- "hash": "94acebb40f91fa6aab2be22d5f32d9b020aefe85"
- },
- "/builds/canyon/canyon-demo/src/routers/index.tsx": {
- "path": "/builds/canyon/canyon-demo/src/routers/index.tsx",
- "statementMap": {},
- "fnMap": {},
- "branchMap": {},
- "s": {},
- "f": {},
- "b": {},
- "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
- "hash": "331bbffdd38304ac26edcd0f159b967d23f5bdcd"
- },
- "/builds/canyon/canyon-demo/src/App.tsx": {
- "path": "/builds/canyon/canyon-demo/src/App.tsx",
- "statementMap": {
- "0": {
- "start": {
- "line": 7,
- "column": 26
- },
- "end": {
- "line": 7,
- "column": 49
- }
- },
- "1": {
- "start": {
- "line": 8,
- "column": 2
- },
- "end": {
- "line": 12,
- "column": 3
- }
- }
- },
- "fnMap": {
- "0": {
- "name": "App",
- "decl": {
- "start": {
- "line": 6,
- "column": 9
- },
- "end": {
- "line": 6,
- "column": 12
- }
- },
- "loc": {
- "start": {
- "line": 6,
- "column": 15
- },
- "end": {
- "line": 13,
- "column": 1
- }
- },
- "line": 6
- }
- },
- "branchMap": {},
- "s": {
- "0": 1,
- "1": 1
- },
- "f": {
- "0": 1
- },
- "b": {},
- "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
- "hash": "1454065cc7fb2c09d5dcdbb82b046335a719923d"
- },
- "/builds/canyon/canyon-demo/src/main.tsx": {
- "path": "/builds/canyon/canyon-demo/src/main.tsx",
- "statementMap": {
- "0": {
- "start": {
- "line": 7,
- "column": 0
- },
- "end": {
- "line": 12,
- "column": 1
- }
- }
- },
- "fnMap": {},
- "branchMap": {},
- "s": {
- "0": 1
- },
- "f": {},
- "b": {},
- "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
- "hash": "2ca7e398b7e7ea1ee9480ada2f5111a10d111593"
- }
-}
diff --git a/packages/canyon-report/src/mock.ts b/packages/canyon-report/src/mock.ts
index 998ab128..e7dea878 100644
--- a/packages/canyon-report/src/mock.ts
+++ b/packages/canyon-report/src/mock.ts
@@ -1,7 +1,6 @@
-
export const __coverage__ = {
- 'src/pages/Welcome.tsx': {
- path: 'src/pages/Welcome.tsx',
+ '~/src/pages/Welcome.tsx': {
+ path: '~/src/pages/Welcome.tsx',
statementMap: {
'0': {
start: {
@@ -109,8 +108,8 @@ export const __coverage__ = {
_coverageSchema: '1a1c01bbd47fc00a2c39e90264f33305004495a9',
hash: '44a06ed36306fbbfd189234db0541dd6d0488999',
},
- 'src/pages/Home.tsx': {
- path: 'src/pages/Home.tsx',
+ '~/src/pages/Home.tsx': {
+ path: '~/src/pages/Home.tsx',
statementMap: {
'0': {
start: {
@@ -423,8 +422,8 @@ export const __coverage__ = {
_coverageSchema: '1a1c01bbd47fc00a2c39e90264f33305004495a9',
hash: '281cf50578a4f2383ee67388ed5a85fa3354e30c',
},
- 'src/routers/index.tsx': {
- path: 'src/routers/index.tsx',
+ '~/src/routers/index.tsx': {
+ path: '~/src/routers/index.tsx',
statementMap: {},
fnMap: {},
branchMap: {},
@@ -434,8 +433,8 @@ export const __coverage__ = {
_coverageSchema: '1a1c01bbd47fc00a2c39e90264f33305004495a9',
hash: '331bbffdd38304ac26edcd0f159b967d23f5bdcd',
},
- 'src/App.tsx': {
- path: 'src/App.tsx',
+ '~/src/App.tsx': {
+ path: '~/src/App.tsx',
statementMap: {
'0': {
start: {
@@ -496,8 +495,8 @@ export const __coverage__ = {
_coverageSchema: '1a1c01bbd47fc00a2c39e90264f33305004495a9',
hash: '1454065cc7fb2c09d5dcdbb82b046335a719923d',
},
- 'src/main.tsx': {
- path: 'src/main.tsx',
+ '~/src/main.tsx': {
+ path: '~/src/main.tsx',
statementMap: {
'0': {
start: {
@@ -523,14 +522,14 @@ export const __coverage__ = {
};
export const __filecontent__ = {
- 'src/pages/Welcome.tsx':
+ '~/src/pages/Welcome.tsx':
'aW1wb3J0IHt1c2VOYXZpZ2F0ZX0gZnJvbSAicmVhY3Qtcm91dGVyLWRvbSI7Cgpjb25zdCBXZWxjb21lID0gKCkgPT4gewpjb25zdCBuYXZpZ2F0ZSA9IHVzZU5hdmlnYXRlKCkKcmV0dXJuIDxkaXY+CiAgICA8YnV0dG9uIG9uQ2xpY2s9eygpPT57CiAgICAgICAgbmF2aWdhdGUoLTEpCiAgICB9fT7lm57ljrs8L2J1dHRvbj4KPC9kaXY+Cn0KCmV4cG9ydCBkZWZhdWx0IFdlbGNvbWUK',
- 'src/pages/Home.tsx':
+ '~/src/pages/Home.tsx':
'aW1wb3J0IHsgdXNlU3RhdGUgfSBmcm9tICdyZWFjdCcKCmZ1bmN0aW9uIEhvbWUoKSB7CiAgICBjb25zdCBbY291bnQsIHNldENvdW50XSA9IHVzZVN0YXRlKDApCgogICAgZnVuY3Rpb24gdGlwcyhjOm51bWJlcikgewogICAgICAgIGlmIChjID4gMyl7CiAgICAgICAgICAgIHJldHVybiAnY291bnTotoXov4cz5LqGLHRlc3QxMDI0JwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCfkvaDlpb0nKQogICAgICAgICAgICByZXR1cm4gJ2NvdW505bCP5LqO562J5LqOMycKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gKAogICAgICAgIDxkaXYgY2xhc3NOYW1lPSJBcHAiPgogICAgICAgICAgICA8ZGl2PgogICAgICAgICAgICAgICAgPGJ1dHRvbiBpZD17J2J0bid9IHR5cGU9ImJ1dHRvbiIgb25DbGljaz17KCkgPT4gc2V0Q291bnQoKGNvdW50KSA9PiBjb3VudCArIDEpfT4KICAgICAgICAgICAgICAgICAgICBjb3VudCBpczoge2NvdW50fQogICAgICAgICAgICAgICAgPC9idXR0b24+CiAgICAgICAgICAgICAgICA8cD57dGlwcyhjb3VudCl9PC9wPgoKICAgICAgICAgICAgICAgIDxidXR0b24gaWQ9eyd0ZXN0J30gb25DbGljaz17KCk9PnsKICAgICAgICAgICAgICAgICAgICB3aW5kb3cubG9jYXRpb24uaHJlZiA9ICcvd2VsY29tZScKICAgICAgICAgICAgICAgIH19PgogICAgICAgICAgICAgICAgICAgIOa1i+ivlei3s+i9rAogICAgICAgICAgICAgICAgPC9idXR0b24+CiAgICAgICAgICAgICAgICA8YnV0dG9uIGlkPXsndGVzdDEnfSBvbkNsaWNrPXsoKT0+ewogICAgICAgICAgICAgICAgICAgIHdpbmRvdy5vcGVuKCcvd2VsY29tZScpCiAgICAgICAgICAgICAgICB9fT4KICAgICAgICAgICAgICAgICAgICDmtYvor5Xot7PovazlpJbpg6gKICAgICAgIC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