Skip to content

Commit

Permalink
Update to ESLint next/2.0.0-rc-* dependency;
Browse files Browse the repository at this point in the history
Update `should` dependency;
Update unit tests to reduce config loading and be more specific in error tests;
  • Loading branch information
adametry committed Dec 12, 2015
1 parent 7f190a6 commit dcdfff7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 61 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -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"
},
Expand All @@ -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": {
Expand Down
61 changes: 27 additions & 34 deletions test/fail.js
Expand Up @@ -9,36 +9,34 @@ 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();
});

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)
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
29 changes: 27 additions & 2 deletions test/linting.js
Expand Up @@ -12,14 +12,39 @@ 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: {
'$': true
}
})
.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);
Expand All @@ -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;')
}));
});

Expand Down
30 changes: 9 additions & 21 deletions test/result.js
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/util.js
Expand Up @@ -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);
Expand All @@ -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',
Expand Down

0 comments on commit dcdfff7

Please sign in to comment.