Skip to content

Commit

Permalink
fix: disable Jest addon for source files
Browse files Browse the repository at this point in the history
Fixes #31
  • Loading branch information
André Costa Lima committed Mar 14, 2018
1 parent b60054d commit 5145754
Show file tree
Hide file tree
Showing 13 changed files with 586 additions and 1 deletion.
23 changes: 23 additions & 0 deletions addons/jest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var jestPlugin = require('eslint-plugin-jest');

module.exports = {
'env': {
'jest/globals': true,
Expand All @@ -10,4 +12,25 @@ module.exports = {
'plugins': [
'jest',
],
'overrides': [{
'env': {
'jest/globals': false,
},
'files': [
'**/*.js',
],
'excludedFiles': [
'**/__tests__/**/*.js',
'**/?(*.)@(spec|test).js',
'test?(s)/**/*.js',
],
// Disable all rules provided by Jest plugin
'rules': Object.keys(jestPlugin.rules).reduce(function (rules, rule) {
var key = 'jest/' + rule;

rules[key] = 0;

return rules;
}, {}),
}],
};
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = {
// eslint-disable-next-line quote-props
testMatch: [
'**/test/index.spec.js',
],
};
282 changes: 281 additions & 1 deletion test/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ Array [
]
`;

exports[`should pass on fixtures/rules/jest/jest.js 1`] = `
exports[`should pass on fixtures/rules/jest/jest.spec.js 1`] = `
Array [
Object {
"column": 1,
Expand Down Expand Up @@ -1801,3 +1801,283 @@ Array [
`;

exports[`should pass on fixtures/samples/es8-babel-parser/contrived.good.js 1`] = `Array []`;

exports[`should pass on fixtures/samples/jest/__tests__/jest.js 1`] = `
Array [
Object {
"column": 1,
"line": 4,
"rule": "jest/no-disabled-tests",
"severity": 1,
},
Object {
"column": 4,
"line": 11,
"rule": "jest/no-focused-tests",
"severity": 2,
},
Object {
"column": 1,
"line": 19,
"rule": "jest/no-identical-title",
"severity": 2,
},
Object {
"column": 5,
"line": 28,
"rule": "jest/valid-expect",
"severity": 2,
},
]
`;

exports[`should pass on fixtures/samples/jest/jest.spec.js 1`] = `
Array [
Object {
"column": 1,
"line": 4,
"rule": "jest/no-disabled-tests",
"severity": 1,
},
Object {
"column": 4,
"line": 11,
"rule": "jest/no-focused-tests",
"severity": 2,
},
Object {
"column": 1,
"line": 19,
"rule": "jest/no-identical-title",
"severity": 2,
},
Object {
"column": 5,
"line": 28,
"rule": "jest/valid-expect",
"severity": 2,
},
]
`;

exports[`should pass on fixtures/samples/jest/jest.test.js 1`] = `
Array [
Object {
"column": 1,
"line": 4,
"rule": "jest/no-disabled-tests",
"severity": 1,
},
Object {
"column": 4,
"line": 11,
"rule": "jest/no-focused-tests",
"severity": 2,
},
Object {
"column": 1,
"line": 19,
"rule": "jest/no-identical-title",
"severity": 2,
},
Object {
"column": 5,
"line": 28,
"rule": "jest/valid-expect",
"severity": 2,
},
]
`;

exports[`should pass on fixtures/samples/jest/non-test-file.js 1`] = `
Array [
Object {
"column": 1,
"line": 4,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 1,
"line": 6,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 1,
"line": 11,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 1,
"line": 13,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 1,
"line": 18,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 1,
"line": 19,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 1,
"line": 21,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 1,
"line": 22,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 1,
"line": 27,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 5,
"line": 28,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 1,
"line": 31,
"rule": "no-undef",
"severity": 2,
},
Object {
"column": 5,
"line": 32,
"rule": "no-undef",
"severity": 2,
},
]
`;

exports[`should pass on fixtures/samples/jest/spec.js 1`] = `
Array [
Object {
"column": 1,
"line": 4,
"rule": "jest/no-disabled-tests",
"severity": 1,
},
Object {
"column": 4,
"line": 11,
"rule": "jest/no-focused-tests",
"severity": 2,
},
Object {
"column": 1,
"line": 19,
"rule": "jest/no-identical-title",
"severity": 2,
},
Object {
"column": 5,
"line": 28,
"rule": "jest/valid-expect",
"severity": 2,
},
]
`;

exports[`should pass on fixtures/samples/jest/test.js 1`] = `
Array [
Object {
"column": 1,
"line": 4,
"rule": "jest/no-disabled-tests",
"severity": 1,
},
Object {
"column": 4,
"line": 11,
"rule": "jest/no-focused-tests",
"severity": 2,
},
Object {
"column": 1,
"line": 19,
"rule": "jest/no-identical-title",
"severity": 2,
},
Object {
"column": 5,
"line": 28,
"rule": "jest/valid-expect",
"severity": 2,
},
]
`;

exports[`should pass on fixtures/samples/jest/test/jest.js 1`] = `
Array [
Object {
"column": 1,
"line": 4,
"rule": "jest/no-disabled-tests",
"severity": 1,
},
Object {
"column": 4,
"line": 11,
"rule": "jest/no-focused-tests",
"severity": 2,
},
Object {
"column": 1,
"line": 19,
"rule": "jest/no-identical-title",
"severity": 2,
},
Object {
"column": 5,
"line": 28,
"rule": "jest/valid-expect",
"severity": 2,
},
]
`;

exports[`should pass on fixtures/samples/jest/tests/jest.js 1`] = `
Array [
Object {
"column": 1,
"line": 4,
"rule": "jest/no-disabled-tests",
"severity": 1,
},
Object {
"column": 4,
"line": 11,
"rule": "jest/no-focused-tests",
"severity": 2,
},
Object {
"column": 1,
"line": 19,
"rule": "jest/no-identical-title",
"severity": 2,
},
Object {
"column": 5,
"line": 28,
"rule": "jest/valid-expect",
"severity": 2,
},
]
`;
File renamed without changes.
10 changes: 10 additions & 0 deletions test/fixtures/samples/jest/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"root": true,
"extends": [
"../../../../es6.js",
"../../../../addons/jest.js"
],
"rules": {
"strict": 0
}
}
33 changes: 33 additions & 0 deletions test/fixtures/samples/jest/__tests__/jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// `no-disabled-tests` - Disallow disabled tests
// ---------------------------------------------------------------------
// Bad
it.skip('no-disabled-tests bad', () => {});
// Good
it('no-disabled-tests good', () => {});

// `no-focused-tests` - Disallow focused tests
// ---------------------------------------------------------------------
// Bad
it.only('no-focused-tests bad', () => {});
// Good
it('no-focused-tests good', () => {});

// `no-identical-title` - Disallow identical titles
// ---------------------------------------------------------------------
// Bad
it('no-identical-title bad', () => {});
it('no-identical-title bad', () => {});
// Good
it('no-identical-title good', () => {});
it('no-identical-title good 2', () => {});

// `valid-expect` - Enforce valid expect() usage
// ---------------------------------------------------------------------
// Bad
it('valid-expect bad', () => {
expect('something');
});
// Good
it('valid-expect good', () => {
expect('something').not.toEqual('else');
});
Loading

0 comments on commit 5145754

Please sign in to comment.