Skip to content

Commit 8cb5e56

Browse files
authored
Set up lint and test (#1)
* Set up lint and test * Add travis setup * Add lint-staged * Remove babel * Format markdown files witg prettier * Run tests in node environment * Update lockfile * Remove more flow, and force strict mode * Support node 4
1 parent 8ba2da4 commit 8cb5e56

25 files changed

+3391
-323
lines changed

.eslintrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
module.exports = {
4+
extends: ['eslint:recommended', 'prettier'],
5+
plugins: ['prettier'],
6+
parserOptions: {
7+
ecmaVersion: 2017,
8+
},
9+
env: {
10+
node: true,
11+
},
12+
rules: {
13+
strict: 'error',
14+
'prettier/prettier': 'error',
15+
},
16+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.npmignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
**/__mocks__/**
21
**/__tests__/**
3-
src

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: node_js
2+
node_js:
3+
- node
4+
- 8
5+
- 6
6+
- 4
7+
cache:
8+
yarn: true
9+
branches:
10+
only:
11+
- master

README.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# eslint-plugin-jest
22

3+
[![Build Status](https://travis-ci.org/jest-community/eslint-plugin-jest.svg?branch=master)](https://travis-ci.org/jest-community/eslint-plugin-jest)
4+
35
Eslint plugin for Jest
46

57
## Installation
@@ -8,21 +10,20 @@ Eslint plugin for Jest
810
$ yarn add --dev eslint eslint-plugin-jest
911
```
1012

11-
**Note:** If you installed ESLint globally then you must also install `eslint-plugin-jest` globally.
13+
**Note:** If you installed ESLint globally then you must also install
14+
`eslint-plugin-jest` globally.
1215

1316
## Usage
1417

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

1721
```json
1822
{
19-
"plugins": [
20-
"jest"
21-
]
23+
"plugins": ["jest"]
2224
}
2325
```
2426

25-
2627
Then configure the rules you want to use under the rules section.
2728

2829
```json
@@ -48,33 +49,41 @@ You can also whitelist the environment variables provided by Jest by doing:
4849

4950
## Supported Rules
5051

51-
- [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) - disallow disabled tests.
52-
- [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) - disallow focused tests.
53-
- [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) - disallow identical titles.
54-
- [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) - ensure expect is called correctly.
52+
* [no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) -
53+
disallow disabled tests.
54+
* [no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) -
55+
disallow focused tests.
56+
* [no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) -
57+
disallow identical titles.
58+
* [valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md) -
59+
ensure expect is called correctly.
5560

5661
## Shareable configurations
5762

5863
### Recommended
5964

60-
This plugin exports a recommended configuration that enforces good testing practices.
65+
This plugin exports a recommended configuration that enforces good testing
66+
practices.
6167

62-
To enable this configuration use the `extends` property in your `.eslintrc` config file:
68+
To enable this configuration use the `extends` property in your `.eslintrc`
69+
config file:
6370

6471
```json
6572
{
6673
"extends": ["plugin:jest/recommended"]
6774
}
6875
```
6976

70-
See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending configuration files.
77+
See [ESLint
78+
documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files)
79+
for more information about extending configuration files.
7180

7281
The rules enabled in this configuration are:
7382

74-
- [jest/no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md)
75-
- [jest/no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md)
76-
- [jest/no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md)
77-
- [jest/valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md)
83+
* [jest/no-disabled-tests](/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md)
84+
* [jest/no-focused-tests](/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md)
85+
* [jest/no-identical-title](/packages/eslint-plugin-jest/docs/rules/no-identical-title.md)
86+
* [jest/valid-expect](/packages/eslint-plugin-jest/docs/rules/valid-expect.md)
7887

7988
## Credit
8089

docs/rules/no-disabled-tests.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This rule raises a warning about disabled tests.
1010
## Rule Details
1111

1212
There are a number of ways to disable tests in Jest:
13+
1314
* by appending `.skip` to the test-suite or test-case
1415
* by prepending the test function name with `x`
1516
* by declaring a test with a name but no function body
@@ -34,7 +35,7 @@ it('bar');
3435
test('bar');
3536

3637
it('foo', () => {
37-
pending()
38+
pending();
3839
});
3940
```
4041

docs/rules/no-focused-tests.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# Disallow Focused Tests (no-focused-tests)
22

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.
4-
This feature is really helpful to debug a failing test, so you don’t have to execute all of your tests.
5-
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.
3+
Jest has a feature that allows you to focus tests by appending `.only` or
4+
prepending `f` to a test-suite or a test-case. This feature is really helpful to
5+
debug a failing test, so you don’t have to execute all of your tests. After you
6+
have fixed your test and before committing the changes you have to remove
7+
`.only` to ensure all tests are executed on your build system.
68

7-
This rule reminds you to remove `.only` from your tests by raising a warning whenever you are using the exclusivity feature.
9+
This rule reminds you to remove `.only` from your tests by raising a warning
10+
whenever you are using the exclusivity feature.
811

912
## Rule Details
1013

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

1418
```js
1519
const describeOnly = describe.only;

docs/rules/no-identical-title.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# Disallow identical titles (no-identical-title)
22

3-
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.
3+
Having identical titles for two different tests or test suites may create
4+
confusion. For example, when a test with the same title as another test in the
5+
same test suite fails, it is harder to know which one failed and thus harder to
6+
fix.
47

58
## Rule Details
69

7-
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.
10+
This rule looks at the title of every test and test suites. It will report when
11+
two test suites or two test cases at the same level of a test suite have the
12+
same title.
813

914
The following patterns are considered warnings:
1015

@@ -17,7 +22,8 @@ describe('foo', () => {
1722
// ...
1823
});
1924

20-
describe('baz', () => { // Has the same title as a previous test suite
25+
describe('baz', () => {
26+
// Has the same title as a previous test suite
2127
// ...
2228
});
2329
});
@@ -37,7 +43,8 @@ describe('foo', () => {
3743
it('should work', () => {});
3844
});
3945

40-
describe('baz', () => { // Has the same title as a previous test suite
46+
describe('baz', () => {
47+
// Has the same title as a previous test suite
4148
// Has the same name as a test in a sibling test suite, which is fine
4249
it('should work', () => {});
4350
});

docs/rules/prefer-to-have-length.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Suggest using `toHaveLength()` (prefer-to-have-length)
1+
# Suggest using `toHaveLength()` (prefer-to-have-length)
22

3-
In order to have a better failure message, `toHaveLength()` should be used upon asserting expections on object's length property.
3+
In order to have a better failure message, `toHaveLength()` should be used upon
4+
asserting expections on object's length property.
45

56
## Rule details
67

7-
This rule triggers a warning if `toBe()` is used to assert object's length property.
8+
This rule triggers a warning if `toBe()` is used to assert object's length
9+
property.
810

911
```js
1012
expect(files.length).toBe(1);

docs/rules/valid-expect.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Enforce valid `expect()` usage (valid-expect)
22

3-
Ensure `expect()` is called with a single argument and there is an actual expectation made.
3+
Ensure `expect()` is called with a single argument and there is an actual
4+
expectation made.
45

56
## Rule details
67

7-
This rule triggers a warning if `expect()` is called with more than one argument or without arguments.
8-
It would also issue a warning if there is nothing called on `expect()`, e.g.:
8+
This rule triggers a warning if `expect()` is called with more than one argument
9+
or without arguments. It would also issue a warning if there is nothing called
10+
on `expect()`, e.g.:
911

1012
```js
1113
expect();

0 commit comments

Comments
 (0)