【发布时间】:2016-06-09 01:45:11
【问题描述】:
我在./test 中有 2 个测试文件。
假设test1.js 是一个 Mocha 测试,它启动服务器并针对 URI 运行各种请求,以确定它们都按预期运行。
test2.js 是一个 Mocha 测试,它使用 Karma 加载特定脚本(包括 angular-mocks.js)并在几个浏览器中运行,以确保 那里的所有功能都按预期运行。
在package.json 中,我将test 属性配置为:
"scripts": {
"test": "./node_modules/.bin/mocha --reporter spec -t 5000"
},
酷,我可以通过命令行npm test 来运行 Mocha。但是哦,不,Mocha 运行了我的两个脚本,test2.js 当然会使整个事情崩溃,因为其中的逻辑假设它是在 Karma 的上下文中运行的(如果我没有正确描述这一点,请原谅)。
我可以有 2 个测试文件夹,test 和 test-ng 之类的,但我认为最终我希望能够 npm test 并运行不同的测试集,即:
"./node_modules/.bin/mocha --reporter spec -t 5000"
"./node_modules/.bin/karma start"
并将它们配置为每个运行正确的 js 文件。我一直在疯狂地寻找一个例子,其中客户端和服务器端测试存在于同一个 repo 中,但我只找到教程和博客文章等来演示其中一个。有人可以帮助我朝着正确的方向前进吗?
编辑:我应该这样考虑/组织我的测试吗?
./tests/server/**.js
./tests/e2e/**.js
./tests/unit/**.js
我可能基于 npm 默认使用 ./test/ 文件夹这一事实做出假设。
编辑 2:我现在或多或少地在做我上面描述的事情,并且在 repo 的自述文件中描述了我的测试,例如:
Angular 单元测试可以通过 Karma 运行:
./node_modules/.bin/karma start karma.conf.jsAngular 端到端测试可以通过 Protractor 运行:
./node_modules/.bin/protractor protractor.conf.jsExpress 单元测试可以通过 Mocha 运行:
./node_modules/.bin/mocha ...
所以现在我根本不使用npm test,我想知道使用它有什么好处。
【问题讨论】:
-
无论谁投票结束,我认为这根本不是基于意见的。我可以将问题标题重命名为“How can you have 2 different test sets in an npm script directive”,但这不是解释性的。
标签: mocha.js karma-runner karma-mocha