From dcdfff7ed3ebadede3ed5669e7a40b25b5742ed5 Mon Sep 17 00:00:00 2001 From: Adam Reeves Date: Sat, 12 Dec 2015 10:16:19 -0600 Subject: [PATCH] Update to ESLint next/2.0.0-rc-* dependency; Update `should` dependency; Update unit tests to reduce config loading and be more specific in error tests; --- package.json | 4 ++-- test/fail.js | 61 ++++++++++++++++++++++--------------------------- test/linting.js | 29 +++++++++++++++++++++-- test/result.js | 30 ++++++++---------------- test/util.js | 4 ++-- 5 files changed, 67 insertions(+), 61 deletions(-) diff --git a/package.json b/package.json index 49b4799..5af4931 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "license": "MIT", "dependencies": { "bufferstreams": "^1.1.0", - "eslint": "^1.4.0", + "eslint": "next", "gulp-util": "^3.0.6", "object-assign": "^4.0.1" }, @@ -53,7 +53,7 @@ "istanbul-coveralls": "^1.0.3", "jscs": "^2.0.0", "mocha": "^2.2.5", - "should": "^7.0.1", + "should": "^8.0.1", "vinyl": "^1.0.0" }, "jscsConfig": { diff --git a/test/fail.js b/test/fail.js index 9268fff..37c2041 100644 --- a/test/fail.js +++ b/test/fail.js @@ -9,28 +9,26 @@ require('mocha'); describe('gulp-eslint failOnError', function() { it('should fail a file immediately if an error is found', function(done) { - var lintStream = eslint({ - envs: ['browser'], - rules: { - 'no-undef': 2, - 'strict': 0 - } - }); + var lintStream = eslint({useEslintrc: false, rules: {'no-undef': 2}}); + + function endWithoutError() { + done(new Error('An error was not thrown before ending')); + } - lintStream.pipe(eslint.failOnError().on('error', function(err) { + lintStream.pipe(eslint.failOnError()) + .on('error', function(err) { + this.removeListener('finish', endWithoutError); should.exists(err); - err.message.should.equal('\"document\" is read only.'); + err.message.should.equal('"x" is not defined.'); err.fileName.should.equal('test/fixtures/invalid.js'); err.plugin.should.equal('gulp-eslint'); done(); - })) - .on('end', function() { - done(new Error('An error was not thrown before ending')); - }); + }) + .on('finish', endWithoutError); lintStream.write(new File({ path: 'test/fixtures/invalid.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 1;') })); lintStream.end(); @@ -38,7 +36,7 @@ describe('gulp-eslint failOnError', function() { it('should pass a file if only warnings are found', function(done) { - var lintStream = eslint({rules: {'no-undef': 1, 'strict': 0}}); + var lintStream = eslint({useEslintrc: false, rules: {'no-undef': 1, 'strict': 0}}); lintStream.pipe(eslint.failOnError()) .on('error', done) @@ -72,36 +70,31 @@ describe('gulp-eslint failOnError', function() { describe('gulp-eslint failAfterError', function() { it('should fail when the file stream ends if an error is found', function(done) { - var lintStream = eslint({ - envs: ['browser'], - rules: { - 'no-undef': 2, - 'strict': 0 - } - }); + var lintStream = eslint({useEslintrc: false, rules: {'no-undef': 2}}); - lintStream.pipe(eslint.failAfterError().on('error', function(err) { + function endWithoutError() { + done(new Error('An error was not thrown before ending')); + } + + lintStream.pipe(eslint.failAfterError()) + .on('error', function(err) { + this.removeListener('finish', endWithoutError); should.exists(err); err.message.should.equal('Failed with 1 error'); err.name.should.equal('ESLintError'); err.plugin.should.equal('gulp-eslint'); done(); - })); + }) + .on('finish', endWithoutError); lintStream.end(new File({ path: 'test/fixtures/invalid.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 1;') })); }); it('should fail when the file stream ends if multiple errors are found', function(done) { - var lintStream = eslint({ - envs: ['browser'], - rules: { - 'no-undef': 2, - 'strict': 0 - } - }); + var lintStream = eslint({useEslintrc: false, rules: {'no-undef': 2}}); lintStream.pipe(eslint.failAfterError().on('error', function(err) { should.exists(err); @@ -113,12 +106,12 @@ describe('gulp-eslint failAfterError', function() { lintStream.end(new File({ path: 'test/fixtures/invalid.js', - contents: new Buffer('document = "abuse read-only value"; a = false;') + contents: new Buffer('x = 1; a = false;') })); }); it('should pass when the file stream ends if only warnings are found', function(done) { - var lintStream = eslint({rules: {'no-undef': 1, 'strict': 0}}); + var lintStream = eslint({useEslintrc: false, rules: {'no-undef': 1, 'strict': 0}}); lintStream.pipe(eslint.failAfterError()) .on('error', done) diff --git a/test/linting.js b/test/linting.js index 3fff1b9..b4bb4fe 100644 --- a/test/linting.js +++ b/test/linting.js @@ -12,7 +12,7 @@ require('mocha'); describe('gulp-eslint plugin', function() { - it('should produce expected message via buffer', function(done) { + it('should configure an alternate parser', function(done) { eslint({ configFile: 'test/fixtures/.eslintrc-babel', globals: { @@ -20,6 +20,31 @@ describe('gulp-eslint plugin', function() { } }) .on('error', done) + .on('data', function(file) { + should.exist(file); + should.exist(file.contents); + should.exist(file.eslint); + file.eslint.should.have.property('filePath', 'test/fixtures/es6.js'); + + file.eslint.messages + .should.be.instanceof(Array) + .and.have.lengthOf(1); + + file.eslint.messages[0] + .should.have.properties('message', 'line', 'column') + .and.have.property('ruleId', 'strict'); + + done(); + }) + .end(new File({ + path: 'test/fixtures/es6.js', + contents: new Buffer('(() => {\n\t$.fn.foo = (a) => `${a}b`; }());') + })); + }); + + it('should produce expected message via buffer', function(done) { + eslint({useEslintrc: false, rules: {strict: [2, 'global']}}) + .on('error', done) .on('data', function(file) { should.exist(file); should.exist(file.contents); @@ -38,7 +63,7 @@ describe('gulp-eslint plugin', function() { }) .end(new File({ path: 'test/fixtures/use-strict.js', - contents: new Buffer('(() => {\n\t$.fn.foo = (a) => `${a}b`; }());') + contents: new Buffer('var x = 1;') })); }); diff --git a/test/result.js b/test/result.js index 7c5bae2..e9c6c0e 100644 --- a/test/result.js +++ b/test/result.js @@ -10,15 +10,9 @@ require('mocha'); describe('gulp-eslint result', function() { - it('should provide a ESLint result', function(done) { + it('should provide an ESLint result', function(done) { var resultCount = 0; - var lintStream = eslint({ - envs: ['browser'], - rules: { - 'no-undef': 2, - 'strict': [1, 'global'] - } - }); + var lintStream = eslint({useEslintrc: false, rules: {'no-undef': 2, 'strict': [1, 'global']}}); lintStream .pipe(eslint.result(function(result) { @@ -35,17 +29,17 @@ describe('gulp-eslint result', function() { lintStream.write(new File({ path: 'test/fixtures/invalid-1.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 1;') })); lintStream.write(new File({ path: 'test/fixtures/invalid-2.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 2;') })); lintStream.write(new File({ path: 'test/fixtures/invalid-3.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 3;') })); lintStream.end(); @@ -180,13 +174,7 @@ describe('gulp-eslint results', function() { it('should provide ESLint results', function(done) { var resultsCalled = false; - var lintStream = eslint({ - envs: ['browser'], - rules: { - 'no-undef': 2, - 'strict': [1, 'global'] - } - }); + var lintStream = eslint({useEslintrc: false, rules: {'no-undef': 2, 'strict': [1, 'global']}}); lintStream .pipe(eslint.results(function(results) { @@ -203,17 +191,17 @@ describe('gulp-eslint results', function() { lintStream.write(new File({ path: 'test/fixtures/invalid-1.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 1;') })); lintStream.write(new File({ path: 'test/fixtures/invalid-2.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 2;') })); lintStream.write(new File({ path: 'test/fixtures/invalid-3.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 3;') })); lintStream.end(); diff --git a/test/util.js b/test/util.js index f482ad2..bc182ce 100644 --- a/test/util.js +++ b/test/util.js @@ -19,7 +19,7 @@ describe('utility methods', function() { var passedFile = false, streamFile = new File({ path: 'test/fixtures/invalid.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 1;') }), testStream = util.transform(function(file, enc, cb) { should.exist(file); @@ -44,7 +44,7 @@ describe('utility methods', function() { files = [ new File({ path: 'test/fixtures/invalid.js', - contents: new Buffer('document = "abuse read-only value";') + contents: new Buffer('x = 1;') }), new File({ path: 'test/fixtures/undeclared.js',