node.js - 用于 Mocha 测试的 Grunt : How to correctly setup . html 文件?

标签 node.js gruntjs mocha.js mocha-phantomjs

我是 grunttests 的新手,目前我的设置如下:
Grunt 运行任务,之后我有 build 文件夹,其中我有我编译的 index.html 和他的所有资源(css, js, 图片)
现在我想使用 grunt-mocha-phantomjs 运行测试,它需要添加到我的 index.html 中,例如:

<link href="../node_modules/mocha/mocha.css" media="screen" rel="stylesheet" type="text/css" />

head 标签内并且:

<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
<script src="../node_modules/chai/chai.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
mocha.ui('bdd');
expect = chai.expect;
</script>
<script src="test.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8">
mocha.run();
</script>

body 标签内。

我也希望能够在网络浏览器中打开修改后的 index.html。 (我已经为它设置了 apache 并且 example testgrunt 和网络浏览器中都很好用)
所以我计划使用任务 grunt-contrib-copy 将所有文件从我的 build 目录复制到 test 目录并将这些行添加到 index.html 然后启动 mocha_phantomjs 任务。

  • 这是正确的做法吗?
  • 哪个 NpmTask 可以做到?

最佳答案

不确定“这样做是否正确?”部分,但我解决了。
我使用了 grunt-html-build 及其 Removing parts功能。
移除build文件夹的phantom代码,保留testing文件夹。
效果很好。

关于node.js - 用于 Mocha 测试的 Grunt : How to correctly setup . html 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45667740/

相关文章:

javascript - 让 beforeEach 仅运行其所在文件中的测试

javascript - 使用 Mocha 测试数组的断言错误

node.js - 为什么在 Node.js 代码中使用 import 和 require()?

node.js - nodejs - 如何检查代码的哪一部分通过单元测试进行了测试?

angularjs - 如何将默认端点添加到 Angular $http 请求之前?

javascript - node.js - grunt - 从回调返回解析的数据

node.js - Dart VM 的性能与 Node.js 相比如何?

macos - 无法在 Mac os x 上使用 npm 安装 cordova

node.js - Grunt 服务器在 Nitrous.io 中无法工作

node.js - 如何检查元素是否不存在 selenium nodejs