再说一遍,我说的是测试和覆盖范围。

可能您已经从“为什么从正在运行的应用程序中删除覆盖范围”这一问题中coffee了咖啡-但是这种需求会定期出现。
例如:
- 使用某些第三方工具查找集成测试的范围,而无需进行代码繁琐化,应用终止和报告上传;
- 无需花很长时间就能找到代码,请求是通过哪个特定的应用程序模块传递的;
- 定义一个“死”代码,实际上该代码未在应用程序中使用;
- , .
? !
jest mocha (, ), , V8 - . — , , . , , !
, .
, , express.
1)
const runtimeCoverage = require('runtime-coverage');
2) API endpoint, :
app.get('/startCoverage', async (req, res) => {
await runtimeCoverage.startCoverage();
res.send('coverage started');
});
3) endpoint,
app.get('/getCoverage', async (req, res) => {
const options = {
all: req.query.all,
return: true,
reporters: [req.query.reporter || 'text'],
};
const coverage = await runtimeCoverage.getCoverage(options);
const data = Object.values(coverage)[0];
res.end(data);
});
… !
endpoint, API, — ! , , , .
, - http://localhost:3000/startCoverage http://localhost:3000/getCoverage
----------|---------|----------|---------|---------|---------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|---------------------
All files | 60.34 | 50 | 100 | 60.34 |
index.js | 60.34 | 50 | 100 | 60.34 | 9,27,28,32-41,46-55
----------|---------|----------|---------|---------|---------------------
node_modules, , node modules :
.-------------------------------------------------------------|---------|----------|---------|---------|-------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------------------------------------------|---------|----------|---------|---------|-------------------------
All files | 62.89 | 30 | 26.14 | 62.89 |
runtime-coverage-sample | 62.07 | 50 | 100 | 62.07 |
index.js | 62.07 | 50 | 100 | 62.07 | 9,20-28,32-41,54,55
runtime-coverage-sample/node_modules/content-type | 59.46 | 100 | 28.57 | 59.46 |
index.js | 59.46 | 100 | 28.57 | 59.46 | ...-122,126-163,174-190
runtime-coverage-sample/node_modules/debug/src | 42.57 | 0 | 14.29 | 42.57 |
debug.js | 42.57 | 0 | 14.29 | 42.57 | ...-166,176-189,199-202
runtime-coverage-sample/node_modules/etag | 95.42 | 100 | 75 | 95.42 |
index.js | 95.42 | 100 | 75 | 95.42 | 126-131
runtime-coverage-sample/node_modules/express/lib | 64.54 | 83.33 | 15.58 | 64.54 |
application.js | 62.11 | 50 | 20 | 62.11 | ...,618,628-631,638-644
express.js | 81.03 | 100 | 33.33 | 81.03 | 37-57,112
request.js | 76 | 100 | 0 | 76 | ...,496,507,508,519-525
response.js | 58.93 | 100 | 17.39 | 58.93 | ...,1016-1104,1118-1142
utils.js | 64.71 | 100 | 25 | 64.71 | ...-239,274-282,304-306
runtime-coverage-sample/node_modules/express/lib/middleware | 61.8 | 66.67 | 50 | 61.8 |
init.js | 69.05 | 50 | 50 | 69.05 | 29-41
query.js | 55.32 | 100 | 50 | 55.32 | 26-46
runtime-coverage-sample/node_modules/express/lib/router | 65.82 | 66.67 | 43.33 | 65.82 |
index.js | 61.93 | 100 | 42.11 | 61.93 | ...-635,640-648,651-662
layer.js | 74.59 | 100 | 40 | 74.59 | 33-50,63-74,166-181
route.js | 70.37 | 50 | 50 | 70.37 | ...8-90,171-189,193-215
runtime-coverage-sample/node_modules/finalhandler | 60.12 | 100 | 9.09 | 60.12 |
index.js | 60.12 | 100 | 9.09 | 60.12 | ...-259,272-311,321-331
runtime-coverage-sample/node_modules/fresh | 94.16 | 100 | 66.67 | 94.16 |
index.js | 94.16 | 100 | 66.67 | 94.16 | 94-101
runtime-coverage-sample/node_modules/mime | 62.96 | 25 | 33.33 | 62.96 |
mime.js | 62.96 | 25 | 33.33 | 62.96 | 4-10,22-37,49-63,79,80
runtime-coverage-sample/node_modules/parseurl | 87.34 | 33.33 | 75 | 87.34 |
index.js | 87.34 | 33.33 | 75 | 87.34 | 65-84
runtime-coverage-sample/node_modules/qs/lib | 33.05 | 17.65 | 18.75 | 33.05 |
parse.js | 41.32 | 100 | 33.33 | 41.32 | ...2-97,101-132,136-186
utils.js | 24.35 | 15.15 | 10 | 24.35 | ...,181-201,209-213,217
-------------------------------------------------------------|---------|----------|---------|---------|-------------------------
, — , ( ), - ( , endpoint ).
,
. , .
, collect-v8-coverage ( ), v8-to-istanbul, istanbul-lib-coverage, istanbul-lib-report, istanbul-reports — . , V8 . — .
, — , , . , :
1) , ;
2) ;
3) require , , ;
4) ;
4.1) require, ;
4.2) , , , ;
4.3) require;
5) require;
6) ;
7) , .
, , , — - — - . :
- .
- setInterval
- unhandledRejction, .
, , . . forceReload
forceLineMode
— , .
UPD。我已经完成了一点-现在使用了一个单独的过程来收集与主要封面隔离的空封面-因此副作用的可能性可以忽略不计。
如果突然有人有想法和熟人在工作中用涂料吃狗(而不是像我一样),我将很高兴收到报价和请求。笑脸