├── .gitignore ├── .npmignore ├── .travis.yml ├── History.md ├── LICENSE.txt ├── Makefile ├── README.md ├── bin ├── JSCover-all.jar ├── jscover └── logging.properties ├── index.js ├── lib └── jscover.js ├── package.json ├── runtest-cov.bat ├── runtest.bat └── test ├── jscover.test.js └── lib ├── regexp.js └── subdir └── foo.js /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | cov/ 3 | __cov__* 4 | all-cov/ 5 | coverage.html 6 | *.seed 7 | *.log 8 | *.csv 9 | *.dat 10 | *.out 11 | *.pid 12 | *.gz 13 | 14 | pids 15 | logs 16 | results 17 | 18 | node_modules 19 | npm-debug.log 20 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test/ 2 | cov/ 3 | __cov__* 4 | all-cov/ 5 | coverage.html 6 | lib-cov/ 7 | Makefile 8 | .travis.yml 9 | logo.png 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.8 4 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | 2 | 1.0.0 / 2015-04-27 3 | ================== 4 | 5 | * Turn off console logging for newer JSCover (@saper) 6 | 7 | 0.2.4 / 2013-02-25 8 | ================== 9 | 10 | * change JSCover.jar to 0.1.1, fixed 0.2.x not work with mocha problem. 11 | 12 | 0.2.3 / 2013-02-18 13 | ================== 14 | 15 | * update JSCover-all.jar to 0.2.3 16 | * keep same version with JSCover-all.jar 17 | * remove 0.6 from travis 18 | 19 | 0.2.2 / 2013-01-31 20 | ================== 21 | 22 | * update JSCover to 0.2.1 23 | 24 | 0.2.1 / 2012-12-12 25 | ================== 26 | 27 | * fixed "must not be in the source directory" 28 | 29 | 0.2.0 / 2012-12-11 30 | ================== 31 | 32 | * update JSCover to v0.1.1 33 | * remove 0.9 from travis 34 | 35 | 0.1.1 / 2012-11-05 36 | ================== 37 | 38 | * fixed unittest for node0.6.x 39 | * use random temp dir name 40 | 41 | 0.1.0 / 2012-11-04 42 | ================== 43 | 44 | * support windows env 45 | * add more test cases 46 | * add subdir test case 47 | 48 | 0.0.4 / 2012-11-04 49 | ================== 50 | 51 | * fixed #1 support no-ascii char 52 | 53 | 0.0.3 / 2012-11-03 54 | ================== 55 | 56 | * remove commander, support `jscover . cov` 57 | 58 | 0.0.2 / 2012-11-03 59 | ================== 60 | 61 | * add logo 62 | * fixed bin script bug 63 | 64 | 0.0.1 / 2012-11-03 65 | ================== 66 | 67 | * add Makefile 68 | * finish first version 69 | * commander mode init 70 | * Initial commit 71 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | This software is licensed under the MIT License. 2 | 3 | Copyright (C) 2012 - 2014 by fengmk2 4 | Copyright (C) 2015 node-modules and other contributors. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TESTS = test/*.test.js 2 | REPORTER = spec 3 | TIMEOUT = 5000 4 | GLOBALS = _*jscoverage 5 | 6 | test: 7 | @NODE_ENV=test ./node_modules/mocha/bin/mocha \ 8 | --reporter $(REPORTER) \ 9 | --globals $(GLOBALS) \ 10 | --timeout $(TIMEOUT) \ 11 | $(TESTS) 12 | 13 | test-cov: 14 | @$(MAKE) lib-cov 15 | @JSCOVER_COV=1 $(MAKE) test 16 | @JSCOVER_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html 17 | 18 | all-cov: 19 | @node ./bin/jscover --exclude=lib-cov --exclude=test --exclude=bin . $@ 20 | 21 | lib-cov: 22 | @node ./bin/jscover lib $@ 23 | 24 | .PHONY: test-cov test lib-cov all-cov 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | jscover 2 | ======= 3 | 4 | node wrap for [JSCover](http://tntim96.github.com/JSCover/). 5 | 6 | * jscoverage: [94%](http://fengmk2.github.com/coverage/jscover.html) 7 | 8 | ## Install 9 | 10 | ```bash 11 | $ npm install jscover -g 12 | ``` 13 | 14 | ## Usage 15 | 16 | Just like `jscoverage` 17 | 18 | ```bash 19 | # jscoverage lib lib-cov 20 | $ jscover lib lib-cov 21 | ``` 22 | 23 | ## Authors 24 | 25 | ```bash 26 | $ git summary 27 | 28 | project : jscover 29 | repo age : 4 months 30 | active : 9 days 31 | commits : 30 32 | files : 18 33 | authors : 34 | 30 fengmk2 100.0% 35 | ``` 36 | 37 | ## License 38 | 39 | [MIT](LICENSE.txt) 40 | -------------------------------------------------------------------------------- /bin/JSCover-all.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alibaba-archive/jscover/96ae4ea68c1ab73919ad3dea97f7b095b785e9e3/bin/JSCover-all.jar -------------------------------------------------------------------------------- /bin/jscover: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /*! 4 | * jscover - bin/jscover.js 5 | * Copyright(c) 2012 fengmk2 6 | * MIT Licensed 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * Module dependencies. 13 | */ 14 | 15 | var jscover = require('../'); 16 | 17 | var args = process.argv.slice(2); 18 | var length = args.length; 19 | var source = args[length - 2]; 20 | var target = args[length - 1]; 21 | 22 | jscover(source, target, args.slice(0, length - 2), function (err, stdout) { 23 | if (err) { 24 | if (stdout) { 25 | console.error(stdout); 26 | } 27 | throw err; 28 | } 29 | if (stdout) { 30 | console.log(stdout); 31 | } 32 | }); -------------------------------------------------------------------------------- /bin/logging.properties: -------------------------------------------------------------------------------- 1 | handlers = java.util.logging.ConsoleHandler 2 | java.util.logging.ConsoleHandler.level = SEVERE 3 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = process.env.JSCOVER_COV ? require('./lib-cov/jscover') : require('./lib/jscover'); -------------------------------------------------------------------------------- /lib/jscover.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jscover - lib/jscover.js 3 | * Copyright(c) 2012 fengmk2 4 | * MIT Licensed 5 | */ 6 | 7 | "use strict"; 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var debug = require('debug')('jscover'); 14 | var exec = require('child_process').exec; 15 | var path = require('path'); 16 | var ndir = require('ndir'); 17 | var fse = require('fs-extra'); 18 | var fs = require('fs'); 19 | 20 | var root = path.dirname(__dirname); 21 | var JSCoverPath = process.env.JSCOVER || path.join(root, 'bin', 'JSCover-all.jar'); 22 | var JSCoverLogging = path.join(root, 'bin', 'logging.properties'); 23 | var JSCoverCommand = ['java', 24 | '-Dfile.encoding=UTF-8', 25 | '-Djava.util.logging.config.file="' + JSCoverLogging + '"', 26 | '-jar "' + JSCoverPath + '"', 27 | '-fs'].join(' '); 28 | 29 | /** 30 | * Pedding codes to support nodejs 31 | * @type {String} 32 | */ 33 | var PEDDING = "/* ****** automatically generated by jscover - do not edit ******/\n\ 34 | if (typeof _$jscoverage === 'undefined') { _$jscoverage = {}; }\n\ 35 | /* ****** end - do not edit ******/\n"; 36 | 37 | module.exports = function jscover(source, target, options, callback) { 38 | source = source || ''; 39 | target = target || ''; 40 | options = options || []; 41 | var tmpName = '__cov__' + Date.now(); 42 | var tmpdir = process.env.TMPDIR || '/tmp'; 43 | var tmpTargetDir = path.join(tmpdir, tmpName); 44 | var tmpTarget = path.join(tmpTargetDir, path.basename(target)); 45 | 46 | var cleanup = function () { 47 | fse.removeSync(tmpTargetDir); 48 | fse.removeSync(path.join(target, tmpName)); 49 | }; 50 | 51 | var cmd = JSCoverCommand; 52 | if (options && options.length > 0) { 53 | cmd += ' ' + options.join(' '); 54 | } 55 | cmd += ' --exclude=node_modules --exclude=.git/ --exclude=.svn/'; 56 | cmd += ' --exclude="' + tmpTarget + '" --exclude="' + target + '"'; 57 | cmd += ' "' + source + '" "' + tmpTarget + '"'; 58 | debug(cmd); 59 | var child = exec(cmd, function (err, stdout, stderr) { 60 | var output = ''; 61 | if (stdout) { 62 | output += stdout; 63 | } 64 | if (stderr) { 65 | output += stderr; 66 | if (!err) { 67 | err = new Error(stderr.trim()); 68 | } 69 | err.name = 'JSCover' + err.name; 70 | } 71 | if (err) { 72 | debug(err, stderr); 73 | cleanup(); 74 | return callback(err, output); 75 | } 76 | 77 | var success = !stdout && !stderr; 78 | if (!success) { 79 | return callback(null, output); 80 | } 81 | ndir.walk(tmpTarget, function onDir(dirpath, items) { 82 | var todir = dirpath.replace(tmpTarget, target); 83 | fse.mkdirpSync(todir); 84 | for (var i = 0; i < items.length; i++) { 85 | var info = items[i]; 86 | var from = info[0]; 87 | var name = path.basename(from); 88 | if (name === '.git' || name === '.svn' || name.indexOf('jscoverage') === 0) { 89 | continue; 90 | } 91 | var to = path.join(todir, path.basename(from)); 92 | if (info[1].isDirectory()) { 93 | fse.mkdirpSync(to); 94 | } else if (info[1].isFile()) { 95 | var content = fs.readFileSync(from); 96 | if (path.extname(to).toLowerCase() === '.js') { 97 | content = PEDDING + content.toString(); 98 | } 99 | fs.writeFileSync(to, content); 100 | } 101 | } 102 | }, function end() { 103 | cleanup(); 104 | callback(); 105 | }, function error(err, errPath) { 106 | cleanup(); 107 | console.error('%s error: %s', errPath, err); 108 | callback(err); 109 | }); 110 | 111 | }); 112 | }; 113 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jscover", 3 | "version": "1.0.0", 4 | "description": "node wrap for JSCover.", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "bin": { 10 | "jscover": "./bin/jscover" 11 | }, 12 | "scripts": { 13 | "test": "make test" 14 | }, 15 | "dependencies": { 16 | "fs-extra": "0.3.1", 17 | "debug": "0.7.0", 18 | "ndir": "0.1.5" 19 | }, 20 | "devDependencies": { 21 | "should": "*", 22 | "mocha": "*" 23 | }, 24 | "repository": { 25 | "type": "git", 26 | "url": "git://github.com/fengmk2/jscover.git" 27 | }, 28 | "keywords": [ 29 | "jscover", 30 | "JSCover", 31 | "jscoverage" 32 | ], 33 | "author": "fengmk2 ", 34 | "license": "MIT" 35 | } 36 | -------------------------------------------------------------------------------- /runtest-cov.bat: -------------------------------------------------------------------------------- 1 | node bin\jscover lib lib-cov 2 | 3 | SET JSCOVER_COV=1 4 | 5 | node_modules\.bin\mocha --globals _*jscoverage && node_modules\.bin\mocha --globals _*jscoverage --reporter html-cov > coverage.html -------------------------------------------------------------------------------- /runtest.bat: -------------------------------------------------------------------------------- 1 | node_modules\.bin\mocha --globals _*jscoverage --reporter spec -------------------------------------------------------------------------------- /test/jscover.test.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jscover - test/jscover.test.js 3 | * Copyright(c) 2012 fengmk2 4 | * MIT Licensed 5 | */ 6 | 7 | "use strict"; 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var jscover = require('../'); 14 | var should = require('should'); 15 | var path = require('path'); 16 | var fs = require('fs'); 17 | var fse = require('fs-extra'); 18 | fs.existsSync = fs.existsSync || path.existsSync; 19 | 20 | 21 | describe('jscover.test.js', function () { 22 | var source = path.join(__dirname, 'lib'); 23 | var target = path.join(__dirname, 'lib-cov'); 24 | 25 | beforeEach(function () { 26 | fse.removeSync(target); 27 | }); 28 | 29 | it('should coverage lib to lib-cov', function (done) { 30 | should.ok(!fs.existsSync(target)); 31 | jscover(source, target, null, function (err, stdout) { 32 | should.not.exist(err); 33 | should.not.exist(stdout); 34 | should.ok(fs.existsSync(target)); 35 | done(); 36 | }); 37 | }); 38 | 39 | it('should coverage lib to lib-cov with --exclude=subdir', function (done) { 40 | should.ok(!fs.existsSync(target)); 41 | should.ok(!fs.existsSync(path.join(target, 'subdir'))); 42 | jscover(source, target, ['--exclude=subdir'], function (err, stdout) { 43 | should.not.exist(err); 44 | should.not.exist(stdout); 45 | should.ok(fs.existsSync(target)); 46 | should.ok(!fs.existsSync(path.join(target, 'subdir'))); 47 | done(); 48 | }); 49 | }); 50 | 51 | it('should return stdout when args missing', function (done) { 52 | jscover('', null, {}, function (err) { 53 | should.exist(err); 54 | err.name.should.equal('JSCoverError'); 55 | err.message.trim().should.endWith("Source directory '' is invalid"); 56 | done(); 57 | }); 58 | }); 59 | 60 | it('should return error when dir not exists', function (done) { 61 | jscover('a', 'b', {}, function (err) { 62 | should.exist(err); 63 | err.name.should.equal('JSCoverError'); 64 | err.message.trim().should.endWith("Source directory 'a' is invalid"); 65 | done(); 66 | }); 67 | }); 68 | 69 | describe('utf8', function () { 70 | it('should coverage no-ascii char success', function (done) { 71 | should.ok(!fs.existsSync(target)); 72 | jscover(source, target, null, function (err, output) { 73 | should.not.exist(err); 74 | should.not.exist(output); 75 | var regexp = fs.readFileSync(path.join(source, 'regexp.js'), 'utf8'); 76 | fs.readFileSync(path.join(target, 'regexp.js'), 'utf8').should.containEql(regexp); 77 | var targetFoo = require(path.join(target, 'subdir', 'foo')); 78 | var sourceFoo = require(path.join(source, 'subdir', 'foo')); 79 | for (var k in sourceFoo) { 80 | sourceFoo[k].should.equal(targetFoo[k]); 81 | } 82 | done(); 83 | }); 84 | }); 85 | }); 86 | }); 87 | -------------------------------------------------------------------------------- /test/lib/regexp.js: -------------------------------------------------------------------------------- 1 | var foo = /,|,你好/ig; -------------------------------------------------------------------------------- /test/lib/subdir/foo.js: -------------------------------------------------------------------------------- 1 | exports.hello = '你好,Hello world'; 2 | exports.hexNumber = 0x12; 3 | exports.count = 16; 4 | 5 | exports.hexNumber2 = 0xff; --------------------------------------------------------------------------------