monocart-coverage-reports 2.8.0 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -10
- package/README.zh-Hans.md +46 -7
- package/lib/cli.js +1 -0
- package/lib/converter/converter.js +2 -5
- package/lib/default/options.js +3 -0
- package/lib/index.d.ts +3 -0
- package/lib/istanbul/istanbul.js +2 -4
- package/lib/utils/source-path.js +85 -68
- package/lib/v8/v8.js +11 -5
- package/package.json +101 -101
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
- [Collecting V8 Coverage Data from Node.js](#collecting-v8-coverage-data-from-nodejs)
|
|
22
22
|
- [Collecting V8 Coverage Data with `CDPClient` API](#collecting-v8-coverage-data-with-cdpclient-api)
|
|
23
23
|
- [V8 Coverage Data API](#v8-coverage-data-api)
|
|
24
|
-
* [
|
|
24
|
+
* [Filtering Results](#filtering-results)
|
|
25
25
|
* [Resolve `sourcePath` for the Source Files](#resolve-sourcepath-for-the-source-files)
|
|
26
26
|
* [Adding Empty Coverage for Untested Files](#adding-empty-coverage-for-untested-files)
|
|
27
27
|
* [onEnd Hook](#onend-hook)
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
- [ts-node](#ts-node)
|
|
54
54
|
- [AVA](#ava)
|
|
55
55
|
- [Codecov](#codecov)
|
|
56
|
+
- [Codacy](#codacy)
|
|
56
57
|
- [Coveralls](#coveralls)
|
|
57
58
|
- [Sonar Cloud](#sonar-cloud)
|
|
58
59
|
* [Contributing](#contributing)
|
|
@@ -467,7 +468,8 @@ export interface ScriptCoverage {
|
|
|
467
468
|
export type V8CoverageData = ScriptCoverage[];
|
|
468
469
|
```
|
|
469
470
|
|
|
470
|
-
##
|
|
471
|
+
## Filtering Results
|
|
472
|
+
### Using `entryFilter` and `sourceFilter` to filter the results for V8 report
|
|
471
473
|
When V8 coverage data collected, it actually contains the data of all entry files, for example:
|
|
472
474
|
|
|
473
475
|
- *dist/main.js*
|
|
@@ -517,19 +519,33 @@ const coverageOptions = {
|
|
|
517
519
|
}
|
|
518
520
|
};
|
|
519
521
|
```
|
|
520
|
-
|
|
522
|
+
As CLI args (JSON-like string. Added in: v2.8):
|
|
523
|
+
```sh
|
|
524
|
+
mcr --sourceFilter "{'**/node_modules/**':false,'**/**':true}"
|
|
525
|
+
```
|
|
526
|
+
Note, those patterns will be transformed to a function, and the order of the patterns will impact the results:
|
|
521
527
|
```js
|
|
522
528
|
const coverageOptions = {
|
|
523
|
-
// '**/node_modules/**': false,
|
|
524
|
-
// '**/vendor.js': false,
|
|
525
|
-
// '**/src/**': true
|
|
526
529
|
entryFilter: (entry) => {
|
|
527
530
|
if (minimatch(entry.url, '**/node_modules/**')) { return false; }
|
|
528
531
|
if (minimatch(entry.url, '**/vendor.js')) { return false; }
|
|
529
532
|
if (minimatch(entry.url, '**/src/**')) { return true; }
|
|
530
533
|
return false; // else unmatched
|
|
531
534
|
}
|
|
532
|
-
|
|
535
|
+
};
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
### Using `filter` instead of `entryFilter` and `sourceFilter`
|
|
539
|
+
If you don't want to define both `entryFilter` and `sourceFilter`, you can use `filter` instead. (Added in: v2.8)
|
|
540
|
+
```js
|
|
541
|
+
const coverageOptions = {
|
|
542
|
+
// combined patterns
|
|
543
|
+
filter: {
|
|
544
|
+
'**/node_modules/**': false,
|
|
545
|
+
'**/vendor.js': false,
|
|
546
|
+
'**/src/**': true
|
|
547
|
+
'**/**': true
|
|
548
|
+
}
|
|
533
549
|
};
|
|
534
550
|
```
|
|
535
551
|
|
|
@@ -826,6 +842,7 @@ await new CoverageReport(coverageOptions).generate();
|
|
|
826
842
|
}
|
|
827
843
|
}
|
|
828
844
|
```
|
|
845
|
+
see example: [merge-code-coverage](https://github.com/cenfun/merge-code-coverage)
|
|
829
846
|
|
|
830
847
|
## Common issues
|
|
831
848
|
### Unexpected coverage
|
|
@@ -897,6 +914,7 @@ When `logging` is `debug`, the raw report data will be preserved in `[outputDir]
|
|
|
897
914
|
- [playwright-coverage](https://github.com/cenfun/playwright-coverage) - Example for Playwright coverage reports
|
|
898
915
|
- [playwright-bdd-coverage](https://github.com/cenfun/playwright-bdd-coverage) - Example for Playwright BDD coverage reports
|
|
899
916
|
- [monocart-reporter](https://github.com/cenfun/monocart-reporter) - Playwright custom reporter, supports generating [Code coverage report](https://github.com/cenfun/monocart-reporter?#code-coverage-report)
|
|
917
|
+
- [merge-code-coverage](https://github.com/cenfun/merge-code-coverage) - Example for merging code coverage (unit + e2e shard)
|
|
900
918
|
- Coverage for component testing with `monocart-reporter`:
|
|
901
919
|
- [playwright-ct-vue](https://github.com/cenfun/playwright-ct-vue)
|
|
902
920
|
- [playwright-ct-react](https://github.com/cenfun/playwright-ct-react)
|
|
@@ -969,13 +987,32 @@ const coverageOptions = {
|
|
|
969
987
|
]
|
|
970
988
|
};
|
|
971
989
|
```
|
|
972
|
-
- Github actions
|
|
990
|
+
- Github actions:
|
|
973
991
|
```yml
|
|
974
992
|
- name: Codecov
|
|
975
993
|
uses: codecov/codecov-action@v3
|
|
976
994
|
with:
|
|
977
995
|
files: ./coverage-reports/codecov.json
|
|
978
996
|
```
|
|
997
|
+
|
|
998
|
+
### [Codacy](https://www.codacy.com/)
|
|
999
|
+
[](https://app.codacy.com/gh/cenfun/monocart-coverage-reports/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
1000
|
+
- Using `lcov` report:
|
|
1001
|
+
```js
|
|
1002
|
+
const coverageOptions = {
|
|
1003
|
+
outputDir: "./coverage-reports",
|
|
1004
|
+
lcov: true
|
|
1005
|
+
};
|
|
1006
|
+
```
|
|
1007
|
+
- Github actions:
|
|
1008
|
+
```yml
|
|
1009
|
+
- name: Codacy Coverage Reporter
|
|
1010
|
+
uses: codacy/codacy-coverage-reporter-action@v1
|
|
1011
|
+
with:
|
|
1012
|
+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
|
|
1013
|
+
coverage-reports: ./docs/mcr/lcov.info
|
|
1014
|
+
```
|
|
1015
|
+
|
|
979
1016
|
### [Coveralls](https://coveralls.io/)
|
|
980
1017
|
[](https://coveralls.io/github/cenfun/monocart-coverage-reports?branch=main)
|
|
981
1018
|
- Using `lcov` report:
|
|
@@ -985,13 +1022,14 @@ const coverageOptions = {
|
|
|
985
1022
|
lcov: true
|
|
986
1023
|
};
|
|
987
1024
|
```
|
|
988
|
-
- Github actions
|
|
1025
|
+
- Github actions:
|
|
989
1026
|
```yml
|
|
990
1027
|
- name: Coveralls
|
|
991
1028
|
uses: coverallsapp/github-action@v2
|
|
992
1029
|
with:
|
|
993
1030
|
files: ./coverage-reports/lcov.info
|
|
994
1031
|
```
|
|
1032
|
+
|
|
995
1033
|
### [Sonar Cloud](https://sonarcloud.io/)
|
|
996
1034
|
[](https://sonarcloud.io/summary/new_code?id=monocart-coverage-reports)
|
|
997
1035
|
- Using `lcov` report. Github actions example:
|
|
@@ -1013,8 +1051,9 @@ const coverageOptions = {
|
|
|
1013
1051
|
```
|
|
1014
1052
|
|
|
1015
1053
|
## Contributing
|
|
1054
|
+
- Node.js 20+
|
|
1055
|
+
- VSCode (extensions: eslint/stylelint/vue)
|
|
1016
1056
|
```sh
|
|
1017
|
-
# Node.js 20+
|
|
1018
1057
|
npm install starfall-cli -g
|
|
1019
1058
|
npm install
|
|
1020
1059
|
|
package/README.zh-Hans.md
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
- [从Node.js](#collecting-v8-coverage-data-from-nodejs)
|
|
22
22
|
- [使用`CDPClient`API](#collecting-v8-coverage-data-with-cdpclient-api)
|
|
23
23
|
- [参考V8覆盖率的API](#v8-coverage-data-api)
|
|
24
|
-
* [
|
|
24
|
+
* [过滤V8覆盖率数据](#filtering-results)
|
|
25
25
|
* [使用 `sourcePath` 修改源文件路径](#resolve-sourcepath-for-the-source-files)
|
|
26
26
|
* [为未测试的文件添加空的覆盖率报告](#adding-empty-coverage-for-untested-files)
|
|
27
27
|
* [onEnd回调函数](#onend-hook)
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
- [ts-node](#ts-node)
|
|
54
54
|
- [AVA](#ava)
|
|
55
55
|
- [Codecov](#codecov)
|
|
56
|
+
- [Codacy](#codacy)
|
|
56
57
|
- [Coveralls](#coveralls)
|
|
57
58
|
- [Sonar Cloud](#sonar-cloud)
|
|
58
59
|
* [Contributing](#contributing)
|
|
@@ -471,6 +472,7 @@ export interface ScriptCoverage {
|
|
|
471
472
|
export type V8CoverageData = ScriptCoverage[];
|
|
472
473
|
```
|
|
473
474
|
|
|
475
|
+
## Filtering Results
|
|
474
476
|
## Using `entryFilter` and `sourceFilter` to filter the results for V8 report
|
|
475
477
|
当收集到V8的覆盖数据时,它实际上包含了所有的入口文件的覆盖率数据, 比如有以下3个文件:
|
|
476
478
|
|
|
@@ -521,19 +523,33 @@ const coverageOptions = {
|
|
|
521
523
|
}
|
|
522
524
|
};
|
|
523
525
|
```
|
|
524
|
-
|
|
526
|
+
作为CLI参数(JSON字符串,Added in: v2.8):
|
|
527
|
+
```sh
|
|
528
|
+
mcr --sourceFilter "{'**/node_modules/**':false,'**/**':true}"
|
|
529
|
+
```
|
|
530
|
+
注意,这些匹配实际上会转换成一个过滤函数(如下),所以如果一个匹配成功则会直接返回,后面的将不再继续匹配。请注意先后顺序,如果存在包含关系的,可以调整上下顺序,最后如果都未匹配,则默认返回false
|
|
525
531
|
```js
|
|
526
532
|
const coverageOptions = {
|
|
527
|
-
// '**/node_modules/**': false,
|
|
528
|
-
// '**/vendor.js': false,
|
|
529
|
-
// '**/src/**': true
|
|
530
533
|
entryFilter: (entry) => {
|
|
531
534
|
if (minimatch(entry.url, '**/node_modules/**')) { return false; }
|
|
532
535
|
if (minimatch(entry.url, '**/vendor.js')) { return false; }
|
|
533
536
|
if (minimatch(entry.url, '**/src/**')) { return true; }
|
|
534
537
|
return false; // else unmatched
|
|
535
538
|
}
|
|
536
|
-
|
|
539
|
+
};
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
### Using `filter` instead of `entryFilter` and `sourceFilter`
|
|
543
|
+
如果你不想定义两个过滤器,可以使用 `filter` 选项代替,可以将多个匹配合并在一起. (Added in: v2.8)
|
|
544
|
+
```js
|
|
545
|
+
const coverageOptions = {
|
|
546
|
+
// combined patterns
|
|
547
|
+
filter: {
|
|
548
|
+
'**/node_modules/**': false,
|
|
549
|
+
'**/vendor.js': false,
|
|
550
|
+
'**/src/**': true
|
|
551
|
+
'**/**': true
|
|
552
|
+
}
|
|
537
553
|
};
|
|
538
554
|
```
|
|
539
555
|
|
|
@@ -828,6 +844,7 @@ await new CoverageReport(coverageOptions).generate();
|
|
|
828
844
|
}
|
|
829
845
|
}
|
|
830
846
|
```
|
|
847
|
+
参见例子: [merge-code-coverage](https://github.com/cenfun/merge-code-coverage)
|
|
831
848
|
|
|
832
849
|
## Common issues
|
|
833
850
|
> 常见问题
|
|
@@ -901,6 +918,7 @@ const coverageOptions = {
|
|
|
901
918
|
- [playwright-coverage](https://github.com/cenfun/playwright-coverage) - Example for Playwright coverage reports
|
|
902
919
|
- [playwright-bdd-coverage](https://github.com/cenfun/playwright-bdd-coverage) - Example for Playwright BDD coverage reports
|
|
903
920
|
- [monocart-reporter](https://github.com/cenfun/monocart-reporter) - Playwright custom reporter, supports generating [Code coverage report](https://github.com/cenfun/monocart-reporter?#code-coverage-report)
|
|
921
|
+
- [merge-code-coverage](https://github.com/cenfun/merge-code-coverage) - Example for merging code coverage (unit + e2e shard)
|
|
904
922
|
- Coverage for component testing with `monocart-reporter`:
|
|
905
923
|
- [playwright-ct-vue](https://github.com/cenfun/playwright-ct-vue)
|
|
906
924
|
- [playwright-ct-react](https://github.com/cenfun/playwright-ct-react)
|
|
@@ -980,6 +998,25 @@ const coverageOptions = {
|
|
|
980
998
|
with:
|
|
981
999
|
files: ./coverage-reports/codecov.json
|
|
982
1000
|
```
|
|
1001
|
+
|
|
1002
|
+
### [Codacy](https://www.codacy.com/)
|
|
1003
|
+
[](https://app.codacy.com/gh/cenfun/monocart-coverage-reports/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
|
|
1004
|
+
- Using `lcov` report:
|
|
1005
|
+
```js
|
|
1006
|
+
const coverageOptions = {
|
|
1007
|
+
outputDir: "./coverage-reports",
|
|
1008
|
+
lcov: true
|
|
1009
|
+
};
|
|
1010
|
+
```
|
|
1011
|
+
- Github actions:
|
|
1012
|
+
```yml
|
|
1013
|
+
- name: Codacy Coverage Reporter
|
|
1014
|
+
uses: codacy/codacy-coverage-reporter-action@v1
|
|
1015
|
+
with:
|
|
1016
|
+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
|
|
1017
|
+
coverage-reports: ./docs/mcr/lcov.info
|
|
1018
|
+
```
|
|
1019
|
+
|
|
983
1020
|
### [Coveralls](https://coveralls.io/)
|
|
984
1021
|
[](https://coveralls.io/github/cenfun/monocart-coverage-reports?branch=main)
|
|
985
1022
|
- Using `lcov` report:
|
|
@@ -996,6 +1033,7 @@ const coverageOptions = {
|
|
|
996
1033
|
with:
|
|
997
1034
|
files: ./coverage-reports/lcov.info
|
|
998
1035
|
```
|
|
1036
|
+
|
|
999
1037
|
### [Sonar Cloud](https://sonarcloud.io/)
|
|
1000
1038
|
[](https://sonarcloud.io/summary/new_code?id=monocart-coverage-reports)
|
|
1001
1039
|
- Using `lcov` report. Github actions example:
|
|
@@ -1017,8 +1055,9 @@ const coverageOptions = {
|
|
|
1017
1055
|
```
|
|
1018
1056
|
|
|
1019
1057
|
## Contributing
|
|
1058
|
+
- Node.js 20+
|
|
1059
|
+
- VSCode (extensions: eslint/stylelint/vue)
|
|
1020
1060
|
```sh
|
|
1021
|
-
# Node.js 20+
|
|
1022
1061
|
npm install starfall-cli -g
|
|
1023
1062
|
npm install
|
|
1024
1063
|
|
package/lib/cli.js
CHANGED
|
@@ -192,6 +192,7 @@ program
|
|
|
192
192
|
|
|
193
193
|
.option('-o, --outputDir <dir>', 'output dir for reports')
|
|
194
194
|
.option('-i, --inputDir <dir>', 'input dir for merging raw files')
|
|
195
|
+
.option('-b, --baseDir <dir>', 'base dir for normalizing path')
|
|
195
196
|
|
|
196
197
|
.option('-a, --all <dir>', 'include all files from dir')
|
|
197
198
|
|
|
@@ -16,9 +16,7 @@ const { getIgnoredRanges } = require('./ignore.js');
|
|
|
16
16
|
const {
|
|
17
17
|
sortRanges, dedupeCountRanges, mergeRangesWith
|
|
18
18
|
} = require('../utils/dedupe.js');
|
|
19
|
-
const {
|
|
20
|
-
getSourceType, getSourcePathHandler, initSourceMapSourcePath
|
|
21
|
-
} = require('../utils/source-path.js');
|
|
19
|
+
const { getSourceType, initSourceMapSourcesPath } = require('../utils/source-path.js');
|
|
22
20
|
const { decode, minimatch } = require('../packages/monocart-coverage-vendor.js');
|
|
23
21
|
|
|
24
22
|
const InfoBranch = require('./info-branch.js');
|
|
@@ -1111,8 +1109,7 @@ const unpackSourceMap = (state, options) => {
|
|
|
1111
1109
|
|
|
1112
1110
|
// keep original urls
|
|
1113
1111
|
const fileUrls = {};
|
|
1114
|
-
|
|
1115
|
-
initSourceMapSourcePath(sourceMap, fileUrls, sourcePath, sourcePathHandler);
|
|
1112
|
+
initSourceMapSourcesPath(fileUrls, sourceMap, sourcePath, options);
|
|
1116
1113
|
state.fileUrls = fileUrls;
|
|
1117
1114
|
|
|
1118
1115
|
// ===============================================
|
package/lib/default/options.js
CHANGED
|
@@ -24,6 +24,9 @@ module.exports = {
|
|
|
24
24
|
// {string|string[]} input raw dir(s)
|
|
25
25
|
inputDir: null,
|
|
26
26
|
|
|
27
|
+
// {string} base dir for normalizing the relative source path, defaults to cwd
|
|
28
|
+
baseDir: null,
|
|
29
|
+
|
|
27
30
|
// (V8 only) {function} A filter function to execute for each element in the V8 list.
|
|
28
31
|
// entryFilter: (entry) => {
|
|
29
32
|
// if (entry.url.indexOf('googleapis.com') !== -1) {
|
package/lib/index.d.ts
CHANGED
|
@@ -230,6 +230,9 @@ declare namespace MCR {
|
|
|
230
230
|
/** {string|string[]} input raw dir(s) */
|
|
231
231
|
inputDir?: string | string[];
|
|
232
232
|
|
|
233
|
+
/** {string} base dir for normalizing the relative source path, defaults to cwd */
|
|
234
|
+
baseDir?: string;
|
|
235
|
+
|
|
233
236
|
/** (V8 only)
|
|
234
237
|
*
|
|
235
238
|
* {string} `minimatch` pattern for entry url;
|
package/lib/istanbul/istanbul.js
CHANGED
|
@@ -7,7 +7,7 @@ const istanbulLibReport = require('istanbul-lib-report');
|
|
|
7
7
|
const Util = require('../utils/util.js');
|
|
8
8
|
const IstanbulSummary = require('./istanbul-summary.js');
|
|
9
9
|
|
|
10
|
-
const {
|
|
10
|
+
const { initIstanbulSourcePath } = require('../utils/source-path.js');
|
|
11
11
|
|
|
12
12
|
const findHtmlPath = (outputDir) => {
|
|
13
13
|
const defaultHtml = path.resolve(outputDir, 'index.html');
|
|
@@ -129,9 +129,7 @@ const mergeIstanbulCoverage = (dataList) => {
|
|
|
129
129
|
const initIstanbulData = (istanbulData, options) => {
|
|
130
130
|
|
|
131
131
|
const fileSources = options.fileSources || {};
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, sourcePathHandler);
|
|
132
|
+
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, options);
|
|
135
133
|
|
|
136
134
|
return {
|
|
137
135
|
fileSources,
|
package/lib/utils/source-path.js
CHANGED
|
@@ -2,7 +2,40 @@ const path = require('path');
|
|
|
2
2
|
const { fileURLToPath, pathToFileURL } = require('url');
|
|
3
3
|
const Util = require('./util.js');
|
|
4
4
|
|
|
5
|
+
const resolveSourceRootUrl = (sourceName, sourceRoot) => {
|
|
6
|
+
// prepend sourceRoot
|
|
7
|
+
if (sourceRoot && !sourceName.startsWith(sourceRoot)) {
|
|
8
|
+
if (!sourceRoot.endsWith('/')) {
|
|
9
|
+
sourceRoot += '/';
|
|
10
|
+
}
|
|
11
|
+
return sourceRoot + sourceName;
|
|
12
|
+
}
|
|
13
|
+
return sourceName;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const resolveAnonymousUrl = (url, index, type) => {
|
|
17
|
+
if (url) {
|
|
18
|
+
return url;
|
|
19
|
+
}
|
|
20
|
+
// anonymous scripts will have __playwright_evaluation_script__ as their URL.
|
|
21
|
+
const list = ['anonymous'];
|
|
22
|
+
if (index) {
|
|
23
|
+
list.push(`-${index}`);
|
|
24
|
+
}
|
|
25
|
+
if (type) {
|
|
26
|
+
list.push(`.${type}`);
|
|
27
|
+
}
|
|
28
|
+
return list.join('');
|
|
29
|
+
};
|
|
30
|
+
|
|
5
31
|
const filterPath = (str) => {
|
|
32
|
+
// double \\ to /
|
|
33
|
+
|
|
34
|
+
// src/images/icons/ sync \.svg$
|
|
35
|
+
// src/images/icons/sync-.svg$
|
|
36
|
+
|
|
37
|
+
str = str.replace(/\\\\/g, '/');
|
|
38
|
+
// decodeURI("%20") to space
|
|
6
39
|
str = decodeURI(str);
|
|
7
40
|
// remove / of start, end or double, ./ ../
|
|
8
41
|
const ls = str.split('/').map((it) => {
|
|
@@ -21,23 +54,42 @@ const filterPath = (str) => {
|
|
|
21
54
|
return ls.join('/');
|
|
22
55
|
};
|
|
23
56
|
|
|
24
|
-
const
|
|
57
|
+
const normalizeSourcePath = (sourceUrl, baseDir) => {
|
|
25
58
|
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
59
|
+
// includes anonymous and everything
|
|
60
|
+
|
|
61
|
+
// file url
|
|
62
|
+
if (sourceUrl.startsWith('file:')) {
|
|
63
|
+
const relPath = Util.relativePath(fileURLToPath(sourceUrl), baseDir);
|
|
64
|
+
return filterPath(relPath);
|
|
31
65
|
}
|
|
32
66
|
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
67
|
+
// absolute path
|
|
68
|
+
// c:\\workspace\test\\selenium.spec.js true
|
|
69
|
+
// c://a.js true
|
|
70
|
+
// c:\\a.js true
|
|
71
|
+
// C:/a.js true
|
|
72
|
+
// /a.js true
|
|
73
|
+
|
|
74
|
+
// a.js false
|
|
75
|
+
// ws://a.js false
|
|
76
|
+
// file://a.js false
|
|
77
|
+
// http://a.com/a.js false
|
|
78
|
+
// webpack://src/a.js false
|
|
79
|
+
|
|
80
|
+
if (path.isAbsolute(sourceUrl)) {
|
|
81
|
+
const relPath = Util.relativePath(sourceUrl, baseDir);
|
|
36
82
|
return filterPath(relPath);
|
|
37
83
|
}
|
|
38
84
|
|
|
39
|
-
//
|
|
40
|
-
|
|
85
|
+
// ws://a.js
|
|
86
|
+
// http://127.0.0:8080/a.js
|
|
87
|
+
// https://127.0.0:8080/a.js?v=1
|
|
88
|
+
// webpack://coverage-v8/./test/mock/src/branch/branch.js
|
|
89
|
+
// webpack://monocart-v8/../starfall-cli/node_modules/css-loader/dist/runtime/api.js
|
|
90
|
+
|
|
91
|
+
// url http/https/webpack
|
|
92
|
+
const urlObj = Util.resolveUrl(sourceUrl);
|
|
41
93
|
if (urlObj) {
|
|
42
94
|
const host = [urlObj.hostname, urlObj.port].filter((it) => it).join('-');
|
|
43
95
|
// always start with '/'
|
|
@@ -52,11 +104,10 @@ const getSourcePath = (url, index = '', type = '') => {
|
|
|
52
104
|
return filterPath(p);
|
|
53
105
|
}
|
|
54
106
|
|
|
55
|
-
//
|
|
56
|
-
const fileUrl = pathToFileURL(
|
|
57
|
-
const relPath = Util.relativePath(fileURLToPath(fileUrl));
|
|
107
|
+
// relative path
|
|
108
|
+
const fileUrl = pathToFileURL(sourceUrl).toString();
|
|
109
|
+
const relPath = Util.relativePath(fileURLToPath(fileUrl), baseDir);
|
|
58
110
|
return filterPath(relPath);
|
|
59
|
-
|
|
60
111
|
};
|
|
61
112
|
|
|
62
113
|
const getSourceType = (sourcePath) => {
|
|
@@ -75,7 +126,7 @@ const getSourceType = (sourcePath) => {
|
|
|
75
126
|
|
|
76
127
|
// ========================================================================================================
|
|
77
128
|
|
|
78
|
-
const
|
|
129
|
+
const getSourcePathReplacer = (options) => {
|
|
79
130
|
const input = options.sourcePath;
|
|
80
131
|
if (typeof input === 'function') {
|
|
81
132
|
return input;
|
|
@@ -96,8 +147,10 @@ const getSourcePathHandler = (options) => {
|
|
|
96
147
|
|
|
97
148
|
// ========================================================================================================
|
|
98
149
|
|
|
99
|
-
const initIstanbulSourcePath = (coverageData, fileSources,
|
|
100
|
-
|
|
150
|
+
const initIstanbulSourcePath = (coverageData, fileSources, options) => {
|
|
151
|
+
|
|
152
|
+
const sourcePathReplacer = getSourcePathReplacer(options);
|
|
153
|
+
if (!sourcePathReplacer) {
|
|
101
154
|
return coverageData;
|
|
102
155
|
}
|
|
103
156
|
|
|
@@ -119,7 +172,7 @@ const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) =>
|
|
|
119
172
|
}
|
|
120
173
|
|
|
121
174
|
// new source path, second is source url
|
|
122
|
-
const newSourcePath =
|
|
175
|
+
const newSourcePath = sourcePathReplacer(sourcePath, item);
|
|
123
176
|
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
124
177
|
sourcePath = newSourcePath;
|
|
125
178
|
}
|
|
@@ -141,55 +194,21 @@ const initIstanbulSourcePath = (coverageData, fileSources, sourcePathHandler) =>
|
|
|
141
194
|
|
|
142
195
|
// ========================================================================================================
|
|
143
196
|
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
// prepend sourceRoot
|
|
147
|
-
if (sourceRoot && !sourceName.startsWith(sourceRoot)) {
|
|
148
|
-
if (!sourceRoot.endsWith('/')) {
|
|
149
|
-
sourceRoot += '/';
|
|
150
|
-
}
|
|
151
|
-
sourceName = sourceRoot + sourceName;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// could be absolute path
|
|
155
|
-
// c:\\workspace\test\\selenium.spec.js
|
|
156
|
-
// a.js false
|
|
157
|
-
// c://a.js true
|
|
158
|
-
// ws://a.js false
|
|
159
|
-
|
|
160
|
-
if (path.isAbsolute(sourceName)) {
|
|
161
|
-
return pathToFileURL(sourceName).toString();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// webpack://coverage-v8/./test/mock/src/branch/branch.js
|
|
165
|
-
// webpack://monocart-v8/../starfall-cli/node_modules/css-loader/dist/runtime/api.js
|
|
166
|
-
|
|
167
|
-
// as url
|
|
168
|
-
const urlObj = Util.resolveUrl(sourceName);
|
|
169
|
-
if (urlObj) {
|
|
170
|
-
return urlObj.toString();
|
|
171
|
-
}
|
|
197
|
+
const initSourceMapSourcesPath = (fileUrls, sourceMap, distFile, options) => {
|
|
172
198
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// as relative path
|
|
176
|
-
const sourceUrl = pathToFileURL(sourceName).toString();
|
|
177
|
-
|
|
178
|
-
// console.log('sourceUrl', sourceUrl);
|
|
179
|
-
|
|
180
|
-
return sourceUrl;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const initSourceMapSourcePath = (sourceMap, fileUrls, distFile, sourcePathHandler) => {
|
|
199
|
+
const baseDir = options.baseDir;
|
|
200
|
+
const sourcePathReplacer = getSourcePathReplacer(options);
|
|
184
201
|
|
|
185
202
|
sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
|
|
186
203
|
|
|
187
|
-
|
|
204
|
+
let sourceUrl = resolveSourceRootUrl(sourceName, sourceMap.sourceRoot);
|
|
205
|
+
sourceUrl = resolveAnonymousUrl(sourceUrl, i + 1, 'js');
|
|
206
|
+
let sourcePath = normalizeSourcePath(sourceUrl, baseDir);
|
|
207
|
+
// console.log(sourceUrl, sourcePath);
|
|
188
208
|
|
|
189
|
-
|
|
190
|
-
if (sourcePathHandler) {
|
|
209
|
+
if (sourcePathReplacer) {
|
|
191
210
|
// sourcePath could be a filename only, may using distFile to get full path
|
|
192
|
-
const newSourcePath =
|
|
211
|
+
const newSourcePath = sourcePathReplacer(sourcePath, {
|
|
193
212
|
url: sourceUrl,
|
|
194
213
|
distFile
|
|
195
214
|
});
|
|
@@ -205,12 +224,10 @@ const initSourceMapSourcePath = (sourceMap, fileUrls, distFile, sourcePathHandle
|
|
|
205
224
|
};
|
|
206
225
|
|
|
207
226
|
module.exports = {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
getSourcePath,
|
|
227
|
+
resolveAnonymousUrl,
|
|
228
|
+
normalizeSourcePath,
|
|
212
229
|
getSourceType,
|
|
213
|
-
|
|
230
|
+
getSourcePathReplacer,
|
|
214
231
|
initIstanbulSourcePath,
|
|
215
|
-
|
|
232
|
+
initSourceMapSourcesPath
|
|
216
233
|
};
|
package/lib/v8/v8.js
CHANGED
|
@@ -3,7 +3,9 @@ const EC = require('eight-colors');
|
|
|
3
3
|
const Util = require('../utils/util.js');
|
|
4
4
|
const { getV8Summary } = require('./v8-summary.js');
|
|
5
5
|
const { dedupeFlatRanges } = require('../utils/dedupe.js');
|
|
6
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
resolveAnonymousUrl, normalizeSourcePath, getSourcePathReplacer
|
|
8
|
+
} = require('../utils/source-path.js');
|
|
7
9
|
const { mergeScriptCovs, minimatch } = require('../packages/monocart-coverage-vendor.js');
|
|
8
10
|
const { collectSourceMaps } = require('../converter/collect-source-maps.js');
|
|
9
11
|
const version = require('../../package.json').version;
|
|
@@ -109,7 +111,9 @@ const initV8ListAndSourcemap = async (v8list, options) => {
|
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
|
|
112
|
-
const
|
|
114
|
+
const sourcePathReplacer = getSourcePathReplacer(options);
|
|
115
|
+
|
|
116
|
+
const baseDir = options.baseDir;
|
|
113
117
|
|
|
114
118
|
// init id, sourcePath
|
|
115
119
|
v8list = v8list.map((entry, i) => {
|
|
@@ -149,14 +153,16 @@ const initV8ListAndSourcemap = async (v8list, options) => {
|
|
|
149
153
|
}
|
|
150
154
|
|
|
151
155
|
// resolve source path
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
const sourceUrl = resolveAnonymousUrl(data.url, i + 1, data.type);
|
|
157
|
+
let sourcePath = normalizeSourcePath(sourceUrl, baseDir);
|
|
158
|
+
if (sourcePathReplacer) {
|
|
159
|
+
const newSourcePath = sourcePathReplacer(sourcePath, data);
|
|
155
160
|
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
156
161
|
sourcePath = newSourcePath;
|
|
157
162
|
}
|
|
158
163
|
}
|
|
159
164
|
data.sourcePath = sourcePath;
|
|
165
|
+
// console.log(data.url, sourcePath);
|
|
160
166
|
|
|
161
167
|
// calculate source id
|
|
162
168
|
data.id = Util.calculateSha1(sourcePath + data.source);
|
package/package.json
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "monocart-coverage-reports",
|
|
3
|
-
"version": "2.8.
|
|
4
|
-
"description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
|
|
5
|
-
"main": "./lib/index.js",
|
|
6
|
-
"bin": {
|
|
7
|
-
"mcr": "./lib/cli.js"
|
|
8
|
-
},
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./lib/index.d.ts",
|
|
12
|
-
"import": "./lib/index.mjs",
|
|
13
|
-
"require": "./lib/index.js",
|
|
14
|
-
"default": "./lib/index.js"
|
|
15
|
-
},
|
|
16
|
-
"./register": {
|
|
17
|
-
"import": "./lib/register/register.mjs",
|
|
18
|
-
"require": "./lib/register/register.js",
|
|
19
|
-
"default": "./lib/register/register.js"
|
|
20
|
-
},
|
|
21
|
-
"./converter": "./lib/converter/converter.js",
|
|
22
|
-
"./util": "./lib/utils/util.js",
|
|
23
|
-
"./package.json": "./package.json"
|
|
24
|
-
},
|
|
25
|
-
"types": "./lib/index.d.ts",
|
|
26
|
-
"scripts": {
|
|
27
|
-
"build-test": "node ./test/build/build-test.js",
|
|
28
|
-
"build": "sf lint && sf b -p && npm run build-test",
|
|
29
|
-
"test-unit": "mocha --parallel test/unit/*.test.js",
|
|
30
|
-
"test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
|
|
31
|
-
"test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
|
|
32
|
-
"test-node-ins": "node ./test/test-node-ins.js",
|
|
33
|
-
"test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
|
|
34
|
-
"test-node-vm": "node ./test/test-node-vm.js",
|
|
35
|
-
"test-node-koa": "node ./test/test-node-koa.js",
|
|
36
|
-
"test-node-fgc": "node ./test/test-node-fgc.js",
|
|
37
|
-
"test-node": "node ./test/test.js --node",
|
|
38
|
-
"test-istanbul": "node ./test/test-istanbul.js",
|
|
39
|
-
"test-v8": "node ./test/test-v8.js",
|
|
40
|
-
"test-puppeteer": "node ./test/test-puppeteer.js",
|
|
41
|
-
"test-anonymous": "node ./test/test-anonymous.js",
|
|
42
|
-
"test-css": "node ./test/test-css.js",
|
|
43
|
-
"test-minify": "node ./test/test-minify.js",
|
|
44
|
-
"test-esbuild": "node ./test/test-esbuild.js",
|
|
45
|
-
"test-rollup": "node ./test/test-rollup.js",
|
|
46
|
-
"test-swc": "node ./test/test-swc.js",
|
|
47
|
-
"test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
|
|
48
|
-
"test-browser": "node ./test/test.js --browser",
|
|
49
|
-
"test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
|
|
50
|
-
"test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
|
|
51
|
-
"test-demo": "node ./test/test-demo.js",
|
|
52
|
-
"test-merge": "node ./test/test-merge.js",
|
|
53
|
-
"test-merge-istanbul": "node ./test/test-merge-istanbul.js",
|
|
54
|
-
"test-client": "node ./test/test-client.js",
|
|
55
|
-
"test-all": "node ./test/test.js && node ./scripts/docs.js",
|
|
56
|
-
"test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js",
|
|
57
|
-
"test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
|
|
58
|
-
"dev": "sf d v8",
|
|
59
|
-
"open": "node ./scripts/open.js",
|
|
60
|
-
"patch": "npm run build && npm run test && sf publish patch -r"
|
|
61
|
-
},
|
|
62
|
-
"workspaces": [
|
|
63
|
-
"packages/*",
|
|
64
|
-
"test"
|
|
65
|
-
],
|
|
66
|
-
"files": [
|
|
67
|
-
"lib",
|
|
68
|
-
"README.zh-Hans.md"
|
|
69
|
-
],
|
|
70
|
-
"license": "MIT",
|
|
71
|
-
"repository": {
|
|
72
|
-
"type": "git",
|
|
73
|
-
"url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
|
|
74
|
-
},
|
|
75
|
-
"dependencies": {
|
|
76
|
-
"console-grid": "^2.2.2",
|
|
77
|
-
"eight-colors": "^1.3.0",
|
|
78
|
-
"istanbul-lib-coverage": "^3.2.2",
|
|
79
|
-
"istanbul-lib-report": "^3.0.1",
|
|
80
|
-
"istanbul-reports": "^3.1.7",
|
|
81
|
-
"lz-utils": "^2.0.2",
|
|
82
|
-
"monocart-code-viewer": "^1.1.3",
|
|
83
|
-
"monocart-formatter": "^3.0.0",
|
|
84
|
-
"monocart-locator": "^1.0.0",
|
|
85
|
-
"turbogrid": "^3.0.13"
|
|
86
|
-
},
|
|
87
|
-
"devDependencies": {
|
|
88
|
-
"commander": "^12.0.0",
|
|
89
|
-
"esbuild": "^0.21.
|
|
90
|
-
"eslint": "~9.2.0",
|
|
91
|
-
"eslint-config-plus": "^2.0.0",
|
|
92
|
-
"eslint-plugin-html": "^8.1.1",
|
|
93
|
-
"eslint-plugin-vue": "^9.26.0",
|
|
94
|
-
"minimatch": "^9.0.4",
|
|
95
|
-
"stylelint": "^16.5.0",
|
|
96
|
-
"stylelint-config-plus": "^1.1.2",
|
|
97
|
-
"supports-color": "^9.4.0",
|
|
98
|
-
"tsx": "^4.
|
|
99
|
-
"ws": "^8.17.0"
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "monocart-coverage-reports",
|
|
3
|
+
"version": "2.8.2",
|
|
4
|
+
"description": "A code coverage tool to generate native V8 reports or Istanbul reports.",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"mcr": "./lib/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"import": "./lib/index.mjs",
|
|
13
|
+
"require": "./lib/index.js",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./register": {
|
|
17
|
+
"import": "./lib/register/register.mjs",
|
|
18
|
+
"require": "./lib/register/register.js",
|
|
19
|
+
"default": "./lib/register/register.js"
|
|
20
|
+
},
|
|
21
|
+
"./converter": "./lib/converter/converter.js",
|
|
22
|
+
"./util": "./lib/utils/util.js",
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"types": "./lib/index.d.ts",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build-test": "node ./test/build/build-test.js",
|
|
28
|
+
"build": "sf lint && sf b -p && npm run build-test",
|
|
29
|
+
"test-unit": "mocha --parallel test/unit/*.test.js",
|
|
30
|
+
"test-node-env": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-env node ./test/test-node-env.js && node ./test/generate-report.js",
|
|
31
|
+
"test-node-api": "cross-env NODE_V8_COVERAGE=.temp/v8-coverage-api node ./test/test-node-api.js",
|
|
32
|
+
"test-node-ins": "node ./test/test-node-ins.js",
|
|
33
|
+
"test-node-cdp": "node --inspect=9229 ./test/test-node-cdp.js",
|
|
34
|
+
"test-node-vm": "node ./test/test-node-vm.js",
|
|
35
|
+
"test-node-koa": "node ./test/test-node-koa.js",
|
|
36
|
+
"test-node-fgc": "node ./test/test-node-fgc.js",
|
|
37
|
+
"test-node": "node ./test/test.js --node",
|
|
38
|
+
"test-istanbul": "node ./test/test-istanbul.js",
|
|
39
|
+
"test-v8": "node ./test/test-v8.js",
|
|
40
|
+
"test-puppeteer": "node ./test/test-puppeteer.js",
|
|
41
|
+
"test-anonymous": "node ./test/test-anonymous.js",
|
|
42
|
+
"test-css": "node ./test/test-css.js",
|
|
43
|
+
"test-minify": "node ./test/test-minify.js",
|
|
44
|
+
"test-esbuild": "node ./test/test-esbuild.js",
|
|
45
|
+
"test-rollup": "node ./test/test-rollup.js",
|
|
46
|
+
"test-swc": "node ./test/test-swc.js",
|
|
47
|
+
"test-v8-and-istanbul": "node ./test/test-v8-and-istanbul.js",
|
|
48
|
+
"test-browser": "node ./test/test.js --browser",
|
|
49
|
+
"test-cli": "npx mcr node ./test/specs/node.test.js -c test/mcr.config.cli.js",
|
|
50
|
+
"test-tsx": "npx mcr tsx ./test/specs/tsx.test.ts -c test/mcr.config.tsx.js",
|
|
51
|
+
"test-demo": "node ./test/test-demo.js",
|
|
52
|
+
"test-merge": "node ./test/test-merge.js",
|
|
53
|
+
"test-merge-istanbul": "node ./test/test-merge-istanbul.js",
|
|
54
|
+
"test-client": "node ./test/test-client.js",
|
|
55
|
+
"test-all": "node ./test/test.js && node ./scripts/docs.js",
|
|
56
|
+
"test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js",
|
|
57
|
+
"test:snap": "cross-env TEST_SNAPSHOT=true npm run test",
|
|
58
|
+
"dev": "sf d v8",
|
|
59
|
+
"open": "node ./scripts/open.js",
|
|
60
|
+
"patch": "npm run build && npm run test && sf publish patch -r"
|
|
61
|
+
},
|
|
62
|
+
"workspaces": [
|
|
63
|
+
"packages/*",
|
|
64
|
+
"test"
|
|
65
|
+
],
|
|
66
|
+
"files": [
|
|
67
|
+
"lib",
|
|
68
|
+
"README.zh-Hans.md"
|
|
69
|
+
],
|
|
70
|
+
"license": "MIT",
|
|
71
|
+
"repository": {
|
|
72
|
+
"type": "git",
|
|
73
|
+
"url": "git+https://github.com/cenfun/monocart-coverage-reports.git"
|
|
74
|
+
},
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"console-grid": "^2.2.2",
|
|
77
|
+
"eight-colors": "^1.3.0",
|
|
78
|
+
"istanbul-lib-coverage": "^3.2.2",
|
|
79
|
+
"istanbul-lib-report": "^3.0.1",
|
|
80
|
+
"istanbul-reports": "^3.1.7",
|
|
81
|
+
"lz-utils": "^2.0.2",
|
|
82
|
+
"monocart-code-viewer": "^1.1.3",
|
|
83
|
+
"monocart-formatter": "^3.0.0",
|
|
84
|
+
"monocart-locator": "^1.0.0",
|
|
85
|
+
"turbogrid": "^3.0.13"
|
|
86
|
+
},
|
|
87
|
+
"devDependencies": {
|
|
88
|
+
"commander": "^12.0.0",
|
|
89
|
+
"esbuild": "^0.21.3",
|
|
90
|
+
"eslint": "~9.2.0",
|
|
91
|
+
"eslint-config-plus": "^2.0.0",
|
|
92
|
+
"eslint-plugin-html": "^8.1.1",
|
|
93
|
+
"eslint-plugin-vue": "^9.26.0",
|
|
94
|
+
"minimatch": "^9.0.4",
|
|
95
|
+
"stylelint": "^16.5.0",
|
|
96
|
+
"stylelint-config-plus": "^1.1.2",
|
|
97
|
+
"supports-color": "^9.4.0",
|
|
98
|
+
"tsx": "^4.10.3",
|
|
99
|
+
"ws": "^8.17.0"
|
|
100
|
+
}
|
|
101
|
+
}
|