我的测试文件夹结构如下所示:
<test>
<test1>
<test2>
<test3>
是否可以编写一个makefile,在单个文件夹或文件夹的一些列表中执行测试?
由于
答案 0 :(得分:3)
当然有可能:
# I like to allow the user to override the default mocha with whatever
# they want in case they are running an experimental version.
MOCHA?=mocha
# Useful to pass ad hoc parameters to mocha.
MOCHA_PARAMS?=
# To work around the fact that commas are argument separators.
comma:=,
.PHONY: test test%
# Do all the tests.
test:
$(MOCHA) --recursive $(MOCHA_PARAMS)
# Allows for combining tests in an ad hoc manner.
test%:
$(MOCHA) $(MOCHA_PARAMS) $(foreach test,$(subst $(comma), ,$(@:test%=%)),test/test$(test))
最后一个目标允许您执行以下操作:
make test1 # runs the tests in test/test1 only
make test1,2 # runs the tests in test/test1 and test/test2
make test1,2,3 # runs the tests in test/test1, test/test2, test/test3
make test1,3 # runs the tests in test/test1, and test/test3
最后一个目标中发生的事情是目标名称(例如test1,2
)已剥离test
前缀,在逗号上拆分,然后每个部分都以test/test
为前缀
如果要测试它,请将上面的代码复制到Makefile中,然后创建test
目录和任意数量的名为test1
,test2
,... {{testN
的子目录。 1}}在它下面。
答案 1 :(得分:0)
根本不需要使用make。尝试将以下内容添加到package.json的脚本部分:
"test": "mocha -R spec --recursive",
"test1": "mocha -R spec test/test1",
"test2": "mocha -R spec test/test2",
"test3": "mocha -R spec test/test3",
"test13": "mocha -R spec test/test1 test/test3",
然后,您可以npm test
或npm run test
或npm run test13
。
答案 2 :(得分:0)
我的解决方案是
test:
@./node_modules/.bin/mocha -R spec -r should --recursive
cloudApi:
find $(CURDIR)/test/cloudApi -iname "*.js" | xargs node_modules/mocha/bin/mocha -R spec -r should
injectors:
find $(CURDIR)/test/injectors -iname "*.js" | xargs node_modules/mocha/bin/mocha -R spec -r should
.PHONY: test cloudApi injectors
并且执行本身看起来像: mocha test / cloudApi / injectors ...