jscoverage modified to support SSJS
C++ C Shell JavaScript Perl Python Other
Pull request Compare This branch is 23 commits behind sunfang1cn:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
js
m4
tests
COPYING
Makefile.am
Makefile.in
Readme.md
aclocal.m4
build.sh
config.guess
config.h.in
config.rpath
config.sub
configure
configure.ac
depcomp
encoding.c
encoding.h
generate-resources.c
global.h
highlight.c
highlight.h
http-connection.c
http-exchange.c
http-host.c
http-message.c
http-server.c
http-server.h
http-url.c
index.js
install-sh
instrument-js.cpp
instrument-js.h
instrument.c
instrument.h
jscoverage-help.txt
jscoverage-highlight.css
jscoverage-ie.css
jscoverage-overlay.js
jscoverage-server-help.txt
jscoverage-server.1
jscoverage-server.c
jscoverage-throbber.gif
jscoverage.1
jscoverage.c
jscoverage.cpp
jscoverage.css
jscoverage.html
jscoverage.js
jscoverage.jsm
jscoverage.manifest
jscoverage.xul
make-bin-dist.sh.in
make-dist.sh.in
missing
package.json
report.js
resource-manager.c
resource-manager.h
stream.c
stream.h
util.c
util.h
wscript

Readme.md

node-jscoverage

JScoverage for node.

Installation

  $ npm  install jscoverage

How to Use

  /** for nodejs **/
  var jsc = require('jscoverage');
  require = jsc.require(module); // rewrite require function
  // pay attention to the second param, means do jscoverage process for this module
  var test_module = require('module for test',true); 

  describe('module',function(){
     describe('#func',function(){
        it('some test',function(){
           //TODO test code here
        });
     });
  });
  // output the coverage when test process exit, you can custom your own coverage report 
  // because the jscoverage report is really easy to DIY
  process.on('exit',function(){
     jsc.coverage();
  });

  /** 
     for javascript in browser,you need a node server to hold your js code,
     when browser request the js file, using jscoverage to process the file content,
     then output the jscoverage injected code .
  **/
  http.create(function(req,res){
     var path = wwwroot + req.url;
     // process single file
     var content = jsc.processFile(path,encode);
     res.end(content);
  }

API

  jsc.processFile(path|content,encode);
     path | content 待转化的文件地址,或文件内容
     encode 文件编码
  jsc.processDir(source_path, dest_path, exclude, exclude_file, options);
  jsc.require(module)
  jsc.coverage()

test private functions in a module

  ======== mo.js ========
  function inner(a,b){
     return a+b;
  }
  exports.mo = function(){}

  ======= test.js =======
  var test_mo = require('./mo.js', true);
  test_mo._test('inner',[1,2]); // test private function inner
  var inner = test_mo._get('inner');
  inner(1,2); // call the private inner function of the mo module