From e2867050be6740b55ad9b6c41d58e8dd2a02ce25 Mon Sep 17 00:00:00 2001 From: Alex Indigo Date: Tue, 1 Mar 2016 10:38:39 -0800 Subject: [PATCH 1/2] Housecleaning - Updated dependencies - Added linting - Added test coverage - Added CI - Made code more lintable --- .editorconfig | 14 ++++++++++++++ .eslintrc | 37 ++++++++++++++++++++++++++++++++++++ .gitignore | 3 ++- .npmignore | 2 ++ .travis.yml | 14 ++++++++++++++ appveyor.yml | 22 ++++++++++++++++++++++ index.js | 51 +++++++++++++++++++++++++------------------------- package.json | 21 +++++++++++++++------ test/.eslintrc | 11 +++++++++++ test/index.js | 33 ++++++++++++++++---------------- 10 files changed, 159 insertions(+), 49 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc create mode 100644 .travis.yml create mode 100644 appveyor.yml create mode 100644 test/.eslintrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6607810 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true + +[**.{css,hbs,js,json,md,scss}] +indent_style = space +indent_size = 2 +insert_final_newline = true diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..24057bd --- /dev/null +++ b/.eslintrc @@ -0,0 +1,37 @@ +{ + "env": { + "node": true + }, + "rules": { + "indent": [2, 2, {"SwitchCase": 1}], + "quotes": [2, "single"], + "linebreak-style": [2, "unix"], + "semi": [2, "always"], + "handle-callback-err": [2, "^err"], + "valid-jsdoc": [2, { + "requireReturn": false, + "requireReturnDescription": false, + "prefer": { + "return": "returns" + } + }], + "no-redeclare": [2, { "builtinGlobals": true }], + "no-shadow": [2, { "builtinGlobals": true, "hoist": "all" }], + "no-use-before-define": [2, "nofunc"], + "no-shadow-restricted-names": 2, + "no-extra-semi": 2, + "no-unused-vars": 2, + "no-undef": 2, + "no-console": 2, + "curly": 0, + "key-spacing": 0, + "strict": 0, + "dot-notation": 0, + "eol-last": 0, + "no-new": 0, + "semi-spacing": 0, + "no-multi-spaces": 0, + "eqeqeq": 0, + "no-mixed-requires": 0 + } +} diff --git a/.gitignore b/.gitignore index 12ac647..4bcdeba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +coverage/ node_modules/ -.DS_Store \ No newline at end of file +.DS_Store diff --git a/.npmignore b/.npmignore index 0facf3d..60dd495 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1,4 @@ +.gitignore +coverage/ test/ testdata/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..83ed0a2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: node_js +node_js: + - "0.10" + - "0.12" + - "iojs" + - "4.2" + - "stable" +script: + - node --version + - npm --version + - npm run lint + - npm run test +after_success: + - "cat coverage/lcov.info | ./node_modules/.bin/coveralls" diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..ab25246 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,22 @@ +init: + - git config --global core.autocrlf true +environment: + matrix: + - nodejs_version: '0.10' + - nodejs_version: '0.12' + - nodejs_version: '1.0' + - nodejs_version: '4.2' + - nodejs_version: '5' +platform: + - x86 + - x64 +install: + - ps: Install-Product node $env:nodejs_version $env:platform + - npm install +test_script: + - node --version + - npm --version + - npm run test +build: off +matrix: + fast_finish: true diff --git a/index.js b/index.js index db59a43..219f7a0 100644 --- a/index.js +++ b/index.js @@ -13,35 +13,36 @@ function shouldIgnoreFile(file, options) { } module.exports = function(options, extraOptions) { + var file; options = options || {}; - function transform(file) { - if (shouldIgnoreFile(file, options)) - return through(); - - var instrumenter = new (options.instrumenter || require('istanbul')).Instrumenter(options.instrumenterConfig || {}); - - var data = ''; - return through(function(buf) { - data += buf; - }, function() { - var self = this; - instrumenter.instrument(data, file, function(err, code) { - if (!err) { - self.queue(code); - } else { - self.emit('error', err); - } - self.queue(null); - }); - }); - } - if (typeof options === 'string') { - var file = options; + file = options; options = extraOptions || {}; - return transform(file); + return transform(options, file); } - return transform; + return transform.bind(null, options); }; + +function transform(options, file) { + if (shouldIgnoreFile(file, options)) + return through(); + + var instrumenter = new (options.instrumenter || require('istanbul')).Instrumenter(options.instrumenterConfig || {}); + + var data = ''; + return through(function(buf) { + data += buf; + }, function() { + var self = this; + instrumenter.instrument(data, file, function(err, code) { + if (!err) { + self.queue(code); + } else { + self.emit('error', err); + } + self.queue(null); + }); + }); +} diff --git a/package.json b/package.json index 8407199..66b26f6 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,19 @@ { "name": "browserify-istanbul", - "version": "1.0.0", + "version": "2.0.0", "description": "A browserify transform for the istanbul code coverage tool", "main": "index.js", "directories": { "test": "test" }, "scripts": { - "test": "mocha" + "lint": "eslint index.js test/*.js", + "test": "istanbul cover _mocha" }, + "pre-commit": [ + "lint", + "test" + ], "repository": { "type": "git", "url": "git://github.com/devongovett/browserify-istanbul.git" @@ -25,12 +30,16 @@ }, "homepage": "https://github.com/devongovett/browserify-istanbul", "dependencies": { - "minimatch": "^2.0.0", - "through": "^2.3.4" + "minimatch": "^3.0.0", + "through": "^2.3.8" }, "devDependencies": { + "browserify": "^13.0.0", + "coveralls": "^2.11.8", + "eslint": "^2.2.0", + "eslint-plugin-mocha": "^2.0.0", "istanbul": "^0.4.2", - "browserify": "^9.0.0", - "mocha": "^2.0.0" + "mocha": "^2.4.5", + "pre-commit": "^1.1.2" } } diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000..d127126 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,11 @@ +{ + "env": { + "mocha": true + }, + "plugins": [ + "mocha" + ], + "rules": { + "mocha/no-exclusive-tests": 2 + } +} diff --git a/test/index.js b/test/index.js index 4b73f38..8e042f3 100644 --- a/test/index.js +++ b/test/index.js @@ -10,10 +10,10 @@ describe('browserify-istanbul', function() { .bundle(function(err, src) { if (err) return done(err); - + var ctx = {}; vm.runInNewContext(src, ctx); - + assert.equal(typeof ctx.__coverage__, 'object'); assert.equal(typeof ctx.__coverage__[require.resolve(__dirname + '/../testdata/src/file.js')], 'object'); assert.equal(typeof ctx.__coverage__[require.resolve(__dirname + '/../testdata/src/ignored.js')], 'object'); @@ -21,17 +21,17 @@ describe('browserify-istanbul', function() { done(); }); }); - + it('should support ignore option in addition to default ignore option', function(done) { browserify(__dirname + '/../testdata/tests/file.js') .transform(istanbul({ ignore: ['**/ignored.js'] })) .bundle(function(err, src) { if (err) return done(err); - + var ctx = {}; vm.runInNewContext(src, ctx); - + assert.equal(typeof ctx.__coverage__, 'object'); assert.equal(typeof ctx.__coverage__[require.resolve(__dirname + '/../testdata/src/file.js')], 'object'); assert.equal(typeof ctx.__coverage__[require.resolve(__dirname + '/../testdata/src/ignored.js')], 'undefined'); @@ -39,17 +39,17 @@ describe('browserify-istanbul', function() { done(); }); }); - + it('should support disabling defaultIgnore', function(done) { browserify(__dirname + '/../testdata/tests/file.js') .transform(istanbul({ ignore: ['**/ignored.js'], defaultIgnore: false })) .bundle(function(err, src) { if (err) return done(err); - + var ctx = {}; vm.runInNewContext(src, ctx); - + assert.equal(typeof ctx.__coverage__, 'object'); assert.equal(typeof ctx.__coverage__[require.resolve(__dirname + '/../testdata/src/file.js')], 'object'); assert.equal(typeof ctx.__coverage__[require.resolve(__dirname + '/../testdata/src/ignored.js')], 'undefined'); @@ -57,15 +57,14 @@ describe('browserify-istanbul', function() { done(); }); }); - + it('should handle invalid .js', function(done) { - browserify(__dirname + '/../testdata/tests/invalid.js') - .transform(istanbul()) - .bundle(function(err, src) { - assert.equal(typeof err, 'object'); - assert.notEqual(err, null, 'Should emit error'); - - done(); - }); + browserify(__dirname + '/../testdata/tests/invalid.js') + .transform(istanbul()) + .bundle(function(err) { + assert.equal(typeof err, 'object'); + assert.notEqual(err, null, 'Should emit error'); + done(); + }); }); }); From ca38f1a47e0bfa13bb2337efe39327e20ca291fd Mon Sep 17 00:00:00 2001 From: Alex Indigo Date: Tue, 1 Mar 2016 10:59:27 -0800 Subject: [PATCH 2/2] What does mocha say to windows? Not today! --- appveyor.yml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index ab25246..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,22 +0,0 @@ -init: - - git config --global core.autocrlf true -environment: - matrix: - - nodejs_version: '0.10' - - nodejs_version: '0.12' - - nodejs_version: '1.0' - - nodejs_version: '4.2' - - nodejs_version: '5' -platform: - - x86 - - x64 -install: - - ps: Install-Product node $env:nodejs_version $env:platform - - npm install -test_script: - - node --version - - npm --version - - npm run test -build: off -matrix: - fast_finish: true