5

How can I run code coverage for client side javascript code using grunt?

I have run the client side javascript code test using mocha-phantomjs to be tested using html page, and it works fine, but I couldn't find a way to run code coverage for it.

It will be great if there is some sample code.

4

1 回答 1

2

我发现使用mocha phantomjs istanbul并通过grun浏览器来完成它。

在客户端 JS 源代码中,确保通过 window 对象公开您的公共 var(s) 或函数,以便在通过 browserify 生成检测文件后使其可访问。这是一个例子:https ://github.com/shadiabuhilal/js-code-coverage-example/blob/master/src/example.js#L36

开发依赖:

"browserify-istanbul": "^0.2.1",
"chai": "^1.10.0",
"grunt": "^0.4.5",
"grunt-browserify": "^3.7.0",
"grunt-cli": "^0.1.13",
"grunt-contrib-clean": "^0.6.0",
"grunt-mocha-phantom-istanbul": "^0.2.1",
"mocha": "^2.1.0"

要查看完整示例,请查看以下 repo:

https://github.com/shadiabuhilal/js-code-coverage-example

于 2015-04-28T00:55:51.910 回答