Skip to content

Commit 2ae559a

Browse files
rubennortefacebook-github-bot
authored andcommitted
eslint: Disable jasmine env and only enable jest env for test files
Summary: Modified the ESLint configuration to only enable the Jest environment for files we consider now tests, which are files with the `-test.js` suffix under `__tests__`. Also enabled some globals for test helpers (any file under `__tests__`). This will allow us to catch misspelled tests, while allowing test helpers to use most Jest APIs. Also disabled the Jasmine environment so people stop using Jasmine APIs and we can rollout Circus soon. Reviewed By: aaronabramov Differential Revision: D13199591 fbshipit-source-id: 12a32cf5835630b9987452b0c33d3f8085001689
1 parent 18f3de9 commit 2ae559a

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

.eslintrc

+28-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
"env": {
77
"es6": true,
8-
"jest": true,
98
},
109

1110
"plugins": [
@@ -14,7 +13,7 @@
1413
"prettier",
1514
"react",
1615
"react-native",
17-
"jest"
16+
"jest",
1817
],
1918

2019
// Map from global var to bool specifying if it can be redefined
@@ -37,7 +36,6 @@
3736
"fetch": false,
3837
"FormData": false,
3938
"global": false,
40-
"jest": false,
4139
"Map": true,
4240
"module": false,
4341
"navigator": false,
@@ -52,8 +50,6 @@
5250
"setTimeout": false,
5351
"window": false,
5452
"XMLHttpRequest": false,
55-
"pit": false,
56-
"jasmine": true
5753
},
5854

5955
"rules": {
@@ -271,5 +267,32 @@
271267
"node": true,
272268
},
273269
},
270+
{
271+
"files": [
272+
"**/__fixtures__/**/*.js",
273+
"**/__mocks__/**/*.js",
274+
"**/__tests__/**/*.js",
275+
"jest/**/*.js",
276+
"RNTester/**/*.js",
277+
],
278+
"globals": {
279+
// Expose some Jest globals for test helpers
280+
"afterAll": true,
281+
"afterEach": true,
282+
"beforeAll": true,
283+
"beforeEach": true,
284+
"expect": true,
285+
"jest": true,
286+
},
287+
},
288+
{
289+
"files": [
290+
"**/__tests__/**/*-test.js",
291+
],
292+
"env": {
293+
"jasmine": true,
294+
"jest": true,
295+
},
296+
},
274297
],
275298
}

Libraries/Utilities/ReactNativeTestTools.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @format
99
*/
1010

11+
/* eslint-env jest */
12+
1113
'use strict';
1214

1315
const React = require('React');

RNTester/e2e/init.js RNTester/e2e/__tests__/init.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
/* eslint-env jasmine */
9+
810
const detox = require('detox');
9-
const config = require('../../package.json').detox;
11+
const config = require('../../../package.json').detox;
1012
const adapter = require('detox/runners/jest/adapter');
1113

1214
jest.setTimeout(480000);
File renamed without changes.

RNTester/e2e/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"setupTestFrameworkScriptFile" : "./init.js",
2+
"setupTestFrameworkScriptFile" : "./__tests__/init.js",
33
"testEnvironment": "node",
44
"bail": true,
55
"verbose": true

0 commit comments

Comments
 (0)