monocart-coverage-reports 2.10.9 → 2.11.0
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 +13 -12
- package/README.zh-Hans.md +13 -11
- package/lib/cli.js +15 -0
- package/lib/converter/converter.js +1 -1
- package/lib/converter/flatten-source-maps.js +1 -1
- package/lib/converter/untested.js +315 -315
- package/lib/generate.js +52 -18
- package/lib/index.d.ts +2 -0
- package/lib/istanbul/istanbul.js +6 -2
- package/lib/packages/monocart-coverage-vendor.js +23 -23
- package/lib/reports/raw.js +85 -3
- package/lib/utils/dedupe.js +8 -3
- package/lib/utils/merge/merge.js +439 -0
- package/lib/utils/merge/range-tree.js +123 -0
- package/lib/utils/util.js +9 -0
- package/lib/v8/v8.js +13 -11
- package/package.json +118 -115
|
@@ -1,315 +1,315 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const Util = require('../utils/util.js');
|
|
4
|
-
|
|
5
|
-
const { pathToFileURL, fileURLToPath } = require('url');
|
|
6
|
-
|
|
7
|
-
const { normalizeSourcePath, getSourcePathReplacer } = require('../utils/source-path.js');
|
|
8
|
-
|
|
9
|
-
// const EC = require('eight-colors');
|
|
10
|
-
const { minimatch, convertSourceMap } = require('../packages/monocart-coverage-vendor.js');
|
|
11
|
-
|
|
12
|
-
// ========================================================================================================
|
|
13
|
-
|
|
14
|
-
const resolveAllDirList = (input) => {
|
|
15
|
-
const dirs = Util.toList(input, ',');
|
|
16
|
-
if (!dirs.length) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const dirList = dirs.filter((it) => fs.existsSync(it));
|
|
20
|
-
if (!dirList.length) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
return dirList;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const resolveAllFilter = (input) => {
|
|
27
|
-
// for function handler
|
|
28
|
-
if (typeof input === 'function') {
|
|
29
|
-
return input;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// for single minimatch pattern
|
|
33
|
-
if (input && typeof input === 'string') {
|
|
34
|
-
// string to multiple patterns "{...}"
|
|
35
|
-
const obj = Util.strToObj(input);
|
|
36
|
-
if (obj) {
|
|
37
|
-
input = obj;
|
|
38
|
-
} else {
|
|
39
|
-
return (filePath) => {
|
|
40
|
-
return minimatch(filePath, input);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// for patterns
|
|
46
|
-
if (input && typeof input === 'object') {
|
|
47
|
-
const patterns = Object.keys(input);
|
|
48
|
-
return (filePath) => {
|
|
49
|
-
for (const pattern of patterns) {
|
|
50
|
-
if (minimatch(filePath, pattern)) {
|
|
51
|
-
return input[pattern];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// false if not matched
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// default
|
|
59
|
-
return () => true;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const resolveAllOptions = (input) => {
|
|
63
|
-
if (!input) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let dir;
|
|
68
|
-
let filter;
|
|
69
|
-
let transformer;
|
|
70
|
-
|
|
71
|
-
if (typeof input === 'string') {
|
|
72
|
-
const obj = Util.strToObj(input);
|
|
73
|
-
if (obj) {
|
|
74
|
-
dir = obj.dir;
|
|
75
|
-
filter = obj.filter;
|
|
76
|
-
transformer = obj.transformer;
|
|
77
|
-
} else {
|
|
78
|
-
dir = input;
|
|
79
|
-
}
|
|
80
|
-
} else if (Array.isArray(input)) {
|
|
81
|
-
dir = input;
|
|
82
|
-
} else {
|
|
83
|
-
dir = input.dir;
|
|
84
|
-
filter = input.filter;
|
|
85
|
-
transformer = input.transformer;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const dirList = resolveAllDirList(dir);
|
|
89
|
-
if (!dirList) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const fileFilter = resolveAllFilter(filter);
|
|
94
|
-
const fileTransformer = typeof transformer === 'function' ? transformer : () => {};
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
dirList,
|
|
98
|
-
fileFilter,
|
|
99
|
-
fileTransformer
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const resolveFileType = (fileType, filePath) => {
|
|
104
|
-
if (fileType === 'js' || fileType === 'css') {
|
|
105
|
-
return fileType;
|
|
106
|
-
}
|
|
107
|
-
const extname = path.extname(filePath);
|
|
108
|
-
if (['.css', '.scss', '.sass', '.less'].includes(extname)) {
|
|
109
|
-
return 'css';
|
|
110
|
-
}
|
|
111
|
-
return 'js';
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const saveUntestedFileSource = async (entryFile, options) => {
|
|
115
|
-
const {
|
|
116
|
-
id,
|
|
117
|
-
url,
|
|
118
|
-
source,
|
|
119
|
-
sourceMap
|
|
120
|
-
} = entryFile;
|
|
121
|
-
// console.log('-', entry.sourcePath);
|
|
122
|
-
|
|
123
|
-
const { cachePath } = Util.getCacheFileInfo('source', id, options.cacheDir);
|
|
124
|
-
if (fs.existsSync(cachePath)) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// save source and sourceMap to separated json file
|
|
129
|
-
const sourceData = {
|
|
130
|
-
id,
|
|
131
|
-
url,
|
|
132
|
-
source,
|
|
133
|
-
sourceMap
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// remove comments if not debug
|
|
137
|
-
if (!Util.isDebug()) {
|
|
138
|
-
sourceData.source = convertSourceMap.removeComments(source);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// console.log('save untested file', id, url);
|
|
142
|
-
|
|
143
|
-
await Util.saveSourceCacheFile(sourceData, options);
|
|
144
|
-
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const getUntestedCoverageData = async (entryList, options, coverageType) => {
|
|
148
|
-
|
|
149
|
-
// save all empty coverage, 20 - 5(empty)
|
|
150
|
-
const dataId = Util.uid(15, 'empty');
|
|
151
|
-
const results = {
|
|
152
|
-
id: dataId
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
if (coverageType === 'istanbul') {
|
|
156
|
-
results.type = 'istanbul';
|
|
157
|
-
results.data = {};
|
|
158
|
-
} else {
|
|
159
|
-
results.type = 'v8';
|
|
160
|
-
results.data = [];
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const emptyCoverageList = [];
|
|
164
|
-
|
|
165
|
-
// save all empty source and sourcemap
|
|
166
|
-
for (const entry of entryList) {
|
|
167
|
-
|
|
168
|
-
// for raw report: source file
|
|
169
|
-
// id, url, source, sourceMap
|
|
170
|
-
await saveUntestedFileSource(entry, options);
|
|
171
|
-
|
|
172
|
-
if (coverageType === 'istanbul') {
|
|
173
|
-
|
|
174
|
-
// ===============================================
|
|
175
|
-
const item = {
|
|
176
|
-
path: fileURLToPath(entry.url),
|
|
177
|
-
statementMap: {},
|
|
178
|
-
fnMap: {},
|
|
179
|
-
branchMap: {},
|
|
180
|
-
s: {},
|
|
181
|
-
f: {},
|
|
182
|
-
b: {}
|
|
183
|
-
};
|
|
184
|
-
// object
|
|
185
|
-
results.data[item.path] = item;
|
|
186
|
-
emptyCoverageList.push(item);
|
|
187
|
-
|
|
188
|
-
} else {
|
|
189
|
-
|
|
190
|
-
// ===============================================
|
|
191
|
-
Util.setEmptyV8Coverage(entry);
|
|
192
|
-
|
|
193
|
-
const item = {
|
|
194
|
-
... entry
|
|
195
|
-
};
|
|
196
|
-
delete item.source;
|
|
197
|
-
delete item.sourceMap;
|
|
198
|
-
|
|
199
|
-
// array
|
|
200
|
-
results.data.push(item);
|
|
201
|
-
// will be parsed to AST and converted to V8 coverage
|
|
202
|
-
emptyCoverageList.push(entry);
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// for raw report: coverage file
|
|
209
|
-
const { cachePath } = Util.getCacheFileInfo('coverage', dataId, options.cacheDir);
|
|
210
|
-
await Util.writeFile(cachePath, JSON.stringify(results));
|
|
211
|
-
|
|
212
|
-
return emptyCoverageList;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
const getEmptyCoverages = async (testedMap, options, coverageType, fileList, fileTransformer) => {
|
|
216
|
-
const sourceFilter = Util.getSourceFilter(options);
|
|
217
|
-
const sourcePathReplacer = getSourcePathReplacer(options);
|
|
218
|
-
const baseDir = options.baseDir;
|
|
219
|
-
|
|
220
|
-
// console.log(fileList);
|
|
221
|
-
|
|
222
|
-
const entryList = [];
|
|
223
|
-
for (const item of fileList) {
|
|
224
|
-
|
|
225
|
-
const { fileType, filePath } = item;
|
|
226
|
-
const type = resolveFileType(fileType, filePath);
|
|
227
|
-
const url = pathToFileURL(filePath).toString();
|
|
228
|
-
const source = Util.readFileSync(filePath);
|
|
229
|
-
const entry = {
|
|
230
|
-
empty: true,
|
|
231
|
-
type,
|
|
232
|
-
url,
|
|
233
|
-
source
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// normalize sourcePath here
|
|
237
|
-
let sourcePath = normalizeSourcePath(url, baseDir);
|
|
238
|
-
if (sourcePathReplacer) {
|
|
239
|
-
const newSourcePath = sourcePathReplacer(sourcePath, entry);
|
|
240
|
-
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
241
|
-
sourcePath = newSourcePath;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// console.log(sourcePath);
|
|
246
|
-
|
|
247
|
-
if (testedMap.has(sourcePath)) {
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (!sourceFilter(sourcePath)) {
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
entry.sourcePath = sourcePath;
|
|
256
|
-
|
|
257
|
-
await fileTransformer(entry, coverageType);
|
|
258
|
-
// after transformer
|
|
259
|
-
entry.id = Util.calculateSha1(entry.sourcePath + entry.source);
|
|
260
|
-
|
|
261
|
-
entryList.push(entry);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
// console.log('fileList', fileList);
|
|
266
|
-
if (!entryList.length) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
// save empty coverage for merging raw reports
|
|
272
|
-
return getUntestedCoverageData(entryList, options, coverageType);
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
const getUntestedList = (testedMap, options, coverageType = 'v8') => {
|
|
276
|
-
const allOptions = resolveAllOptions(options.all);
|
|
277
|
-
// console.log('allOptions', all, allOptions);
|
|
278
|
-
if (!allOptions) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const {
|
|
283
|
-
dirList, fileFilter, fileTransformer
|
|
284
|
-
} = allOptions;
|
|
285
|
-
|
|
286
|
-
const fileList = [];
|
|
287
|
-
dirList.forEach((dir) => {
|
|
288
|
-
Util.forEachFile(dir, [], (fileName, fileDir) => {
|
|
289
|
-
const filePath = path.resolve(fileDir, fileName);
|
|
290
|
-
// return file extname for file type
|
|
291
|
-
const fileType = fileFilter(filePath);
|
|
292
|
-
if (fileType) {
|
|
293
|
-
fileList.push({
|
|
294
|
-
filePath,
|
|
295
|
-
fileType,
|
|
296
|
-
fileDir,
|
|
297
|
-
fileName
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
if (!fileList.length) {
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return getEmptyCoverages(testedMap, options, coverageType, fileList, fileTransformer);
|
|
309
|
-
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
module.exports = {
|
|
314
|
-
getUntestedList
|
|
315
|
-
};
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const Util = require('../utils/util.js');
|
|
4
|
+
|
|
5
|
+
const { pathToFileURL, fileURLToPath } = require('url');
|
|
6
|
+
|
|
7
|
+
const { normalizeSourcePath, getSourcePathReplacer } = require('../utils/source-path.js');
|
|
8
|
+
|
|
9
|
+
// const EC = require('eight-colors');
|
|
10
|
+
const { minimatch, convertSourceMap } = require('../packages/monocart-coverage-vendor.js');
|
|
11
|
+
|
|
12
|
+
// ========================================================================================================
|
|
13
|
+
|
|
14
|
+
const resolveAllDirList = (input) => {
|
|
15
|
+
const dirs = Util.toList(input, ',');
|
|
16
|
+
if (!dirs.length) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const dirList = dirs.filter((it) => fs.existsSync(it));
|
|
20
|
+
if (!dirList.length) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
return dirList;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const resolveAllFilter = (input) => {
|
|
27
|
+
// for function handler
|
|
28
|
+
if (typeof input === 'function') {
|
|
29
|
+
return input;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// for single minimatch pattern
|
|
33
|
+
if (input && typeof input === 'string') {
|
|
34
|
+
// string to multiple patterns "{...}"
|
|
35
|
+
const obj = Util.strToObj(input);
|
|
36
|
+
if (obj) {
|
|
37
|
+
input = obj;
|
|
38
|
+
} else {
|
|
39
|
+
return (filePath) => {
|
|
40
|
+
return minimatch(filePath, input);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// for patterns
|
|
46
|
+
if (input && typeof input === 'object') {
|
|
47
|
+
const patterns = Object.keys(input);
|
|
48
|
+
return (filePath) => {
|
|
49
|
+
for (const pattern of patterns) {
|
|
50
|
+
if (minimatch(filePath, pattern)) {
|
|
51
|
+
return input[pattern];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// false if not matched
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// default
|
|
59
|
+
return () => true;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const resolveAllOptions = (input) => {
|
|
63
|
+
if (!input) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let dir;
|
|
68
|
+
let filter;
|
|
69
|
+
let transformer;
|
|
70
|
+
|
|
71
|
+
if (typeof input === 'string') {
|
|
72
|
+
const obj = Util.strToObj(input);
|
|
73
|
+
if (obj) {
|
|
74
|
+
dir = obj.dir;
|
|
75
|
+
filter = obj.filter;
|
|
76
|
+
transformer = obj.transformer;
|
|
77
|
+
} else {
|
|
78
|
+
dir = input;
|
|
79
|
+
}
|
|
80
|
+
} else if (Array.isArray(input)) {
|
|
81
|
+
dir = input;
|
|
82
|
+
} else {
|
|
83
|
+
dir = input.dir;
|
|
84
|
+
filter = input.filter;
|
|
85
|
+
transformer = input.transformer;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const dirList = resolveAllDirList(dir);
|
|
89
|
+
if (!dirList) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const fileFilter = resolveAllFilter(filter);
|
|
94
|
+
const fileTransformer = typeof transformer === 'function' ? transformer : () => {};
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
dirList,
|
|
98
|
+
fileFilter,
|
|
99
|
+
fileTransformer
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const resolveFileType = (fileType, filePath) => {
|
|
104
|
+
if (fileType === 'js' || fileType === 'css') {
|
|
105
|
+
return fileType;
|
|
106
|
+
}
|
|
107
|
+
const extname = path.extname(filePath);
|
|
108
|
+
if (['.css', '.scss', '.sass', '.less'].includes(extname)) {
|
|
109
|
+
return 'css';
|
|
110
|
+
}
|
|
111
|
+
return 'js';
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const saveUntestedFileSource = async (entryFile, options) => {
|
|
115
|
+
const {
|
|
116
|
+
id,
|
|
117
|
+
url,
|
|
118
|
+
source,
|
|
119
|
+
sourceMap
|
|
120
|
+
} = entryFile;
|
|
121
|
+
// console.log('-', entry.sourcePath);
|
|
122
|
+
|
|
123
|
+
const { cachePath } = Util.getCacheFileInfo('source', id, options.cacheDir);
|
|
124
|
+
if (fs.existsSync(cachePath)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// save source and sourceMap to separated json file
|
|
129
|
+
const sourceData = {
|
|
130
|
+
id,
|
|
131
|
+
url,
|
|
132
|
+
source,
|
|
133
|
+
sourceMap
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// remove comments if not debug
|
|
137
|
+
if (!Util.isDebug()) {
|
|
138
|
+
sourceData.source = convertSourceMap.removeComments(source);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// console.log('save untested file', id, url);
|
|
142
|
+
|
|
143
|
+
await Util.saveSourceCacheFile(sourceData, options);
|
|
144
|
+
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const getUntestedCoverageData = async (entryList, options, coverageType) => {
|
|
148
|
+
|
|
149
|
+
// save all empty coverage, 20 - 5(empty)
|
|
150
|
+
const dataId = Util.uid(15, 'empty');
|
|
151
|
+
const results = {
|
|
152
|
+
id: dataId
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
if (coverageType === 'istanbul') {
|
|
156
|
+
results.type = 'istanbul';
|
|
157
|
+
results.data = {};
|
|
158
|
+
} else {
|
|
159
|
+
results.type = 'v8';
|
|
160
|
+
results.data = [];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const emptyCoverageList = [];
|
|
164
|
+
|
|
165
|
+
// save all empty source and sourcemap
|
|
166
|
+
for (const entry of entryList) {
|
|
167
|
+
|
|
168
|
+
// for raw report: source file
|
|
169
|
+
// id, url, source, sourceMap
|
|
170
|
+
await saveUntestedFileSource(entry, options);
|
|
171
|
+
|
|
172
|
+
if (coverageType === 'istanbul') {
|
|
173
|
+
|
|
174
|
+
// ===============================================
|
|
175
|
+
const item = {
|
|
176
|
+
path: fileURLToPath(entry.url),
|
|
177
|
+
statementMap: {},
|
|
178
|
+
fnMap: {},
|
|
179
|
+
branchMap: {},
|
|
180
|
+
s: {},
|
|
181
|
+
f: {},
|
|
182
|
+
b: {}
|
|
183
|
+
};
|
|
184
|
+
// object
|
|
185
|
+
results.data[item.path] = item;
|
|
186
|
+
emptyCoverageList.push(item);
|
|
187
|
+
|
|
188
|
+
} else {
|
|
189
|
+
|
|
190
|
+
// ===============================================
|
|
191
|
+
Util.setEmptyV8Coverage(entry);
|
|
192
|
+
|
|
193
|
+
const item = {
|
|
194
|
+
... entry
|
|
195
|
+
};
|
|
196
|
+
delete item.source;
|
|
197
|
+
delete item.sourceMap;
|
|
198
|
+
|
|
199
|
+
// array
|
|
200
|
+
results.data.push(item);
|
|
201
|
+
// will be parsed to AST and converted to V8 coverage
|
|
202
|
+
emptyCoverageList.push(entry);
|
|
203
|
+
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// for raw report: coverage file
|
|
209
|
+
const { cachePath } = Util.getCacheFileInfo('coverage', dataId, options.cacheDir);
|
|
210
|
+
await Util.writeFile(cachePath, JSON.stringify(results));
|
|
211
|
+
|
|
212
|
+
return emptyCoverageList;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const getEmptyCoverages = async (testedMap, options, coverageType, fileList, fileTransformer) => {
|
|
216
|
+
const sourceFilter = Util.getSourceFilter(options);
|
|
217
|
+
const sourcePathReplacer = getSourcePathReplacer(options);
|
|
218
|
+
const baseDir = options.baseDir;
|
|
219
|
+
|
|
220
|
+
// console.log(fileList);
|
|
221
|
+
|
|
222
|
+
const entryList = [];
|
|
223
|
+
for (const item of fileList) {
|
|
224
|
+
|
|
225
|
+
const { fileType, filePath } = item;
|
|
226
|
+
const type = resolveFileType(fileType, filePath);
|
|
227
|
+
const url = pathToFileURL(filePath).toString();
|
|
228
|
+
const source = Util.readFileSync(filePath);
|
|
229
|
+
const entry = {
|
|
230
|
+
empty: true,
|
|
231
|
+
type,
|
|
232
|
+
url,
|
|
233
|
+
source
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// normalize sourcePath here
|
|
237
|
+
let sourcePath = normalizeSourcePath(url, baseDir);
|
|
238
|
+
if (sourcePathReplacer) {
|
|
239
|
+
const newSourcePath = sourcePathReplacer(sourcePath, entry);
|
|
240
|
+
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
241
|
+
sourcePath = newSourcePath;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// console.log(sourcePath);
|
|
246
|
+
|
|
247
|
+
if (testedMap.has(sourcePath)) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (!sourceFilter(sourcePath)) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
entry.sourcePath = sourcePath;
|
|
256
|
+
|
|
257
|
+
await fileTransformer(entry, coverageType);
|
|
258
|
+
// after transformer
|
|
259
|
+
entry.id = Util.calculateSha1(entry.sourcePath + entry.source);
|
|
260
|
+
|
|
261
|
+
entryList.push(entry);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
// console.log('fileList', fileList);
|
|
266
|
+
if (!entryList.length) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
// save empty coverage for merging raw reports
|
|
272
|
+
return getUntestedCoverageData(entryList, options, coverageType);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
const getUntestedList = (testedMap, options, coverageType = 'v8') => {
|
|
276
|
+
const allOptions = resolveAllOptions(options.all);
|
|
277
|
+
// console.log('allOptions', all, allOptions);
|
|
278
|
+
if (!allOptions) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const {
|
|
283
|
+
dirList, fileFilter, fileTransformer
|
|
284
|
+
} = allOptions;
|
|
285
|
+
|
|
286
|
+
const fileList = [];
|
|
287
|
+
dirList.forEach((dir) => {
|
|
288
|
+
Util.forEachFile(dir, [], (fileName, fileDir) => {
|
|
289
|
+
const filePath = path.resolve(fileDir, fileName);
|
|
290
|
+
// return file extname for file type
|
|
291
|
+
const fileType = fileFilter(filePath);
|
|
292
|
+
if (fileType) {
|
|
293
|
+
fileList.push({
|
|
294
|
+
filePath,
|
|
295
|
+
fileType,
|
|
296
|
+
fileDir,
|
|
297
|
+
fileName
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
if (!fileList.length) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return getEmptyCoverages(testedMap, options, coverageType, fileList, fileTransformer);
|
|
309
|
+
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
module.exports = {
|
|
314
|
+
getUntestedList
|
|
315
|
+
};
|