eslint-plugin-jest 23.20.0 → 24.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,64 @@
1
+ # [24.1.0](https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.2...v24.1.0) (2020-10-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * **prefer-expect-assertions:** add `onlyFunctionsWithAsyncKeyword` option ([#677](https://github.com/jest-community/eslint-plugin-jest/issues/677)) ([d0cea37](https://github.com/jest-community/eslint-plugin-jest/commit/d0cea37ae0a8ab07b8082cedbaaf161bcc94c405))
7
+
8
+ ## [24.0.2](https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.1...v24.0.2) (2020-09-20)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **no-if:** check both types of function expression ([#672](https://github.com/jest-community/eslint-plugin-jest/issues/672)) ([d462d50](https://github.com/jest-community/eslint-plugin-jest/commit/d462d50aed84ad4dc536a1f47bb7af6abd3dbe92)), closes [#670](https://github.com/jest-community/eslint-plugin-jest/issues/670)
14
+
15
+ ## [24.0.1](https://github.com/jest-community/eslint-plugin-jest/compare/v24.0.0...v24.0.1) (2020-09-12)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * don't include deprecated rules in `all` config ([#664](https://github.com/jest-community/eslint-plugin-jest/issues/664)) ([f636021](https://github.com/jest-community/eslint-plugin-jest/commit/f636021c16215a713845c699858a2978211df49d)), closes [#663](https://github.com/jest-community/eslint-plugin-jest/issues/663)
21
+
22
+ # [24.0.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.20.0...v24.0.0) (2020-09-04)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **no-large-snapshots:** run on all files regardless of type ([#637](https://github.com/jest-community/eslint-plugin-jest/issues/637)) ([22113db](https://github.com/jest-community/eslint-plugin-jest/commit/22113db4cdc2dab42a8e7fdb236d23e7e089741d)), closes [#370](https://github.com/jest-community/eslint-plugin-jest/issues/370)
28
+ * remove Jasmine globals ([#596](https://github.com/jest-community/eslint-plugin-jest/issues/596)) ([a0e2bc5](https://github.com/jest-community/eslint-plugin-jest/commit/a0e2bc526c5c22bcf4d60160242b55d03edb571d))
29
+ * update to typescript-eslint@4 ([1755965](https://github.com/jest-community/eslint-plugin-jest/commit/175596582b3643f36363ff444f987fac08ee0f61)), closes [#590](https://github.com/jest-community/eslint-plugin-jest/issues/590)
30
+
31
+
32
+ ### Code Refactoring
33
+
34
+ * **no-test-callback:** rename rule to `no-done-callback` ([#653](https://github.com/jest-community/eslint-plugin-jest/issues/653)) ([e15a8d1](https://github.com/jest-community/eslint-plugin-jest/commit/e15a8d19234b267784f87fc7acd318dc4cfcdeae))
35
+
36
+
37
+ ### Features
38
+
39
+ * **no-done-callback:** support hooks ([#656](https://github.com/jest-community/eslint-plugin-jest/issues/656)) ([3e6cb44](https://github.com/jest-community/eslint-plugin-jest/commit/3e6cb442a20b9aea710d30f81bf2eb192d193823)), closes [#649](https://github.com/jest-community/eslint-plugin-jest/issues/649) [#651](https://github.com/jest-community/eslint-plugin-jest/issues/651)
40
+ * add `no-conditional-expect` to the recommended ruleset ([40cd89d](https://github.com/jest-community/eslint-plugin-jest/commit/40cd89ddf1d6ebbde8ad455f333dda7b61878ffe))
41
+ * add `no-deprecated-functions` to the recommended ruleset ([5b2af00](https://github.com/jest-community/eslint-plugin-jest/commit/5b2af001b50059e4e7b6ababe0355d664e039046))
42
+ * add `no-interpolation-in-snapshots` to the recommended ruleset ([3705dff](https://github.com/jest-community/eslint-plugin-jest/commit/3705dff9d4f77d21013e263478d8a374d9325acb))
43
+ * add `valid-title` to recommended ruleset ([41f7873](https://github.com/jest-community/eslint-plugin-jest/commit/41f7873f734e0122264ace42f6d99733e7e25089))
44
+ * drop support for node 8 ([#570](https://github.com/jest-community/eslint-plugin-jest/issues/570)) ([6788e72](https://github.com/jest-community/eslint-plugin-jest/commit/6788e72d842751400a970e72b115360ad0b12d2e))
45
+ * set `no-jasmine-globals` to `error` in recommended ruleset ([7080952](https://github.com/jest-community/eslint-plugin-jest/commit/7080952a6baaae7a02c78f60016ee21693121416))
46
+ * **no-large-snapshots:** remove `whitelistedSnapshots` option ([8c1c0c9](https://github.com/jest-community/eslint-plugin-jest/commit/8c1c0c9a3e858757b38225ccb4a624e0621b5ca2))
47
+
48
+
49
+ ### BREAKING CHANGES
50
+
51
+ * **no-done-callback:** `no-done-callback` will now report hooks using callbacks as well, not just tests
52
+ * **no-test-callback:** rename `no-test-callback` to `no-done-callback`
53
+ * recommend `no-conditional-expect` rule
54
+ * recommend `no-interpolation-in-snapshots` rule
55
+ * recommend `no-deprecated-functions` rule
56
+ * recommend `valid-title` rule
57
+ * recommend erroring for `no-jasmine-globals` rule
58
+ * **no-large-snapshots:** `no-large-snapshots` runs on all files regardless of type
59
+ * Jasmine globals are no marked as such
60
+ * Node 10+ required
61
+
1
62
  # [23.20.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.19.0...v23.20.0) (2020-07-30)
2
63
 
3
64
 
package/README.md CHANGED
@@ -57,6 +57,9 @@ doing:
57
57
  }
58
58
  ```
59
59
 
60
+ This is included in all configs shared by this plugin, so can be omitted if
61
+ extending them.
62
+
60
63
  The behaviour of some rules (specifically `no-deprecated-functions`) change
61
64
  depending on the version of `jest` being used.
62
65
 
@@ -135,23 +138,23 @@ installations requiring long-term consistency.
135
138
  | [lowercase-name](docs/rules/lowercase-name.md) | Enforce lowercase test names | | ![fixable][] |
136
139
  | [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ![style][] | ![fixable][] |
137
140
  | [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | ![recommended][] | |
138
- | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Prevent calling `expect` conditionally | | |
139
- | [no-deprecated-functions](docs/rules/no-deprecated-functions.md) | Disallow use of deprecated functions | | ![fixable][] |
141
+ | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Prevent calling `expect` conditionally | ![recommended][] | |
142
+ | [no-deprecated-functions](docs/rules/no-deprecated-functions.md) | Disallow use of deprecated functions | ![recommended][] | ![fixable][] |
140
143
  | [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | ![recommended][] | |
144
+ | [no-done-callback](docs/rules/no-done-callback.md) | Avoid using a callback in asynchronous tests and hooks | ![recommended][] | ![suggest][] |
141
145
  | [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | Disallow duplicate setup and teardown hooks | | |
142
146
  | [no-export](docs/rules/no-export.md) | Disallow using `exports` in files containing tests | ![recommended][] | |
143
147
  | [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended][] | ![fixable][] |
144
148
  | [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | |
145
149
  | [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended][] | |
146
150
  | [no-if](docs/rules/no-if.md) | Disallow conditional logic | | |
147
- | [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | | |
151
+ | [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | ![recommended][] | |
148
152
  | [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals | ![recommended][] | ![fixable][] |
149
153
  | [no-jest-import](docs/rules/no-jest-import.md) | Disallow importing Jest | ![recommended][] | |
150
154
  | [no-large-snapshots](docs/rules/no-large-snapshots.md) | disallow large snapshots | | |
151
155
  | [no-mocks-import](docs/rules/no-mocks-import.md) | Disallow manually importing from `__mocks__` | ![recommended][] | |
152
156
  | [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers | | |
153
157
  | [no-standalone-expect](docs/rules/no-standalone-expect.md) | Disallow using `expect` outside of `it` or `test` blocks | ![recommended][] | |
154
- | [no-test-callback](docs/rules/no-test-callback.md) | Avoid using a callback in asynchronous tests | ![recommended][] | ![suggest][] |
155
158
  | [no-test-prefixes](docs/rules/no-test-prefixes.md) | Use `.only` and `.skip` over `f` and `x` | ![recommended][] | ![fixable][] |
156
159
  | [no-test-return-statement](docs/rules/no-test-return-statement.md) | Disallow explicitly returning from tests | | |
157
160
  | [prefer-called-with](docs/rules/prefer-called-with.md) | Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` | | |
@@ -169,7 +172,7 @@ installations requiring long-term consistency.
169
172
  | [valid-describe](docs/rules/valid-describe.md) | Enforce valid `describe()` callback | ![recommended][] | |
170
173
  | [valid-expect](docs/rules/valid-expect.md) | Enforce valid `expect()` usage | ![recommended][] | |
171
174
  | [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Enforce having return statement when testing with promises | ![recommended][] | |
172
- | [valid-title](docs/rules/valid-title.md) | Enforce valid titles | | ![fixable][] |
175
+ | [valid-title](docs/rules/valid-title.md) | Enforce valid titles | ![recommended][] | ![fixable][] |
173
176
 
174
177
  <!-- end rules list -->
175
178
 
@@ -59,12 +59,12 @@ test.only('foo'); // invalid
59
59
  /*eslint jest/consistent-test-it: ["error", {"fn": "it", "withinDescribe": "test"}]*/
60
60
 
61
61
  it('foo'); // valid
62
- describe('foo', function() {
62
+ describe('foo', function () {
63
63
  test('bar'); // valid
64
64
  });
65
65
 
66
66
  test('foo'); // invalid
67
- describe('foo', function() {
67
+ describe('foo', function () {
68
68
  it('bar'); // invalid
69
69
  });
70
70
  ```
@@ -78,12 +78,12 @@ nested within `describe` to use `it`.
78
78
  /*eslint jest/consistent-test-it: ["error"]*/
79
79
 
80
80
  test('foo'); // valid
81
- describe('foo', function() {
81
+ describe('foo', function () {
82
82
  it('bar'); // valid
83
83
  });
84
84
 
85
85
  it('foo'); // invalid
86
- describe('foo', function() {
86
+ describe('foo', function () {
87
87
  test('bar'); // invalid
88
88
  });
89
89
  ```
@@ -56,9 +56,7 @@ import { expectSaga } from 'redux-saga-test-plan';
56
56
  import { addSaga } from '../src/sagas';
57
57
 
58
58
  test('returns sum', () => {
59
- expectSaga(addSaga, 1, 1)
60
- .returns(2)
61
- .run();
59
+ expectSaga(addSaga, 1, 1).returns(2).run();
62
60
  });
63
61
  ```
64
62
 
@@ -72,9 +70,7 @@ import { expectSaga } from 'redux-saga-test-plan';
72
70
  import { addSaga } from '../src/sagas';
73
71
 
74
72
  test('returns sum', () => {
75
- expectSaga(addSaga, 1, 1)
76
- .returns(2)
77
- .run();
73
+ expectSaga(addSaga, 1, 1).returns(2).run();
78
74
  });
79
75
  ```
80
76
 
@@ -100,12 +96,9 @@ const express = require('express');
100
96
 
101
97
  const app = express();
102
98
 
103
- describe('GET /user', function() {
104
- it('responds with json', function(done) {
105
- request(app)
106
- .get('/user')
107
- .expect('Content-Type', /json/)
108
- .expect(200, done);
99
+ describe('GET /user', function () {
100
+ it('responds with json', function (done) {
101
+ request(app).get('/user').expect('Content-Type', /json/).expect(200, done);
109
102
  });
110
103
  });
111
104
  ```
@@ -0,0 +1,90 @@
1
+ # Avoid using a callback in asynchronous tests and hooks (`no-done-callback`)
2
+
3
+ When calling asynchronous code in hooks and tests, `jest` needs to know when the
4
+ asynchronous work is complete to progress the current run.
5
+
6
+ Originally the most common pattern to archive this was to use callbacks:
7
+
8
+ ```js
9
+ test('the data is peanut butter', done => {
10
+ function callback(data) {
11
+ try {
12
+ expect(data).toBe('peanut butter');
13
+ done();
14
+ } catch (error) {
15
+ done(error);
16
+ }
17
+ }
18
+
19
+ fetchData(callback);
20
+ });
21
+ ```
22
+
23
+ This can be very error prone however, as it requires careful understanding of
24
+ how assertions work in tests or otherwise tests won't behave as expected.
25
+
26
+ For example, if the `try/catch` was left out of the above code, the test would
27
+ timeout rather than fail. Even with the `try/catch`, forgetting to pass the
28
+ caught error to `done` will result in `jest` believing the test has passed.
29
+
30
+ A more straightforward way to handle asynchronous code is to use Promises:
31
+
32
+ ```js
33
+ test('the data is peanut butter', () => {
34
+ return fetchData().then(data => {
35
+ expect(data).toBe('peanut butter');
36
+ });
37
+ });
38
+ ```
39
+
40
+ When a test or hook returns a promise, `jest` waits for that promise to resolve,
41
+ as well as automatically failing should the promise reject.
42
+
43
+ If your environment supports `async/await`, this becomes even simpler:
44
+
45
+ ```js
46
+ test('the data is peanut butter', async () => {
47
+ const data = await fetchData();
48
+ expect(data).toBe('peanut butter');
49
+ });
50
+ ```
51
+
52
+ ## Rule details
53
+
54
+ This rule checks the function parameter of hooks & tests for use of the `done`
55
+ argument, suggesting you return a promise instead.
56
+
57
+ The following patterns are considered warnings:
58
+
59
+ ```js
60
+ beforeEach(done => {
61
+ // ...
62
+ });
63
+
64
+ test('myFunction()', done => {
65
+ // ...
66
+ });
67
+
68
+ test('myFunction()', function (done) {
69
+ // ...
70
+ });
71
+ ```
72
+
73
+ The following patterns are not considered warnings:
74
+
75
+ ```js
76
+ beforeEach(async () => {
77
+ await setupUsTheBomb();
78
+ });
79
+
80
+ test('myFunction()', () => {
81
+ expect(myFunction()).toBeTruthy();
82
+ });
83
+
84
+ test('myFunction()', () => {
85
+ return new Promise(done => {
86
+ expect(myFunction()).toBeTruthy();
87
+ done();
88
+ });
89
+ });
90
+ ```
@@ -15,7 +15,7 @@ Examples of **incorrect** code for this rule:
15
15
  ```js
16
16
  export function myHelper() {}
17
17
 
18
- module.exports = function() {};
18
+ module.exports = function () {};
19
19
 
20
20
  module.exports = {
21
21
  something: 'that should be moved to a non-test file',
@@ -15,7 +15,7 @@ body.
15
15
 
16
16
  // valid:
17
17
 
18
- it('noop', function() {});
18
+ it('noop', function () {});
19
19
 
20
20
  test('noop', () => {});
21
21
 
@@ -27,7 +27,7 @@ test('one', () => {
27
27
  expect(1).toBe(1);
28
28
  });
29
29
 
30
- it('one', function() {
30
+ it('one', function () {
31
31
  expect(1).toBe(1);
32
32
  });
33
33
 
@@ -41,7 +41,7 @@ test('return an expect', () => {
41
41
  return expect(1).toBe(1);
42
42
  });
43
43
 
44
- it('returning a promise', function() {
44
+ it('returning a promise', function () {
45
45
  return new Promise(res => setTimeout(res, 100)).then(() => expect(1).toBe(1));
46
46
  });
47
47
  ```
@@ -55,3 +55,45 @@ test('my test', () => {
55
55
  expect(someThing()).toEqual('foo');
56
56
  });
57
57
  ```
58
+
59
+ ## Options
60
+
61
+ #### `onlyFunctionsWithAsyncKeyword`
62
+
63
+ When `true`, this rule will only warn for tests that use the `async` keyword.
64
+
65
+ ```json
66
+ {
67
+ "rules": {
68
+ "jest/prefer-expect-assertions": [
69
+ "warn",
70
+ { "onlyFunctionsWithAsyncKeyword": true }
71
+ ]
72
+ }
73
+ }
74
+ ```
75
+
76
+ When `onlyFunctionsWithAsyncKeyword` option is set to `true`, the following
77
+ pattern would be a warning:
78
+
79
+ ```js
80
+ test('my test', async () => {
81
+ const result = await someAsyncFunc();
82
+ expect(result).toBe('foo');
83
+ });
84
+ ```
85
+
86
+ While the following patterns would not be considered warnings:
87
+
88
+ ```js
89
+ test('my test', () => {
90
+ const result = someFunction();
91
+ expect(result).toBe('foo');
92
+ });
93
+
94
+ test('my test', async () => {
95
+ expect.assertions(1);
96
+ const result = await someAsyncFunc();
97
+ expect(result).toBe('foo');
98
+ });
99
+ ```
@@ -55,7 +55,7 @@ it(123, () => {});
55
55
  describe(String(/.+/), () => {});
56
56
  describe(myFunction, () => {});
57
57
  xdescribe(myFunction, () => {});
58
- describe(6, function() {});
58
+ describe(6, function () {});
59
59
  ```
60
60
 
61
61
  Examples of **correct** code for this rule:
@@ -82,7 +82,7 @@ fdescribe('is a string', () => {});
82
82
  describe(String(/.+/), () => {});
83
83
  describe(myFunction, () => {});
84
84
  xdescribe(myFunction, () => {});
85
- describe(6, function() {});
85
+ describe(6, function () {});
86
86
  ```
87
87
 
88
88
  **duplicatePrefix**
package/lib/globals.json CHANGED
@@ -5,14 +5,9 @@
5
5
  "beforeEach": false,
6
6
  "describe": false,
7
7
  "expect": false,
8
- "fail": false,
9
8
  "fit": false,
10
9
  "it": false,
11
- "jasmine": false,
12
10
  "jest": false,
13
- "pending": false,
14
- "pit": false,
15
- "require": false,
16
11
  "test": false,
17
12
  "xdescribe": false,
18
13
  "xit": false,
package/lib/index.js CHANGED
@@ -14,12 +14,6 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
14
14
 
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
 
17
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
18
-
19
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
20
-
21
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
-
23
17
  // copied from https://github.com/babel/babel/blob/d8da63c929f2d28c401571e2a43166678c555bc4/packages/babel-helpers/src/helpers.js#L602-L606
24
18
 
25
19
  /* istanbul ignore next */
@@ -32,14 +26,14 @@ interopRequireDefault(require(moduleName)).default;
32
26
 
33
27
  const rulesDir = (0, _path.join)(__dirname, 'rules');
34
28
  const excludedFiles = ['__tests__', 'utils'];
35
- const rules = (0, _fs.readdirSync)(rulesDir).map(rule => (0, _path.parse)(rule).name).filter(rule => !excludedFiles.includes(rule)).reduce((acc, curr) => _objectSpread(_objectSpread({}, acc), {}, {
29
+ const rules = (0, _fs.readdirSync)(rulesDir).map(rule => (0, _path.parse)(rule).name).filter(rule => !excludedFiles.includes(rule)).reduce((acc, curr) => ({ ...acc,
36
30
  [curr]: importDefault((0, _path.join)(rulesDir, curr))
37
31
  }), {});
38
- const recommendedRules = Object.entries(rules).filter(([, rule]) => rule.meta.docs.recommended).reduce((acc, [name, rule]) => _objectSpread(_objectSpread({}, acc), {}, {
32
+ const recommendedRules = Object.entries(rules).filter(([, rule]) => rule.meta.docs.recommended).reduce((acc, [name, rule]) => ({ ...acc,
39
33
  [`jest/${name}`]: rule.meta.docs.recommended
40
34
  }), {});
41
- const allRules = Object.keys(rules).reduce((rules, key) => _objectSpread(_objectSpread({}, rules), {}, {
42
- [`jest/${key}`]: 'error'
35
+ const allRules = Object.entries(rules).filter(([, rule]) => !rule.meta.deprecated).reduce((acc, [name]) => ({ ...acc,
36
+ [`jest/${name}`]: 'error'
43
37
  }), {});
44
38
 
45
39
  const createConfig = rules => ({
@@ -13,7 +13,7 @@ var _default = (0, _utils.createRule)({
13
13
  docs: {
14
14
  description: 'Prevent calling `expect` conditionally',
15
15
  category: 'Best Practices',
16
- recommended: false
16
+ recommended: 'error'
17
17
  },
18
18
  messages: {
19
19
  conditionalExpect: 'Avoid calling `expect` conditionally`'
@@ -9,12 +9,6 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
9
9
 
10
10
  var _utils = require("./utils");
11
11
 
12
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
13
-
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
15
-
16
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
-
18
12
  let cachedJestVersion = null;
19
13
  /** @internal */
20
14
 
@@ -39,7 +33,7 @@ const detectJestVersion = () => {
39
33
  const [majorVersion] = jestPackageJson.version.split('.');
40
34
  return cachedJestVersion = parseInt(majorVersion, 10);
41
35
  }
42
- } catch (_unused) {}
36
+ } catch {}
43
37
 
44
38
  throw new Error('Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly');
45
39
  };
@@ -50,7 +44,7 @@ var _default = (0, _utils.createRule)({
50
44
  docs: {
51
45
  category: 'Best Practices',
52
46
  description: 'Disallow use of deprecated functions',
53
- recommended: false
47
+ recommended: 'error'
54
48
  },
55
49
  messages: {
56
50
  deprecatedFunction: '`{{ deprecation }}` has been deprecated in favor of `{{ replacement }}`'
@@ -62,23 +56,26 @@ var _default = (0, _utils.createRule)({
62
56
  defaultOptions: [],
63
57
 
64
58
  create(context) {
65
- var _ref, _ref$jest;
66
-
67
- const jestVersion = ((_ref = context.settings) === null || _ref === void 0 ? void 0 : (_ref$jest = _ref.jest) === null || _ref$jest === void 0 ? void 0 : _ref$jest.version) || detectJestVersion();
68
-
69
- const deprecations = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, jestVersion >= 15 && {
70
- 'jest.resetModuleRegistry': 'jest.resetModules'
71
- }), jestVersion >= 17 && {
72
- 'jest.addMatchers': 'expect.extend'
73
- }), jestVersion >= 21 && {
74
- 'require.requireMock': 'jest.requireMock',
75
- 'require.requireActual': 'jest.requireActual'
76
- }), jestVersion >= 22 && {
77
- 'jest.runTimersToTime': 'jest.advanceTimersByTime'
78
- }), jestVersion >= 26 && {
79
- 'jest.genMockFromModule': 'jest.createMockFromModule'
80
- });
81
-
59
+ var _context$settings, _context$settings$jes;
60
+
61
+ const jestVersion = ((_context$settings = context.settings) === null || _context$settings === void 0 ? void 0 : (_context$settings$jes = _context$settings.jest) === null || _context$settings$jes === void 0 ? void 0 : _context$settings$jes.version) || detectJestVersion();
62
+ const deprecations = { ...(jestVersion >= 15 && {
63
+ 'jest.resetModuleRegistry': 'jest.resetModules'
64
+ }),
65
+ ...(jestVersion >= 17 && {
66
+ 'jest.addMatchers': 'expect.extend'
67
+ }),
68
+ ...(jestVersion >= 21 && {
69
+ 'require.requireMock': 'jest.requireMock',
70
+ 'require.requireActual': 'jest.requireActual'
71
+ }),
72
+ ...(jestVersion >= 22 && {
73
+ 'jest.runTimersToTime': 'jest.advanceTimersByTime'
74
+ }),
75
+ ...(jestVersion >= 26 && {
76
+ 'jest.genMockFromModule': 'jest.createMockFromModule'
77
+ })
78
+ };
82
79
  return {
83
80
  CallExpression(node) {
84
81
  if (node.callee.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression) {
@@ -104,7 +101,6 @@ var _default = (0, _utils.createRule)({
104
101
  node,
105
102
 
106
103
  fix(fixer) {
107
- // eslint-disable-next-line prefer-const
108
104
  let [name, func] = replacement.split('.');
109
105
 
110
106
  if (callee.property.type === _experimentalUtils.AST_NODE_TYPES.Literal) {
@@ -9,17 +9,29 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
9
9
 
10
10
  var _utils = require("./utils");
11
11
 
12
+ const findCallbackArg = node => {
13
+ if ((0, _utils.isHook)(node) && node.arguments.length >= 1) {
14
+ return node.arguments[0];
15
+ }
16
+
17
+ if ((0, _utils.isTestCase)(node) && node.arguments.length >= 2) {
18
+ return node.arguments[1];
19
+ }
20
+
21
+ return null;
22
+ };
23
+
12
24
  var _default = (0, _utils.createRule)({
13
25
  name: __filename,
14
26
  meta: {
15
27
  docs: {
16
28
  category: 'Best Practices',
17
- description: 'Avoid using a callback in asynchronous tests',
29
+ description: 'Avoid using a callback in asynchronous tests and hooks',
18
30
  recommended: 'error',
19
31
  suggestion: true
20
32
  },
21
33
  messages: {
22
- illegalTestCallback: 'Illegal usage of test callback',
34
+ noDoneCallback: 'Return a Promise instead of relying on callback parameter',
23
35
  suggestWrappingInPromise: 'Wrap in `new Promise({{ callback }} => ...`',
24
36
  useAwaitInsteadOfCallback: 'Use await instead of callback in async functions'
25
37
  },
@@ -31,13 +43,9 @@ var _default = (0, _utils.createRule)({
31
43
  create(context) {
32
44
  return {
33
45
  CallExpression(node) {
34
- if (!(0, _utils.isTestCase)(node) || node.arguments.length !== 2) {
35
- return;
36
- }
37
-
38
- const [, callback] = node.arguments;
46
+ const callback = findCallbackArg(node);
39
47
 
40
- if (!(0, _utils.isFunction)(callback) || callback.params.length !== 1) {
48
+ if (!callback || !(0, _utils.isFunction)(callback) || callback.params.length !== 1) {
41
49
  return;
42
50
  }
43
51
 
@@ -46,7 +54,7 @@ var _default = (0, _utils.createRule)({
46
54
  if (argument.type !== _experimentalUtils.AST_NODE_TYPES.Identifier) {
47
55
  context.report({
48
56
  node: argument,
49
- messageId: 'illegalTestCallback'
57
+ messageId: 'noDoneCallback'
50
58
  });
51
59
  return;
52
60
  }
@@ -61,7 +69,7 @@ var _default = (0, _utils.createRule)({
61
69
 
62
70
  context.report({
63
71
  node: argument,
64
- messageId: 'illegalTestCallback',
72
+ messageId: 'noDoneCallback',
65
73
  suggest: [{
66
74
  messageId: 'suggestWrappingInPromise',
67
75
  data: {
@@ -72,12 +80,6 @@ var _default = (0, _utils.createRule)({
72
80
  const {
73
81
  body
74
82
  } = callback;
75
- /* istanbul ignore if https://github.com/typescript-eslint/typescript-eslint/issues/734 */
76
-
77
- if (!body) {
78
- throw new Error(`Unexpected null when attempting to fix ${context.getFilename()} - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`);
79
- }
80
-
81
83
  const sourceCode = context.getSourceCode();
82
84
  const firstBodyToken = sourceCode.getFirstToken(body);
83
85
  const lastBodyToken = sourceCode.getLastToken(body);
@@ -14,7 +14,7 @@ const testFunctions = new Set([_utils.DescribeAlias.describe, ...validTestCaseNa
14
14
 
15
15
  const isConcurrentExpression = expression => (0, _utils.isSupportedAccessor)(expression.property, _utils.TestCaseProperty.concurrent) && !!expression.parent && expression.parent.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression;
16
16
 
17
- const matchesTestFunction = object => 'name' in object && (object.name in _utils.TestCaseName || object.name in _utils.DescribeAlias);
17
+ const matchesTestFunction = object => 'name' in object && typeof object.name === 'string' && (object.name in _utils.TestCaseName || object.name in _utils.DescribeAlias);
18
18
 
19
19
  const isCallToFocusedTestFunction = object => object.name.startsWith('f') && testFunctions.has(object.name.substring(1));
20
20
 
@@ -11,7 +11,7 @@ var _utils = require("./utils");
11
11
 
12
12
  const testCaseNames = new Set([...Object.keys(_utils.TestCaseName), 'it.only', 'it.concurrent.only', 'it.skip', 'it.concurrent.skip', 'test.only', 'test.concurrent.only', 'test.skip', 'test.concurrent.skip', 'fit.concurrent']);
13
13
 
14
- const isTestArrowFunction = node => node.parent !== undefined && node.parent.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && testCaseNames.has((0, _utils.getNodeName)(node.parent.callee));
14
+ const isTestFunctionExpression = node => node.parent !== undefined && node.parent.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && testCaseNames.has((0, _utils.getNodeName)(node.parent.callee));
15
15
 
16
16
  const conditionName = {
17
17
  [_experimentalUtils.AST_NODE_TYPES.ConditionalExpression]: 'conditional',
@@ -61,8 +61,8 @@ var _default = (0, _utils.createRule)({
61
61
  }
62
62
  },
63
63
 
64
- FunctionExpression() {
65
- stack.push(false);
64
+ FunctionExpression(node) {
65
+ stack.push(isTestFunctionExpression(node));
66
66
  },
67
67
 
68
68
  FunctionDeclaration(node) {
@@ -72,7 +72,7 @@ var _default = (0, _utils.createRule)({
72
72
  },
73
73
 
74
74
  ArrowFunctionExpression(node) {
75
- stack.push(isTestArrowFunction(node));
75
+ stack.push(isTestFunctionExpression(node));
76
76
  },
77
77
 
78
78
  IfStatement: validate,
@@ -15,7 +15,7 @@ var _default = (0, _utils.createRule)({
15
15
  docs: {
16
16
  category: 'Best Practices',
17
17
  description: 'Disallow string interpolation inside snapshots',
18
- recommended: false
18
+ recommended: 'error'
19
19
  },
20
20
  messages: {
21
21
  noInterpolation: 'Do not use string interpolation inside of snapshots'
@@ -15,7 +15,7 @@ var _default = (0, _utils.createRule)({
15
15
  docs: {
16
16
  category: 'Best Practices',
17
17
  description: 'Disallow Jasmine globals',
18
- recommended: 'warn'
18
+ recommended: 'error'
19
19
  },
20
20
  messages: {
21
21
  illegalGlobal: 'Illegal usage of global `{{ global }}`, prefer `{{ replacement }}`',
@@ -11,16 +11,9 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
11
11
 
12
12
  var _utils = require("./utils");
13
13
 
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
15
-
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
-
18
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
-
20
14
  const reportOnViolation = (context, node, {
21
15
  maxSize: lineLimit = 50,
22
- whitelistedSnapshots = {},
23
- allowedSnapshots = whitelistedSnapshots
16
+ allowedSnapshots = {}
24
17
  }) => {
25
18
  const startLine = node.loc.start.line;
26
19
  const endLine = node.loc.end.line;
@@ -88,14 +81,6 @@ var _default = (0, _utils.createRule)({
88
81
  additionalProperties: {
89
82
  type: 'array'
90
83
  }
91
- },
92
- whitelistedSnapshots: {
93
- type: 'object',
94
- patternProperties: {
95
- '.*': {
96
- type: 'array'
97
- }
98
- }
99
84
  }
100
85
  },
101
86
  additionalProperties: false
@@ -104,10 +89,6 @@ var _default = (0, _utils.createRule)({
104
89
  defaultOptions: [{}],
105
90
 
106
91
  create(context, [options]) {
107
- if ('whitelistedSnapshots' in options) {
108
- console.warn('jest/no-large-snapshots: the "whitelistedSnapshots" option has been renamed to "allowedSnapshots"');
109
- }
110
-
111
92
  if (context.getFilename().endsWith('.snap')) {
112
93
  return {
113
94
  ExpressionStatement(node) {
@@ -115,22 +96,34 @@ var _default = (0, _utils.createRule)({
115
96
  }
116
97
 
117
98
  };
118
- } else if (context.getFilename().endsWith('.js')) {
119
- return {
120
- CallExpression(node) {
121
- if ('property' in node.callee && ((0, _utils.isSupportedAccessor)(node.callee.property, 'toMatchInlineSnapshot') || (0, _utils.isSupportedAccessor)(node.callee.property, 'toThrowErrorMatchingInlineSnapshot'))) {
122
- var _options$inlineMaxSiz;
99
+ }
123
100
 
124
- reportOnViolation(context, node, _objectSpread(_objectSpread({}, options), {}, {
125
- maxSize: (_options$inlineMaxSiz = options.inlineMaxSize) !== null && _options$inlineMaxSiz !== void 0 ? _options$inlineMaxSiz : options.maxSize
126
- }));
127
- }
101
+ return {
102
+ CallExpression(node) {
103
+ var _matcher$node$parent;
104
+
105
+ if (!(0, _utils.isExpectCall)(node)) {
106
+ return;
128
107
  }
129
108
 
130
- };
131
- }
109
+ const {
110
+ matcher
111
+ } = (0, _utils.parseExpectCall)(node);
112
+
113
+ if ((matcher === null || matcher === void 0 ? void 0 : (_matcher$node$parent = matcher.node.parent) === null || _matcher$node$parent === void 0 ? void 0 : _matcher$node$parent.type) !== _experimentalUtils.AST_NODE_TYPES.CallExpression) {
114
+ return;
115
+ }
116
+
117
+ if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes(matcher.name)) {
118
+ var _options$inlineMaxSiz;
119
+
120
+ reportOnViolation(context, matcher.node.parent, { ...options,
121
+ maxSize: (_options$inlineMaxSiz = options.inlineMaxSize) !== null && _options$inlineMaxSiz !== void 0 ? _options$inlineMaxSiz : options.maxSize
122
+ });
123
+ }
124
+ }
132
125
 
133
- return {};
126
+ };
134
127
  }
135
128
 
136
129
  });
@@ -12,7 +12,7 @@ var _utils = require("./utils");
12
12
  const getBody = args => {
13
13
  const [, secondArg] = args;
14
14
 
15
- if (secondArg && (0, _utils.isFunction)(secondArg) && secondArg.body && secondArg.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
15
+ if (secondArg && (0, _utils.isFunction)(secondArg) && secondArg.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
16
16
  return secondArg.body.body;
17
17
  }
18
18
 
@@ -39,13 +39,27 @@ var _default = (0, _utils.createRule)({
39
39
  suggestRemovingExtraArguments: 'Remove extra arguments'
40
40
  },
41
41
  type: 'suggestion',
42
- schema: []
42
+ schema: [{
43
+ type: 'object',
44
+ properties: {
45
+ onlyFunctionsWithAsyncKeyword: {
46
+ type: 'boolean'
47
+ }
48
+ },
49
+ additionalProperties: false
50
+ }]
43
51
  },
44
- defaultOptions: [],
52
+ defaultOptions: [{
53
+ onlyFunctionsWithAsyncKeyword: false
54
+ }],
45
55
 
46
- create(context) {
56
+ create(context, [options]) {
47
57
  return {
48
58
  'CallExpression[callee.name=/^(it|test)$/][arguments.1.body.body]'(node) {
59
+ if (options.onlyFunctionsWithAsyncKeyword && !node.arguments[1].async) {
60
+ return;
61
+ }
62
+
49
63
  const testFuncBody = node.arguments[1].body.body;
50
64
 
51
65
  if (!isFirstLineExprStmt(testFuncBody)) {
@@ -40,7 +40,7 @@ var _default = (0, _utils.createRule)({
40
40
  matcher
41
41
  } = (0, _utils.parseExpectCall)(node);
42
42
 
43
- if (!matcher || !(0, _utils.isParsedEqualityMatcherCall)(matcher) || !argument || argument.type !== _experimentalUtils.AST_NODE_TYPES.MemberExpression || !(0, _utils.isSupportedAccessor)(argument.property, 'length') || argument.property.type !== _experimentalUtils.AST_NODE_TYPES.Identifier) {
43
+ if (!matcher || !(0, _utils.isParsedEqualityMatcherCall)(matcher) || (argument === null || argument === void 0 ? void 0 : argument.type) !== _experimentalUtils.AST_NODE_TYPES.MemberExpression || !(0, _utils.isSupportedAccessor)(argument.property, 'length') || argument.property.type !== _experimentalUtils.AST_NODE_TYPES.Identifier) {
44
44
  return;
45
45
  }
46
46
 
@@ -13,14 +13,8 @@ function isEmptyFunction(node) {
13
13
  if (!(0, _utils.isFunction)(node)) {
14
14
  return false;
15
15
  }
16
- /* istanbul ignore if https://github.com/typescript-eslint/typescript-eslint/issues/734 */
17
16
 
18
-
19
- if (!node.body) {
20
- throw new Error(`Unexpected null while performing prefer-todo - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`);
21
- }
22
-
23
- return node.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement && node.body.body && !node.body.body.length;
17
+ return node.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement && !node.body.body.length;
24
18
  }
25
19
 
26
20
  function createTodoFixer(node, fixer) {
@@ -26,6 +26,8 @@ var _default = (0, _utils.createRule)({
26
26
  create(context) {
27
27
  return {
28
28
  CallExpression(node) {
29
+ var _matcher$arguments;
30
+
29
31
  if (!(0, _utils.isExpectCall)(node)) {
30
32
  return;
31
33
  }
@@ -35,7 +37,7 @@ var _default = (0, _utils.createRule)({
35
37
  modifier
36
38
  } = (0, _utils.parseExpectCall)(node);
37
39
 
38
- if (matcher && matcher.arguments && matcher.arguments.length === 0 && ['toThrow', 'toThrowError'].includes(matcher.name) && (!modifier || !(modifier.name === _utils.ModifierName.not || modifier.negation))) {
40
+ if ((matcher === null || matcher === void 0 ? void 0 : (_matcher$arguments = matcher.arguments) === null || _matcher$arguments === void 0 ? void 0 : _matcher$arguments.length) === 0 && ['toThrow', 'toThrowError'].includes(matcher.name) && (!modifier || !(modifier.name === _utils.ModifierName.not || modifier.negation))) {
39
41
  // Look for `toThrow` calls with no arguments.
40
42
  context.report({
41
43
  messageId: 'addErrorMessage',
@@ -12,12 +12,6 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils");
12
12
 
13
13
  var _package = require("../../package.json");
14
14
 
15
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
16
-
17
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
18
-
19
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
-
21
15
  const REPO_URL = 'https://github.com/jest-community/eslint-plugin-jest';
22
16
 
23
17
  const createRule = _experimentalUtils.ESLintUtils.RuleCreator(name => {
@@ -231,7 +225,8 @@ const parseExpectMember = expectMember => ({
231
225
  node: expectMember
232
226
  });
233
227
 
234
- const reparseAsMatcher = parsedMember => _objectSpread(_objectSpread({}, parsedMember), {}, {
228
+ const reparseAsMatcher = parsedMember => ({ ...parsedMember,
229
+
235
230
  /**
236
231
  * The arguments being passed to this `Matcher`, if any.
237
232
  *
@@ -265,9 +260,9 @@ const reparseMemberAsModifier = parsedMember => {
265
260
  }
266
261
 
267
262
  const negation = parsedMember.node.parent && isExpectMember(parsedMember.node.parent, ModifierName.not) ? parsedMember.node.parent : undefined;
268
- return _objectSpread(_objectSpread({}, parsedMember), {}, {
263
+ return { ...parsedMember,
269
264
  negation
270
- });
265
+ };
271
266
  };
272
267
 
273
268
  const isSpecificMember = (member, specific) => member.name === specific;
@@ -86,7 +86,7 @@ var _default = (0, _utils.createRule)({
86
86
  });
87
87
  }
88
88
 
89
- if (callback.body && callback.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
89
+ if (callback.body.type === _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
90
90
  callback.body.body.forEach(node => {
91
91
  if (node.type === _experimentalUtils.AST_NODE_TYPES.ReturnStatement) {
92
92
  context.report({
@@ -76,8 +76,8 @@ const isParentThenOrPromiseReturned = (node, testFunctionBody) => node.type ===
76
76
 
77
77
  const verifyExpectWithReturn = (promiseCallbacks, node, context, testFunctionBody) => {
78
78
  promiseCallbacks.some(promiseCallback => {
79
- if (promiseCallback && (0, _utils.isFunction)(promiseCallback) && promiseCallback.body) {
80
- if (isExpectCallPresentInFunction(promiseCallback.body) && node.parent && node.parent.parent && !isParentThenOrPromiseReturned(node.parent.parent, testFunctionBody)) {
79
+ if (promiseCallback && (0, _utils.isFunction)(promiseCallback)) {
80
+ if (isExpectCallPresentInFunction(promiseCallback.body) && node.parent.parent && !isParentThenOrPromiseReturned(node.parent.parent, testFunctionBody)) {
81
81
  reportReturnRequired(context, node.parent.parent);
82
82
  return true;
83
83
  }
@@ -118,11 +118,6 @@ var _default = (0, _utils.createRule)({
118
118
  const {
119
119
  body
120
120
  } = testFunction;
121
- /* istanbul ignore if https://github.com/typescript-eslint/typescript-eslint/issues/734 */
122
-
123
- if (!body) {
124
- throw new Error(`Unexpected null when attempting to fix ${context.getFilename()} - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`);
125
- }
126
121
 
127
122
  if (body.type !== _experimentalUtils.AST_NODE_TYPES.BlockStatement) {
128
123
  return;
@@ -190,7 +190,7 @@ var _default = (0, _utils.createRule)({
190
190
  return;
191
191
  }
192
192
 
193
- if (matcher.node.parent && (0, _utils.isExpectMember)(matcher.node.parent)) {
193
+ if ((0, _utils.isExpectMember)(matcher.node.parent)) {
194
194
  context.report({
195
195
  messageId: 'modifierUnknown',
196
196
  data: {
@@ -210,7 +210,7 @@ var _default = (0, _utils.createRule)({
210
210
 
211
211
  const parentNode = matcher.node.parent;
212
212
 
213
- if (!modifier || !parentNode || !parentNode.parent || modifier.name === _utils.ModifierName.not) {
213
+ if (!parentNode.parent || !modifier || modifier.name === _utils.ModifierName.not) {
214
214
  return;
215
215
  }
216
216
  /**
@@ -48,7 +48,7 @@ var _default = (0, _utils.createRule)({
48
48
  docs: {
49
49
  category: 'Best Practices',
50
50
  description: 'Enforce valid titles',
51
- recommended: false
51
+ recommended: 'error'
52
52
  },
53
53
  messages: {
54
54
  titleMustBeString: 'Title must be a string',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "23.20.0",
3
+ "version": "24.1.0",
4
4
  "description": "Eslint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",
@@ -20,11 +20,11 @@
20
20
  "lib/"
21
21
  ],
22
22
  "scripts": {
23
- "build": "babel --extensions .js,.ts src --out-dir lib --copy-files",
24
- "postbuild": "rimraf lib/__tests__ lib/**/__tests__",
23
+ "build": "babel --extensions .js,.ts src --out-dir lib --copy-files && rimraf lib/__tests__ 'lib/**/__tests__'",
25
24
  "lint": "eslint . --ignore-pattern '!.eslintrc.js' --ext js,ts",
26
- "prepack": "yarn build",
27
- "prettylint": "prettylint docs/**/*.md README.md package.json",
25
+ "prepack": "rimraf lib && yarn build",
26
+ "prettier:check": "prettier --check 'docs/**/*.md' README.md '.github/**' package.json tsconfig.json src/globals.json .yarnrc.yml",
27
+ "prettier:write": "prettier --write 'docs/**/*.md' README.md '.github/**' package.json tsconfig.json src/globals.json .yarnrc.yml",
28
28
  "test": "jest",
29
29
  "tools:regenerate-docs": "ts-node -T tools/regenerate-docs",
30
30
  "typecheck": "tsc -p ."
@@ -41,14 +41,8 @@
41
41
  ]
42
42
  },
43
43
  "lint-staged": {
44
- "*.{js,ts}": [
45
- "eslint --fix",
46
- "git add"
47
- ],
48
- "*.{md,json}": [
49
- "prettier --write",
50
- "git add"
51
- ]
44
+ "*.{js,ts}": "eslint --fix",
45
+ "*.{md,json,yml}": "prettier --write"
52
46
  },
53
47
  "prettier": {
54
48
  "arrowParens": "avoid",
@@ -87,28 +81,28 @@
87
81
  ]
88
82
  },
89
83
  "dependencies": {
90
- "@typescript-eslint/experimental-utils": "^2.5.0"
84
+ "@typescript-eslint/experimental-utils": "^4.0.1"
91
85
  },
92
86
  "devDependencies": {
93
87
  "@babel/cli": "^7.4.4",
94
88
  "@babel/core": "^7.4.4",
95
89
  "@babel/preset-env": "^7.4.4",
96
90
  "@babel/preset-typescript": "^7.3.3",
97
- "@commitlint/cli": "^8.2.0",
98
- "@commitlint/config-conventional": "^8.2.0",
91
+ "@commitlint/cli": "^11.0.0",
92
+ "@commitlint/config-conventional": "^11.0.0",
99
93
  "@schemastore/package": "^0.0.6",
100
- "@semantic-release/changelog": "^3.0.5",
101
- "@semantic-release/git": "^7.0.17",
94
+ "@semantic-release/changelog": "^5.0.1",
95
+ "@semantic-release/git": "^9.0.0",
102
96
  "@types/dedent": "^0.7.0",
103
- "@types/jest": "^25.1.0",
104
- "@types/node": "^12.6.6",
105
- "@types/prettier": "^1.19.0",
106
- "@typescript-eslint/eslint-plugin": "^2.5.0",
107
- "@typescript-eslint/parser": "^2.5.0",
108
- "babel-jest": "^25.2.0",
97
+ "@types/jest": "^26.0.0",
98
+ "@types/node": "^14.0.0",
99
+ "@types/prettier": "^2.0.0",
100
+ "@typescript-eslint/eslint-plugin": "^4.0.1",
101
+ "@typescript-eslint/parser": "^4.0.1",
102
+ "babel-jest": "^26.0.1",
109
103
  "babel-plugin-replace-ts-export-assignment": "^0.0.2",
110
104
  "dedent": "^0.7.0",
111
- "eslint": "^5.1.0 || ^6.0.0",
105
+ "eslint": "^5.1.0 || ^6.0.0 || ^7.0.0",
112
106
  "eslint-config-prettier": "^6.5.0",
113
107
  "eslint-plugin-eslint-comments": "^3.1.2",
114
108
  "eslint-plugin-eslint-config": "^1.0.2",
@@ -116,23 +110,22 @@
116
110
  "eslint-plugin-import": "^2.20.2",
117
111
  "eslint-plugin-node": "^11.0.0",
118
112
  "eslint-plugin-prettier": "^3.0.0",
119
- "husky": "^3.0.9",
120
- "jest": "^25.2.0",
113
+ "husky": "^4.2.5",
114
+ "jest": "^26.0.1",
121
115
  "jest-runner-eslint": "^0.10.0",
122
- "lint-staged": "^9.4.2",
123
- "prettier": "^1.19.1",
124
- "prettylint": "^1.0.0",
116
+ "lint-staged": "^10.2.2",
117
+ "prettier": "^2.0.5",
125
118
  "resolve-from": "^5.0.0",
126
119
  "rimraf": "^3.0.0",
127
- "semantic-release": "^15.13.28",
128
- "ts-node": "^8.10.1",
129
- "typescript": "^3.5.3"
120
+ "semantic-release": "^17.0.7",
121
+ "ts-node": "^9.0.0",
122
+ "typescript": "^4.0.0"
130
123
  },
131
124
  "peerDependencies": {
132
125
  "eslint": ">=5"
133
126
  },
134
127
  "engines": {
135
- "node": ">=8"
128
+ "node": ">=10"
136
129
  },
137
130
  "release": {
138
131
  "plugins": [
@@ -1,76 +0,0 @@
1
- # Avoid using a callback in asynchronous tests (`no-test-callback`)
2
-
3
- Jest allows you to pass a callback to test definitions, typically called `done`,
4
- that is later invoked to indicate that the asynchronous test is complete.
5
-
6
- However, that means that if your test throws (e.g. because of a failing
7
- assertion), `done` will never be called unless you manually use `try-catch`.
8
-
9
- ```js
10
- test('some test', done => {
11
- expect(false).toBe(true);
12
- done();
13
- });
14
- ```
15
-
16
- The test above will time out instead of failing the assertions, since `done` is
17
- never called.
18
-
19
- Correct way of doing the same thing is to wrap it in `try-catch`.
20
-
21
- ```js
22
- test('some test', done => {
23
- try {
24
- expect(false).toBe(true);
25
- done();
26
- } catch (e) {
27
- done(e);
28
- }
29
- });
30
- ```
31
-
32
- However, Jest supports a second way of having asynchronous tests - using
33
- promises.
34
-
35
- ```js
36
- test('some test', () => {
37
- return new Promise(done => {
38
- expect(false).toBe(true);
39
- done();
40
- });
41
- });
42
- ```
43
-
44
- Even though `done` is never called here, the Promise will still reject, and Jest
45
- will report the assertion error correctly.
46
-
47
- ## Rule details
48
-
49
- This rule triggers a warning if you have a `done` callback in your test.
50
-
51
- The following patterns are considered warnings:
52
-
53
- ```js
54
- test('myFunction()', done => {
55
- // ...
56
- });
57
-
58
- test('myFunction()', function(done) {
59
- // ...
60
- });
61
- ```
62
-
63
- The following patterns are not considered warnings:
64
-
65
- ```js
66
- test('myFunction()', () => {
67
- expect(myFunction()).toBeTruthy();
68
- });
69
-
70
- test('myFunction()', () => {
71
- return new Promise(done => {
72
- expect(myFunction()).toBeTruthy();
73
- done();
74
- });
75
- });
76
- ```