如何使用makefile和mocha在子文件夹中运行测试

如何使用makefile和mocha在子文件夹中运行测试,makefile,mocha.js,Makefile,Mocha.js,我的测试文件夹结构如下所示: <test> <test1> <test2> <test3> 是否可以编写一个makefile,在单个文件夹或一些排列的文件夹中执行测试 谢谢根本不需要使用make。尝试将以下内容添加到package.json的脚本部分: "test": "mocha -R spec --recursive", "test1": "mocha -R spec test/test1", "test2": "

我的测试文件夹结构如下所示:

<test>
    <test1>
    <test2>
    <test3>

是否可以编写一个makefile,在单个文件夹或一些排列的文件夹中执行测试


谢谢

根本不需要使用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
根本不需要使用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
根本不需要使用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
根本不需要使用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测试
npm运行测试
npm运行测试13
确保这是可能的:

# 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
<代码>测试n在它下面。

确保有可能:

# 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
<代码>测试n在它下面。

确保有可能:

# 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
<代码>测试n在它下面。

确保有可能:

# 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
<代码>测试在它下面。

我的解决方案是

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
执行本身看起来像: 摩卡测试/cloudApi/注射器…

我的解决方案是

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
执行本身看起来像: 摩卡测试/cloudApi/注射器…

我的解决方案是

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
执行本身看起来像: 摩卡测试/cloudApi/注射器…

我的解决方案是

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
执行本身看起来像: 摩卡测试/cloudApi/注射器