Skip to content

Commit

Permalink
Merge branch 'master' of github.com:facebook/jest
Browse files Browse the repository at this point in the history
  • Loading branch information
hramos committed Jan 6, 2017
2 parents fefa6e5 + b135885 commit a6a256a
Show file tree
Hide file tree
Showing 31 changed files with 816 additions and 167 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[ignore]
.*/node_modules/config-chain/test/broken.json
.*/node_modules/react-native/.*
.*/node_modules/fbjs/.*
.*/vendor/jsonlint/.*
Expand Down
18 changes: 7 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ node_js:
- "6"
- "7"

sudo: required
sudo: false

cache:
yarn: true
directories:
- ".eslintcache"
- "node_modules"
- $HOME/.yarn-cache

before_install:
# Repo for Yarn
- sudo apt-key adv --keyserver pgp.mit.edu --recv D101F7899D41F3C3
- echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
- sudo apt-get update -qq
- sudo apt-get install -y -qq yarn
- yarn global add npm@latest
- npm install npm@latest

install: yarn

script: yarn run test-ci
script:
- (cd packages/eslint-plugin-jest && yarn link)
- yarn link eslint-plugin-jest
- yarn run test-ci
2 changes: 2 additions & 0 deletions examples/jquery/__tests__/displayUser-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2004-present Facebook. All Rights Reserved.

/* global document */

'use strict';

jest.mock('../fetchCurrentUser.js');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global document */

test('a failed assertion comparing a DOM node does not crash Jest', () => {
expect(document.body).toBe(null);
});
2 changes: 2 additions & 0 deletions integration_tests/jasmine_async/__tests__/promise_fit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

/* eslint-disable jest/no-focused-tests */

'use strict';

describe('promise fit', () => {
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/resolve/__tests__/resolve-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ function testRequire(filename) {
return () => platform = require(filename);
}

test('should resolve filename.<platform>.js', () => {
test('should explicitly resolve filename.<platform>.js', () => {
expect(testRequire('../test1.android.js')).not.toThrow();
expect(platform.extension).toBe('android.js');
});

test('should resolve filename.native.js', () => {
test('should explicitly resolve filename.native.js', () => {
expect(testRequire('../test1.native.js')).not.toThrow();
expect(platform.extension).toBe('native.js');
});

test('should resolve filename.js', () => {
test('should explicitly resolve filename.js', () => {
expect(testRequire('../test1.js')).not.toThrow();
expect(platform.extension).toBe('js');
});

test('should resolve filename.json', () => {
test('should explicitly resolve filename.json', () => {
expect(testRequire('../test1.json')).not.toThrow();
expect(platform.extension).toBe('json');
});
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lerna": "2.0.0-beta.31",
"lerna": "2.0.0-beta.32",
"version": "18.1.0",
"linkedFiles": {
"prefix": "/**\n * @flow\n */\n"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"jasmine-reporters": "^2.2.0",
"jsdom": "^9.9.1",
"left-pad": "^1.1.1",
"lerna": "2.0.0-beta.31",
"lerna": "2.0.0-beta.32",
"micromatch": "^2.3.11",
"mkdirp": "^0.5.1",
"progress": "^1.1.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"main": "build/index.js",
"dependencies": {
"babel-core": "^6.0.0",
"babel-plugin-istanbul": "^3.0.0",
"babel-plugin-istanbul": "^3.1.2",
"babel-preset-jest": "^18.0.0"
}
}
12 changes: 11 additions & 1 deletion packages/eslint-config-fb-strict/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ const importPattern = String.raw`^(?:var|let|const|import type)\s+` +
String.raw`\s*(?:=\s*require\(|from)[a-zA-Z_+./''\s\d\-]+\)?[^;\n]*[;\n]`;
const maxLenIgnorePattern = String.raw`(^\s*it\(|${importPattern})`;

delete fbjsConfig.rules['babel/flow-object-type'];

module.exports = Object.assign({}, fbjsConfig, {
'rules': Object.assign({}, fbjsConfig.rules, {
env: {
es6: true,
'jest/globals': true,
node: true,
},
plugins: fbjsConfig.plugins.concat(['jest']),
rules: Object.assign({}, fbjsConfig.rules, {
'array-bracket-spacing': [2, 'never'],
'arrow-parens': [2, 'as-needed'],
'arrow-spacing': [2],
Expand All @@ -31,6 +39,8 @@ module.exports = Object.assign({}, fbjsConfig, {
'computed-property-spacing': [2, 'never'],
'eol-last': [2],
'flowtype/object-type-delimiter': [2, 'comma'],
'jest/no-focused-tests': [2],
'jest/no-identical-title': [2],
'max-len': [2, {
'code': 80,
'ignorePattern': maxLenIgnorePattern,
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config-fb-strict/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"dependencies": {
"babel-eslint": "^7.0.0",
"eslint": "^3.3.0",
"eslint-config-fbjs": "^2.0.0-alpha.1",
"eslint-plugin-babel": "^4.0.0",
"eslint-config-fbjs": "^1.0.0"
"eslint-plugin-jest": "^18.1.0"
}
}
3 changes: 3 additions & 0 deletions packages/eslint-plugin-jest/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/__mocks__/**
**/__tests__/**
src
56 changes: 56 additions & 0 deletions packages/eslint-plugin-jest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# eslint-plugin-jest

Eslint plugin for Jest

## Installation

```
$ yarn add --dev eslint eslint-plugin-jest
```

**Note:** If you installed ESLint globally then you must also install `eslint-plugin-jest` globally.

## Usage

Add `jest` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

```json
{
"plugins": [
"jest"
]
}
```


Then configure the rules you want to use under the rules section.

```json
{
"rules": {
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error"
}
}
```

You can also whitelist the environment variables provided by Jest by doing:

```json
{
"env": {
"jest/globals": true
}
}
```

## Supported Rules

- [no-focused-tests](docs/rules/no-focused-tests.md) - disallow focused tests.
- [no-identical-title](docs/rules/no-identical-title.md) - disallow identical titles.


## Credit

* [eslint-plugin-mocha](https://github.com/lo1tuma/eslint-plugin-mocha)
* [eslint-plugin-jasmine](https://github.com/tlvince/eslint-plugin-jasmine)
42 changes: 42 additions & 0 deletions packages/eslint-plugin-jest/docs/rules/no-focused-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Disallow Focused Tests (no-focused-tests)

Jest has a feature that allows you to focus tests by appending `.only` or prepending `f` to a test-suite or a test-case.
This feature is really helpful to debug a failing test, so you don’t have to execute all of your tests.
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.

This rule reminds you to remove `.only` from your tests by raising a warning whenever you are using the exclusivity feature.

## Rule Details

This rule looks for every `describe.only`, `it.only`, `test.only`, `fdescribe`, `fit` and `ftest` occurrences within the source code.
Of course there are some edge-cases which can’t be detected by this rule e.g.:

```js
var describeOnly = describe.only;
describeOnly.apply(describe);
```

The following patterns are considered warnings:

```js
describe.only("foo", function () {});
it.only("foo", function () {});
describe["only"]("bar", function () {});
it["only"]("bar", function () {});
test.only("foo", function () {});
test["only"]("bar", function () {});
fdescribe("foo", function () {});
fit("foo", function () {});
ftest("bar", function () {});
```

These patterns would not be considered warnings:

```js
describe("foo", function () {});
it("foo", function () {});
describe.skip("bar", function () {});
it.skip("bar", function () {});
test("foo", function () {});
test.skip("bar", function () {});
```
45 changes: 45 additions & 0 deletions packages/eslint-plugin-jest/docs/rules/no-identical-title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Disallow identical titles (no-identical-title)

Having identical titles for two different tests or test suites may create confusion. For example, when a test with the same title as another test in the same test suite fails, it is harder to know which one failed and thus harder to fix.

## Rule Details

This rule looks at the title of every test and test suites. It will report when two test suites or two test cases at the same level of a test suite have the same title.

The following patterns are considered warnings:

```js
describe('foo', function () {
it('should do bar', function() {});
it('should do bar', function() {}); // Has the same title as the previous test

describe('baz', function() {
// ...
});

describe('baz', function() { // Has the same title as a previous test suite
// ...
});
});
```

These patterns would not be considered warnings:

```js
describe('foo', function () {
it('should do foo', function() {});
it('should do bar', function() {});

// Has the same name as a parent test suite, which is fine
describe('foo', function() {
// Has the same name as a test in a parent test suite, which is fine
it('should do foo', function() {});
it('should work', function() {});
});

describe('baz', function() { // Has the same title as a previous test suite
// Has the same name as a test in a sibling test suite, which is fine
it('should work', function() {});
});
});
```
24 changes: 24 additions & 0 deletions packages/eslint-plugin-jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "eslint-plugin-jest",
"version": "18.1.0",
"description": "Eslint rules for Jest",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin"
],
"author": {
"name": "Jonathan Kim",
"email": "[email protected]",
"url": "jkimbo.com"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git"
},
"main": "build/index.js",
"peerDependencies": {
"eslint": ">=3.6"
},
"license": "BSD-3-Clause"
}
40 changes: 40 additions & 0 deletions packages/eslint-plugin-jest/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/

'use strict';

module.exports = {
environments: {
globals: {
globals: {
afterAll: false,
afterEach: false,
beforeAll: false,
beforeEach: false,
describe: false,
expect: false,
fit: false,
it: false,
jasmine: false,
jest: false,
pit: false,
require: false,
test: false,
xdescribe: false,
xit: false,
xtest: false,
},
},
},
rules: {
'no-focused-tests': require('./rules/no-focused-tests'),
'no-identical-title': require('./rules/no-identical-title'),
},
};
Loading

0 comments on commit a6a256a

Please sign in to comment.