我的 package.json
中有一个如下所示的脚本:
"scripts": {
"test": "... && mocha --full-trace test/db test/http test/storage test/utils",
我想将 --async-stack-traces
传递给 mocha,但 --async-stack-traces
是节点命令行参数,而不是 mocha 命令行参数。
我想我可以通过运行 node --async-stack-traces node_modules/mocha/bin/mocha --full-trace test/db test/http test/storage test/utils
来实现这一点,但是关于它的一些东西感觉不雅或不惯用。还有其他方法可以实现吗?
答案 0 :(得分:1)
你写的方式基本上就是这样做的方式:
node --async-stack-traces node_modules/mocha/bin/mocha --full-trace test/db test/http test/storage test/utils
您可以像这样使用 node_modules/.bin
来整理一下:
node --async-stack-traces node_modules/.bin/mocha --full-trace test/db test/http test/storage test/utils
下一个可能不是 Windows 兼容的,也不那么容易理解,但是如果您只支持类 UNIX 操作系统,则可以依靠 $PATH
脚本的 npm
注入来整理多一点:
node --async-stack-traces `which mocha` --full-trace test/db test/http test/storage test/utils
如果不想依赖whereis
,可以使用npm bin
:
node --async-stack-traces `npm bin`/mocha --full-trace test/db test/http test/storage test/utils
希望在这一点上,您举手并回到上面的第一个或第二个选项。 (我推荐第二个选项,这样您就不会依赖于 mocha
包布局,这可能会发生变化。)