Use Blanket. js instead of jscover

Source: Internet
Author: User

Before encountering Blanket. js, I used this jscover for code coverage testing.

Jscover

The advantage of using jscover is that the java version is used directly without compilation. The disadvantage is that the java environment dependency is required.
Use Makefile to drive the entire test execution, such as urllib/Makefile

TESTS = test/*.test.jsREPORTER = specTIMEOUT = 20000JSCOVERAGE = ./node_modules/jscover/bin/jscovertest:  @NODE_ENV=test ./node_modules/mocha/bin/mocha \    --reporter $(REPORTER) \    --timeout $(TIMEOUT) \    $(TESTS)test-cov:  @rm -rf ./lib-cov  @$(JSCOVERAGE) lib lib-cov  @URLLIB_COV=1 $(MAKE) test REPORTER=dot  @URLLIB_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html.PHONY: test test-cov

Run the code coverage test:

$ make test-cov

Open coverage.html to see the coverage.

Blanket. js

One day on github, I saw Blanket. js, which was an unexpected result and finally got rid of Code Conversion dependencies.

Blanket. js is an easy to install, easy to configure, and easy to use JavaScript code coverage library that works both in-browser and with nodejs.

After using balancer. js, you no longer need to convert the code into a file or use java dependencies.

Take urllib/Makefile as an example:

TESTS = test/*.test.jsREPORTER = specTIMEOUT = 20000MOCHA_OPTS =test:  @NODE_ENV=test ./node_modules/mocha/bin/mocha \    --reporter $(REPORTER) \    --timeout $(TIMEOUT) \    $(MOCHA_OPTS) \    $(TESTS)test-cov:  @URLLIB_COV=1 $(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=dot  @URLLIB_COV=1 $(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov > coverage.html.PHONY: test test-cov

Refer to Getting Started Guide (nodejs version)

In package. json, add the code matching mode of blanket. Make sure you want to convert the code in that path.

"scripts": {  "test": "make test",  "blanket": { "pattern": "urllib/lib" }},

The command execution remains the same:

$ make test-cov

coverage.htmlThe results are the same as those of the jscover report. If no file is generated, you do not need to install java on the server.

Project

For non-lib-type projects, such as common application projects, code coverage testing can also be done well using Blanket. js.

Take urlrar as an example:

Markfile

TESTS = test/*.test.jsREPORTER = specTIMEOUT = 10000MOCHA_OPTS =install:  @npm installtest: install  @NODE_ENV=test ./node_modules/mocha/bin/mocha \    --reporter $(REPORTER) \    --timeout $(TIMEOUT) \    $(MOCHA_OPTS) \    $(TESTS)test-cov:   @URLRAR_COV=1 $(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=html-cov > coverage.html  @URLRAR_COV=1 $(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=travis-covtest-all: test test-cov.PHONY: test-cov test test-all

Package. json

"devDependencies": {    "travis-cov": "*",    "blanket": "*",    // ...  },  "scripts": {    "test": "make test-all",    "blanket": {       "pattern": "//^((?!(node_modules|test)).)*$/",      "data-cover-flags": {        "debug": false      }    },    "travis-cov": {      "threshold": 93    }  },
$ npm test 

Running result: contains test results and code coverage.


1 Love

^_^ I hope this article will be useful to you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.