Skip to content

Commit 41781fe

Browse files
committed
Merge branch 'master' of git://github.com/facebook/jest into danger
2 parents a1405cc + e5d5a55 commit 41781fe

File tree

23 files changed

+103
-165
lines changed

23 files changed

+103
-165
lines changed

examples/jquery/__tests__/displayUser-test.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright 2004-present Facebook. All Rights Reserved.
22

3+
/* global document */
4+
35
'use strict';
46

57
jest.mock('../fetchCurrentUser.js');
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global document */
2+
13
test('a failed assertion comparing a DOM node does not crash Jest', () => {
24
expect(document.body).toBe(null);
35
});

integration_tests/jasmine_async/__tests__/promise_fit-test.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* of patent rights can be found in the PATENTS file in the same directory.
77
*/
88

9+
/* eslint-disable jest/no-focused-tests */
10+
911
'use strict';
1012

1113
describe('promise fit', () => {

integration_tests/resolve/__tests__/resolve-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ function testRequire(filename) {
1313
return () => platform = require(filename);
1414
}
1515

16-
test('should resolve filename.<platform>.js', () => {
16+
test('should explicitly resolve filename.<platform>.js', () => {
1717
expect(testRequire('../test1.android.js')).not.toThrow();
1818
expect(platform.extension).toBe('android.js');
1919
});
2020

21-
test('should resolve filename.native.js', () => {
21+
test('should explicitly resolve filename.native.js', () => {
2222
expect(testRequire('../test1.native.js')).not.toThrow();
2323
expect(platform.extension).toBe('native.js');
2424
});
2525

26-
test('should resolve filename.js', () => {
26+
test('should explicitly resolve filename.js', () => {
2727
expect(testRequire('../test1.js')).not.toThrow();
2828
expect(platform.extension).toBe('js');
2929
});
3030

31-
test('should resolve filename.json', () => {
31+
test('should explicitly resolve filename.json', () => {
3232
expect(testRequire('../test1.json')).not.toThrow();
3333
expect(platform.extension).toBe('json');
3434
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"eslint-plugin-babel": "^4.0.0",
1616
"eslint-plugin-flow-vars": "^0.5.0",
1717
"eslint-plugin-flowtype": "^2.28.2",
18+
"eslint-plugin-jest": "file:packages/eslint-plugin-jest",
1819
"eslint-plugin-react": "^6.7.1",
1920
"flow-bin": "^0.37.0",
2021
"glob": "^7.1.1",

packages/eslint-config-fb-strict/index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ const importPattern = String.raw`^(?:var|let|const|import type)\s+` +
1717
String.raw`\s*(?:=\s*require\(|from)[a-zA-Z_+./''\s\d\-]+\)?[^;\n]*[;\n]`;
1818
const maxLenIgnorePattern = String.raw`(^\s*it\(|${importPattern})`;
1919

20+
delete fbjsConfig.rules['babel/flow-object-type'];
21+
2022
module.exports = Object.assign({}, fbjsConfig, {
21-
'rules': Object.assign({}, fbjsConfig.rules, {
23+
env: {
24+
es6: true,
25+
'jest/globals': true,
26+
node: true,
27+
},
28+
plugins: fbjsConfig.plugins.concat(['jest']),
29+
rules: Object.assign({}, fbjsConfig.rules, {
2230
'array-bracket-spacing': [2, 'never'],
2331
'arrow-parens': [2, 'as-needed'],
2432
'arrow-spacing': [2],
@@ -31,6 +39,8 @@ module.exports = Object.assign({}, fbjsConfig, {
3139
'computed-property-spacing': [2, 'never'],
3240
'eol-last': [2],
3341
'flowtype/object-type-delimiter': [2, 'comma'],
42+
'jest/no-focused-tests': [2],
43+
'jest/no-identical-title': [2],
3444
'max-len': [2, {
3545
'code': 80,
3646
'ignorePattern': maxLenIgnorePattern,

packages/eslint-config-fb-strict/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"dependencies": {
1010
"babel-eslint": "^7.0.0",
1111
"eslint": "^3.3.0",
12+
"eslint-config-fbjs": "^2.0.0-alpha.1",
1213
"eslint-plugin-babel": "^4.0.0",
13-
"eslint-config-fbjs": "^1.0.0"
14+
"eslint-plugin-jest": "^18.1.0"
1415
}
1516
}

packages/eslint-plugin-jest/README.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,25 @@ Then configure the rules you want to use under the rules section.
2828
```json
2929
{
3030
"rules": {
31-
"jest/no-exclusive-tests": "error",
31+
"jest/no-focused-tests": "error",
3232
"jest/no-identical-title": "error"
3333
}
3434
}
3535
```
3636

37+
You can also whitelist the environment variables provided by Jest by doing:
38+
39+
```json
40+
{
41+
"env": {
42+
"jest/globals": true
43+
}
44+
}
45+
```
46+
3747
## Supported Rules
3848

39-
- [no-exclusive-tests](docs/rules/no-exclusive-tests.md) - disallow exclusive tests.
49+
- [no-focused-tests](docs/rules/no-focused-tests.md) - disallow focused tests.
4050
- [no-identical-title](docs/rules/no-identical-title.md) - disallow identical titles.
4151

4252

packages/eslint-plugin-jest/docs/rules/no-exclusive-tests.md renamed to packages/eslint-plugin-jest/docs/rules/no-focused-tests.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Disallow Exclusive Tests (no-exclusive-tests)
1+
# Disallow Focused Tests (no-focused-tests)
22

3-
Jest has a feature that allows you to run tests exclusively by appending `.only` or prepending `f` to a test-suite or a test-case.
3+
Jest has a feature that allows you to focus tests by appending `.only` or prepending `f` to a test-suite or a test-case.
44
This feature is really helpful to debug a failing test, so you don’t have to execute all of your tests.
55
After you have fixed your test and before committing the changes you have to remove `.only` to ensure all tests are executed on your build system.
66

packages/eslint-plugin-jest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-jest",
3-
"version": "18.0.0",
3+
"version": "18.1.0",
44
"description": "Eslint rules for Jest",
55
"keywords": [
66
"eslint",

packages/eslint-plugin-jest/src/index.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,33 @@
88
* @flow
99
*/
1010

11-
/* eslint-disable global-require */
12-
1311
'use strict';
1412

15-
module.exports.rules = {
16-
'no-exclusive-tests': require('./rules/no-exclusive-tests'),
17-
'no-identical-title': require('./rules/no-identical-title'),
13+
module.exports = {
14+
environments: {
15+
globals: {
16+
globals: {
17+
afterAll: false,
18+
afterEach: false,
19+
beforeAll: false,
20+
beforeEach: false,
21+
describe: false,
22+
expect: false,
23+
fit: false,
24+
it: false,
25+
jasmine: false,
26+
jest: false,
27+
pit: false,
28+
require: false,
29+
test: false,
30+
xdescribe: false,
31+
xit: false,
32+
xtest: false,
33+
},
34+
},
35+
},
36+
rules: {
37+
'no-focused-tests': require('./rules/no-focused-tests'),
38+
'no-identical-title': require('./rules/no-identical-title'),
39+
},
1840
};

packages/eslint-plugin-jest/src/rules/__tests__/no-exclusive-tests-test.js renamed to packages/eslint-plugin-jest/src/rules/__tests__/no-focused-tests-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const RuleTester = require('eslint').RuleTester;
1616
const rules = require('../../').rules;
1717

1818
const ruleTester = new RuleTester();
19-
const expectedErrorMessage = 'Unexpected exclusive test.';
19+
const expectedErrorMessage = 'Unexpected focused test.';
2020

21-
ruleTester.run('no-exclusive-tests', rules['no-exclusive-tests'], {
21+
ruleTester.run('no-focused-tests', rules['no-focused-tests'], {
2222
valid: [
2323
'describe()',
2424
'it()',

packages/eslint-plugin-jest/src/rules/__tests__/no-identical-title-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @flow
99
*/
1010

11-
/* eslint-disable no-template-curly-in-string, sort-keys, max-len */
11+
/* eslint-disable sort-keys, max-len */
1212

1313
'use strict';
1414

packages/eslint-plugin-jest/src/rules/no-exclusive-tests.js renamed to packages/eslint-plugin-jest/src/rules/no-focused-tests.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ module.exports = function(context: EslintContext) {
2222
return object && jestTestFunctions.indexOf(object.name) !== -1;
2323
}
2424

25-
function matchesExclusiveTestFunction(object) {
25+
function matchesFocusedTestFunction(object) {
2626
return (
2727
object &&
28-
object.name.charAt(0) === 'f' &&
28+
object.name[0] === 'f' &&
2929
jestTestFunctions.indexOf(object.name.substring(1)) !== -1
3030
);
3131
}
@@ -40,8 +40,8 @@ module.exports = function(context: EslintContext) {
4040
);
4141
}
4242

43-
function isCallToExclusiveJestFunction(callee) {
44-
return matchesExclusiveTestFunction(callee);
43+
function isCallToFocusedJestFunction(callee) {
44+
return matchesFocusedTestFunction(callee);
4545
}
4646

4747
return {
@@ -56,18 +56,18 @@ module.exports = function(context: EslintContext) {
5656
isCallToJestOnlyFunction(callee)
5757
) {
5858
context.report({
59-
message: 'Unexpected exclusive test.',
59+
message: 'Unexpected focused test.',
6060
node: callee.property,
6161
});
6262
return;
6363
}
6464

6565
if (
6666
callee.type === 'Identifier' &&
67-
isCallToExclusiveJestFunction(callee)
67+
isCallToFocusedJestFunction(callee)
6868
) {
6969
context.report({
70-
message: 'Unexpected exclusive test.',
70+
message: 'Unexpected focused test.',
7171
node: callee,
7272
});
7373
return;

packages/eslint-plugin-jest/src/rules/no-identical-title.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
import type {EslintContext, CallExpression} from './types';
1313

1414
const describeAliases = [
15-
'describe',
16-
'xdescribe',
1715
'describe.only',
1816
'describe.skip',
17+
'describe',
1918
'fdescribe',
19+
'xdescribe',
2020
];
2121

2222
const testCaseNames = [
23-
'it',
23+
'fit',
2424
'it.only',
2525
'it.skip',
26-
'fit',
27-
'test',
26+
'it',
2827
'test.only',
2928
'test.skip',
30-
'ftest',
29+
'test',
30+
'xit',
31+
'xtest',
3132
];
3233

3334
function getNodeName(node) {

packages/eslint-plugin-jest/src/rules/types.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,33 @@
77
*
88
* @flow
99
*/
10-
export type Identifier = {
10+
11+
export type Identifier = {|
1112
type: 'Identifier',
1213
name: string,
1314
value: string,
14-
}
15+
|};
1516

16-
export type MemberExpression = {
17+
export type MemberExpression = {|
1718
type: 'MemberExpression',
1819
name: string,
1920
expression: CallExpression,
2021
property: Identifier,
2122
object: Identifier,
22-
}
23+
|};
2324

24-
export type Literal = {
25+
export type Literal = {|
2526
type: 'Literal',
2627
value?: string,
2728
rawValue?: string,
28-
}
29+
|};
2930

30-
export type CallExpression = {
31+
export type CallExpression = {|
3132
type: 'CallExpression',
3233
arguments: [Literal],
3334
callee: Identifier | MemberExpression,
34-
}
35+
|};
3536

36-
export type EslintContext = {
37-
report: ({ message: string, node: any }) => void
38-
}
37+
export type EslintContext = {|
38+
report: ({message: string, node: any}) => void
39+
|};

0 commit comments

Comments
 (0)