Skip to content

Commit

Permalink
eslint: Disable jasmine env and only enable jest env for test files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rubennorte authored and facebook-github-bot committed Nov 27, 2018
1 parent 18f3de9 commit 2ae559a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
33 changes: 28 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

"env": {
"es6": true,
"jest": true,
},

"plugins": [
Expand All @@ -14,7 +13,7 @@
"prettier",
"react",
"react-native",
"jest"
"jest",
],

// Map from global var to bool specifying if it can be redefined
Expand All @@ -37,7 +36,6 @@
"fetch": false,
"FormData": false,
"global": false,
"jest": false,
"Map": true,
"module": false,
"navigator": false,
Expand All @@ -52,8 +50,6 @@
"setTimeout": false,
"window": false,
"XMLHttpRequest": false,
"pit": false,
"jasmine": true
},

"rules": {
Expand Down Expand Up @@ -271,5 +267,32 @@
"node": true,
},
},
{
"files": [
"**/__fixtures__/**/*.js",
"**/__mocks__/**/*.js",
"**/__tests__/**/*.js",
"jest/**/*.js",
"RNTester/**/*.js",
],
"globals": {
// Expose some Jest globals for test helpers
"afterAll": true,
"afterEach": true,
"beforeAll": true,
"beforeEach": true,
"expect": true,
"jest": true,
},
},
{
"files": [
"**/__tests__/**/*-test.js",
],
"env": {
"jasmine": true,
"jest": true,
},
},
],
}
2 changes: 2 additions & 0 deletions Libraries/Utilities/ReactNativeTestTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @format
*/

/* eslint-env jest */

'use strict';

const React = require('React');
Expand Down
4 changes: 3 additions & 1 deletion RNTester/e2e/init.js → RNTester/e2e/__tests__/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

/* eslint-env jasmine */

const detox = require('detox');
const config = require('../../package.json').detox;
const config = require('../../../package.json').detox;
const adapter = require('detox/runners/jest/adapter');

jest.setTimeout(480000);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion RNTester/e2e/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"setupTestFrameworkScriptFile" : "./init.js",
"setupTestFrameworkScriptFile" : "./__tests__/init.js",
"testEnvironment": "node",
"bail": true,
"verbose": true
Expand Down

0 comments on commit 2ae559a

Please sign in to comment.