如何从Makefile运行nyc merge? [英] How do I run nyc merge from Makefile?
问题描述
我已经用Jasmine单元测试继承了JS代码库.测试框架使用karma
和instanbul-combine
来获取代码覆盖率.看来istanbul-combine
不能与当前的节点模块一起使用,而且不再维护:建议的替代品是nyc
.我在用Makefile
中的nyc
替换istanbul-combine
时遇到问题.
I've inherited a JS code base with Jasmine unit tests. The testing framework uses karma
and instanbul-combine
to get code coverage. It seems istanbul-combine
isn't working with present node modules, and besides is no longer maintained: the recommended replacement is nyc
. I'm having trouble replacing istanbul-combine
with nyc
in the Makefile
.
这是我尝试合并数据的尝试(甚至还没有尝试获取报告):
Here's are my attempts at merging the data (not even trying to get a report yet):
#1
@for dir in $(shell ls -d coverage/*/); do \
echo "Merging $${dir}"; \
npx nyc merge $${dir} coverage-final.json; \
done
#2
npx nyc merge coverage coverage-final.json
#3
npx nyc merge --include coverage/*/ coverage-final.json
coverage数据位于coverage/*/coverage-final.json
中,但是这些尝试均未能成功将其合并到结果文件coverage-final.json
中.
The coverage data is in coverage/*/coverage-final.json
, but none of these attempts succeeds in mergeing it into the result file coverage-final.json
.
使用#1,我可以肯定它实际上只是将一组结果合并到结果文件中.对于#2,会有一个错误.但是,如果我将该命令放在外壳CLI中,则结果文件中将不会放置任何内容.
With #1, I'm pretty sure it's only actually merging a single set of results into the result file. With #2, there's an error; but if I put that command in the shell CLI, nothing is put into the result file.
使用#3,至少没有错误,但是仅合并了一个coverage文件.
With #3, at least there's no error, but only one of the coverage files is merged.
这是我要替换的原始Makefile行:
Here's the original Makefile line that I'm replacing:
PATH=$(PROJECT_HOME)/bin:$$PATH node_modules/istanbul-combine/cli.js \
-d coverage/summary -r html \
coverage/*/coverage-final.json
推荐答案
我在Makefile中编写了一个小脚本,用于将coverage-final.json
文件从coverage
目录的子目录复制到coverage
目录本身,然后将它们合并到JS主目录中的coverage-final.json
文件中.
I wrote a little script in the Makefile to copy the coverage-final.json
files from the child directories of the coverage
directory to the coverage
directory itself, and then merge them into a coverage-final.json
file in the main JS directory.
@cd coverage; \
for dir in $(dir */coverage-final.json); do \
fn="$${dir}coverage-final.json"; \
newName="$${dir::-1}.json"; \
echo "cp $${fn} $${newName}"; \
cp $$fn $$newName; \
done;
npx nyc merge coverage coverage-final.json
各个覆盖率文件的新文件名取自它们所来自的目录的名称.
The new filenames of the individual coverage files are taken from the name of the directories from which they come.
这篇关于如何从Makefile运行nyc merge?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!