├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── cli.js ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | coverage 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | git: 3 | depth: 2 4 | branches: 5 | except: 6 | - /^v\d/ 7 | language: node_js 8 | node_js: 9 | - iojs 10 | - node 11 | notifications: 12 | email: false 13 | script: 14 | - npm run-script coverage 15 | after_script: 16 | - npm run-script coveralls 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 - 2016 Shinnosuke Watanabe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # istanbul-coveralls 2 | 3 | [![NPM version](https://img.shields.io/npm/v/istanbul-coveralls.svg)](https://www.npmjs.com/package/istanbul-coveralls) 4 | [![Build Status](https://travis-ci.org/shinnn/istanbul-coveralls.svg?branch=master)](https://travis-ci.org/shinnn/istanbul-coveralls) 5 | [![Coverage Status](https://img.shields.io/coveralls/shinnn/istanbul-coveralls.svg)](https://coveralls.io/r/shinnn/istanbul-coveralls?branch=master) 6 | [![Dependency Status](https://david-dm.org/shinnn/istanbul-coveralls.svg)](https://david-dm.org/shinnn/istanbul-coveralls) 7 | [![devDependency Status](https://david-dm.org/shinnn/istanbul-coveralls/dev-status.svg)](https://david-dm.org/shinnn/istanbul-coveralls#info=devDependencies) 8 | 9 | A simple alias for [istanbul](https://github.com/gotwarlost/istanbul) + [node-coveralls](https://github.com/cainus/node-coveralls) 10 | 11 | ```sh 12 | istanbul cover test.js && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage 13 | ``` 14 | 15 | ↓ 16 | 17 | ```sh 18 | istanbul cover test.js && istanbul-coveralls 19 | ``` 20 | 21 | ## Installation 22 | 23 | [Use npm](https://docs.npmjs.com/cli/install). 24 | 25 | ```sh 26 | npm install --save-dev istanbul istanbul-coveralls 27 | ``` 28 | 29 | ## Usage 30 | 31 | 1. Write a coverage information file under `./coverage` by using [`istanbul cover` command](https://github.com/gotwarlost/istanbul#the-cover-command) or [the API of istanbul](https://github.com/gotwarlost/istanbul#api). 32 | 2. Run `istanbul-coveralls` command. See [the docs of node-coveralls](https://github.com/cainus/node-coveralls#usage) for more information about its usage. 33 | 34 | ### Option 35 | 36 | #### `--no-rm` 37 | 38 | By default, it removes `./coverage` after coverage reporting. If `--no-rm` flag is enabled, it doesn't remove the directory. 39 | 40 | ```sh 41 | istanbul cover test.js && istanbul-coveralls --no-rm 42 | ``` 43 | 44 | ## Example 45 | 46 | ### [Mocha](http://mochajs.org/) 47 | 48 | ```sh 49 | istanbul cover ./node_modules/.bin/_mocha && ./node_modules/.bin/istanbul-coveralls 50 | ``` 51 | 52 | If you run the test as a [npm script](https://docs.npmjs.com/misc/scripts), [you can omit directory names from the command](https://docs.npmjs.com/misc/scripts#path). 53 | 54 | ```sh 55 | istanbul cover _mocha && istanbul-coveralls 56 | ``` 57 | 58 | ## License 59 | 60 | Copyright (c) 2014 - 2016 [Shinnosuke Watanabe](https://github.com/shinnn) 61 | 62 | Licensed under [the MIT LIcense](./LICENSE). 63 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | var argv = require('minimist')(process.argv.slice(2), { 5 | alias: { 6 | h: 'help', 7 | v: 'version' 8 | }, 9 | boolean: ['help', 'rm', 'version'] 10 | }); 11 | 12 | if (argv.version) { 13 | console.log(require('./package.json').version); 14 | } else if (argv.help) { 15 | var sumUp = require('sum-up'); 16 | var yellow = require('chalk').yellow; 17 | 18 | var pkg = require('./package.json'); 19 | 20 | console.log([ 21 | sumUp(pkg), 22 | '', 23 | 'Example:', 24 | ' istanbul cover test.js && istanbul-coveralls', 25 | 'Options:', 26 | yellow(' -h, --help ') + ' print usage information', 27 | yellow(' -v, --version') + ' print version', 28 | yellow(' --no-rm ') + ' preserve ./coverage directory after coverage reporting' 29 | ].join('\n')); 30 | } else { 31 | require('./')({rimraf: argv.rm}, function(err) { 32 | if (err) { 33 | throw err; 34 | } 35 | }); 36 | } 37 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * istanbul-coveralls | MIT (c) Shinnosuke Watanabe 3 | * https://github.com/shinnn/istanbul-coveralls 4 | */ 5 | 6 | 'use strict'; 7 | 8 | var fs = require('fs'); 9 | 10 | var handleInput = require('coveralls').handleInput; 11 | var rimraf = require('rimraf'); 12 | 13 | module.exports = function istanbulCoveralls(option, cb) { 14 | if (cb === undefined) { 15 | cb = option; 16 | option = {rimraf: true}; 17 | } 18 | 19 | fs.readFile('./coverage/lcov.info', 'utf8', function(err, content) { 20 | if (err) { 21 | cb(err); 22 | return; 23 | } 24 | 25 | handleInput(content, function(msg) { 26 | if (msg) { 27 | cb(new Error(msg)); 28 | return; 29 | } 30 | 31 | if (option.rimraf) { 32 | rimraf('./coverage', cb); 33 | } else { 34 | cb(); 35 | } 36 | }); 37 | }); 38 | }; 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "istanbul-coveralls", 3 | "version": "1.0.3", 4 | "description": "A simple alias for istanbul + coveralls", 5 | "repository": "shinnn/istanbul-coveralls", 6 | "author": "Shinnosuke Watanabe (https://github.com/shinnn)", 7 | "scripts": { 8 | "pretest": "eslint --config @shinnn/cli --env mocha --rule 'no-reserved-keys: 0' --ignore-path .gitignore .", 9 | "test": "_mocha test.js --timeout 25600", 10 | "coverage": "istanbul cover _mocha test.js -- --timeout 25600", 11 | "coveralls": "${npm_package_scripts_coverage} && ${npm_package_bin}" 12 | }, 13 | "license": "MIT", 14 | "bin": "cli.js", 15 | "files": [ 16 | "cli.js", 17 | "index.js" 18 | ], 19 | "keywords": [ 20 | "istanbul", 21 | "coveralls", 22 | "command", 23 | "command-line", 24 | "cli", 25 | "coverage", 26 | "report", 27 | "integration", 28 | "lcov", 29 | "shorten", 30 | "alias" 31 | ], 32 | "dependencies": { 33 | "chalk": "^1.1.3", 34 | "coveralls": "^2.11.9", 35 | "minimist": "^1.2.0", 36 | "rimraf": "^2.5.2", 37 | "sum-up": "^2.0.0" 38 | }, 39 | "devDependencies": { 40 | "@shinnn/eslint-config-cli": "^1.0.0", 41 | "eslint": "^2.10.1", 42 | "istanbul": "^0.4.3", 43 | "mocha": "^2.4.5", 44 | "output-file": "^1.1.1" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | /* eslint no-shadow: 0 */ 2 | 'use strict'; 3 | 4 | var assert = require('assert'); 5 | var exec = require('child_process').exec; 6 | var fs = require('fs'); 7 | var path = require('path'); 8 | 9 | var outputFile = require('output-file'); 10 | var rimraf = require('rimraf'); 11 | 12 | var istanbulCoveralls = require('./'); 13 | var pkg = require('./package.json'); 14 | 15 | var fixtureLcov; 16 | /* istanbul ignore if */ 17 | if (process.env.npm_lifecycle_event === 'coveralls') { 18 | fixtureLcov = fs.readFileSync('coverage/lcov.info'); 19 | } else { 20 | fixtureLcov = 'TN:\nSF:' + path.resolve('fixture.js') + 21 | '\nFNF:0\nFNH:0\nLF:0\nLH:0\nBRF:0\nBRH:0\nend_of_record\n'; 22 | 23 | // Set temporary JOB ID for testing 24 | process.env.COVERALLS_SERVICE_JOB_ID = '33674997'; 25 | } 26 | 27 | var writeLcov = outputFile.bind(null, 'coverage/lcov.info', fixtureLcov); 28 | 29 | before(fs.writeFile.bind(null, './fixture.js', '')); 30 | beforeEach(rimraf.bind(null, './coverage')); 31 | after(rimraf.bind(null, './fixture.js')); 32 | 33 | describe('istanbulCoveralls()', function() { 34 | it('should pass an error when lcov.info doesn\'t exist.', function(done) { 35 | istanbulCoveralls(function(err) { 36 | assert(err); 37 | assert.strictEqual(err.code, 'ENOENT'); 38 | done(); 39 | }); 40 | }); 41 | 42 | it('should not overwrite arguments.', function(done) { 43 | var callback = function() { 44 | assert.strictEqual(typeof callback, 'function'); 45 | done(); 46 | }; 47 | istanbulCoveralls(callback); 48 | }); 49 | 50 | it('should pass an error when it cannot parse lcov.info.', function(done) { 51 | outputFile('coverage/lcov.info', 'dummy', function(err) { 52 | assert.strictEqual(err, null); 53 | istanbulCoveralls(function(err) { 54 | assert.strictEqual(err.message, 'Failed to parse string'); 55 | done(); 56 | }); 57 | }); 58 | }); 59 | 60 | it('should not pass an error when it takes valid lcov.info.', function(done) { 61 | writeLcov(function(err) { 62 | assert.strictEqual(err, null); 63 | istanbulCoveralls(done); 64 | }); 65 | }); 66 | 67 | it('should not remove ./coverage when `rimraf` option is enabled.', function(done) { 68 | writeLcov(function(err) { 69 | assert.strictEqual(err, null); 70 | istanbulCoveralls({rimraf: false}, function(err) { 71 | assert.strictEqual(err, undefined); 72 | assert.equal(arguments.length, 0); 73 | fs.stat('./coverage', function(err, stat) { 74 | assert.strictEqual(err, null); 75 | assert(stat.isDirectory()); 76 | done(); 77 | }); 78 | }); 79 | }); 80 | }); 81 | }); 82 | 83 | describe('"istanbul-coveralls" command', function() { 84 | it('should run index.js script.', function(done) { 85 | writeLcov(function(err) { 86 | assert.strictEqual(err, null); 87 | exec('node cli.js', done); 88 | }); 89 | }); 90 | 91 | it('should print error message when the script throws an error.', function(done) { 92 | outputFile('coverage/lcov.info', 'dummy', function(err) { 93 | assert.ifError(err); 94 | exec('node cli.js', function(err) { 95 | assert(err); 96 | assert(/Failed to parse string/.test(err.message)); 97 | done(); 98 | }); 99 | }); 100 | }); 101 | 102 | it('should print usage informaion when `--help` flag is enabled.', function(done) { 103 | exec('node cli.js --help', function(err, stdout) { 104 | assert(/print usage information/.test(stdout)); 105 | done(err); 106 | }); 107 | }); 108 | 109 | it('should accept `-h` alias.', function(done) { 110 | exec('node cli.js -h', function(err, stdout) { 111 | assert(/Example/.test(stdout)); 112 | done(err); 113 | }); 114 | }); 115 | 116 | it('should print version when `--version` flag is enabled.', function(done) { 117 | exec('node cli.js --version', function(err, stdout) { 118 | assert.strictEqual(stdout, pkg.version + '\n'); 119 | done(err); 120 | }); 121 | }); 122 | 123 | it('should accept `-v` alias.', function(done) { 124 | exec('node cli.js -v', function(err, stdout) { 125 | assert.strictEqual(stdout, pkg.version + '\n'); 126 | done(err); 127 | }); 128 | }); 129 | 130 | it('should not remove ./coverage when `--no-rm` flag is enabled.', function(done) { 131 | writeLcov(function(err) { 132 | assert.strictEqual(err, null); 133 | exec('node cli.js --no-rm', function(err) { 134 | assert.strictEqual(err, null); 135 | fs.stat('./coverage', function(err, stat) { 136 | assert.strictEqual(err, null); 137 | assert(stat.isDirectory()); 138 | done(); 139 | }); 140 | }); 141 | }); 142 | }); 143 | }); 144 | --------------------------------------------------------------------------------