eslint-plugin-jest 27.2.0 → 27.2.2

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.
Files changed (79) hide show
  1. package/README.md +1 -1
  2. package/docs/rules/no-alias-methods.md +1 -1
  3. package/docs/rules/no-hooks.md +1 -1
  4. package/docs/rules/no-if.md +1 -1
  5. package/docs/rules/no-large-snapshots.md +4 -0
  6. package/docs/rules/require-hook.md +2 -6
  7. package/docs/rules/valid-expect.md +2 -2
  8. package/lib/index.js +5 -12
  9. package/lib/processors/__tests__/snapshot-processor.test.js +36 -0
  10. package/lib/rules/__tests__/consistent-test-it.test.js +921 -0
  11. package/lib/rules/__tests__/expect-expect.test.js +347 -0
  12. package/lib/rules/__tests__/fixtures/class.ts +13 -0
  13. package/lib/rules/__tests__/fixtures/file.ts +0 -0
  14. package/lib/rules/__tests__/fixtures/foo.ts +1 -0
  15. package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +530 -0
  16. package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +530 -0
  17. package/lib/rules/__tests__/fixtures/react.tsx +0 -0
  18. package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +6 -0
  19. package/lib/rules/__tests__/fixtures/tsconfig.json +16 -0
  20. package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
  21. package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
  22. package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +15 -0
  23. package/lib/rules/__tests__/max-expects.test.js +330 -0
  24. package/lib/rules/__tests__/max-nested-describe.test.js +247 -0
  25. package/lib/rules/__tests__/no-alias-methods.test.js +190 -0
  26. package/lib/rules/__tests__/no-commented-out-tests.test.js +213 -0
  27. package/lib/rules/__tests__/no-conditional-expect.test.js +696 -0
  28. package/lib/rules/__tests__/no-conditional-in-test.test.js +777 -0
  29. package/lib/rules/__tests__/no-deprecated-functions.test.js +119 -0
  30. package/lib/rules/__tests__/no-disabled-tests.test.js +241 -0
  31. package/lib/rules/__tests__/no-done-callback.test.js +424 -0
  32. package/lib/rules/__tests__/no-duplicate-hooks.test.js +469 -0
  33. package/lib/rules/__tests__/no-export.test.js +107 -0
  34. package/lib/rules/__tests__/no-focused-tests.test.js +373 -0
  35. package/lib/rules/__tests__/no-hooks.test.js +90 -0
  36. package/lib/rules/__tests__/no-identical-title.test.js +270 -0
  37. package/lib/rules/__tests__/no-if.test.js +787 -0
  38. package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +58 -0
  39. package/lib/rules/__tests__/no-jasmine-globals.test.js +206 -0
  40. package/lib/rules/__tests__/no-large-snapshots.test.js +237 -0
  41. package/lib/rules/__tests__/no-mocks-import.test.js +73 -0
  42. package/lib/rules/__tests__/no-restricted-jest-methods.test.js +103 -0
  43. package/lib/rules/__tests__/no-restricted-matchers.test.js +244 -0
  44. package/lib/rules/__tests__/no-standalone-expect.test.js +230 -0
  45. package/lib/rules/__tests__/no-test-prefixes.test.js +206 -0
  46. package/lib/rules/__tests__/no-test-return-statement.test.js +122 -0
  47. package/lib/rules/__tests__/no-untyped-mock-factory.test.js +149 -0
  48. package/lib/rules/__tests__/prefer-called-with.test.js +40 -0
  49. package/lib/rules/__tests__/prefer-comparison-matcher.test.js +200 -0
  50. package/lib/rules/__tests__/prefer-each.test.js +295 -0
  51. package/lib/rules/__tests__/prefer-equality-matcher.test.js +184 -0
  52. package/lib/rules/__tests__/prefer-expect-assertions.test.js +1437 -0
  53. package/lib/rules/__tests__/prefer-expect-resolves.test.js +96 -0
  54. package/lib/rules/__tests__/prefer-hooks-in-order.test.js +678 -0
  55. package/lib/rules/__tests__/prefer-hooks-on-top.test.js +218 -0
  56. package/lib/rules/__tests__/prefer-lowercase-title.test.js +619 -0
  57. package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +360 -0
  58. package/lib/rules/__tests__/prefer-snapshot-hint.test.js +784 -0
  59. package/lib/rules/__tests__/prefer-spy-on.test.js +100 -0
  60. package/lib/rules/__tests__/prefer-strict-equal.test.js +46 -0
  61. package/lib/rules/__tests__/prefer-to-be.test.js +438 -0
  62. package/lib/rules/__tests__/prefer-to-contain.test.js +301 -0
  63. package/lib/rules/__tests__/prefer-to-have-length.test.js +99 -0
  64. package/lib/rules/__tests__/prefer-todo.test.js +78 -0
  65. package/lib/rules/__tests__/require-hook.test.js +403 -0
  66. package/lib/rules/__tests__/require-to-throw-message.test.js +108 -0
  67. package/lib/rules/__tests__/require-top-level-describe.test.js +236 -0
  68. package/lib/rules/__tests__/test-utils.js +11 -0
  69. package/lib/rules/__tests__/unbound-method.test.js +518 -0
  70. package/lib/rules/__tests__/valid-describe-callback.test.js +305 -0
  71. package/lib/rules/__tests__/valid-expect-in-promise.test.js +1583 -0
  72. package/lib/rules/__tests__/valid-expect.test.js +894 -0
  73. package/lib/rules/__tests__/valid-title.test.js +1147 -0
  74. package/lib/rules/utils/__tests__/detectJestVersion.test.js +221 -0
  75. package/lib/rules/utils/__tests__/parseJestFnCall.test.js +809 -0
  76. package/lib/rules/utils/accessors.js +4 -0
  77. package/lib/rules/utils/misc.js +36 -20
  78. package/lib/rules/valid-expect-in-promise.js +3 -3
  79. package/package.json +13 -9
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <a href="https://eslint.org/">
3
3
  <img height="150" src="https://eslint.org/assets/images/logo/eslint-logo-color.svg">
4
4
  </a>
5
- <a href="https://facebook.github.io/jest/">
5
+ <a href="https://jestjs.io/">
6
6
  <img width="150" height="150" vspace="" hspace="25" src="https://jestjs.io/img/jest.png">
7
7
  </a>
8
8
  <h1>eslint-plugin-jest</h1>
@@ -11,7 +11,7 @@ This rule _warns_ in the 🎨 `style`
11
11
  <!-- end auto-generated rule header -->
12
12
 
13
13
  > These aliases are going to be removed in the next major version of Jest - see
14
- > <https://github.com/facebook/jest/issues/13164> for more
14
+ > <https://github.com/jestjs/jest/issues/13164> for more
15
15
 
16
16
  Several Jest methods have alias names, such as `toThrow` having the alias of
17
17
  `toThrowError`. This rule ensures that only the canonical name as used in the
@@ -173,4 +173,4 @@ safely disable this rule.
173
173
 
174
174
  ## Further Reading
175
175
 
176
- - [Jest docs - Setup and Teardown](https://facebook.github.io/jest/docs/en/setup-teardown.html)
176
+ - [Jest docs - Setup and Teardown](https://jestjs.io/docs/setup-teardown)
@@ -1,7 +1,7 @@
1
1
  # Disallow conditional logic (`no-if`)
2
2
 
3
3
  ❌ This rule is deprecated. It was replaced by
4
- [`jest/no-conditional-in-test`](../../docs/rules/no-conditional-in-test.md).
4
+ [`jest/no-conditional-in-test`](no-conditional-in-test.md).
5
5
 
6
6
  <!-- end auto-generated rule header -->
7
7
 
@@ -24,6 +24,10 @@ module.exports = {
24
24
  };
25
25
  ```
26
26
 
27
+ In order to check external snapshots, you must also have `eslint` check files
28
+ with the `.snap` extension by either passing `--ext snap` on the command line or
29
+ by explicitly specifying `.snap` in `overrides`.
30
+
27
31
  ## Rule details
28
32
 
29
33
  This rule looks at all Jest inline and external snapshots (files with `.snap`
@@ -2,12 +2,8 @@
2
2
 
3
3
  <!-- end auto-generated rule header -->
4
4
 
5
- Often while writing tests you have some setup work that needs to happen before
6
- tests run, and you have some finishing work that needs to happen after tests
7
- run. Jest provides helper functions to handle this.
8
-
9
- It's common when writing tests to need to perform setup work that needs to
10
- happen before tests run, and finishing work after tests run.
5
+ It's common when writing tests to need to perform setup work that has to happen
6
+ before tests run, and finishing work after tests run.
11
7
 
12
8
  Because Jest executes all `describe` handlers in a test file _before_ it
13
9
  executes any of the actual tests, it's important to ensure setup and teardown
@@ -66,7 +66,7 @@ This rule is enabled by default.
66
66
  Enforces to use `await` inside block statements. Using `return` will trigger a
67
67
  warning. Returning one line statements with arrow functions is _always allowed_.
68
68
 
69
- Examples of **incorrect** code for the { "alwaysAwait": **true** } option:
69
+ Examples of **incorrect** code for the `{ "alwaysAwait": true }` option:
70
70
 
71
71
  ```js
72
72
  // alwaysAwait: true
@@ -76,7 +76,7 @@ test('test1', async () => {
76
76
  });
77
77
  ```
78
78
 
79
- Examples of **correct** code for the { "alwaysAwait": **true** } option:
79
+ Examples of **correct** code for the `{ "alwaysAwait": true }` option:
80
80
 
81
81
  ```js
82
82
  // alwaysAwait: true
package/lib/index.js CHANGED
@@ -7,6 +7,8 @@ var snapshotProcessor = _interopRequireWildcard(require("./processors/snapshot-p
7
7
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
8
8
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ // v5 of `@typescript-eslint/experimental-utils` removed this
11
+
10
12
  // copied from https://github.com/babel/babel/blob/d8da63c929f2d28c401571e2a43166678c555bc4/packages/babel-helpers/src/helpers.js#L602-L606
11
13
  /* istanbul ignore next */
12
14
  const interopRequireDefault = obj => obj && obj.__esModule ? obj : {
@@ -17,18 +19,9 @@ const importDefault = moduleName =>
17
19
  interopRequireDefault(require(moduleName)).default;
18
20
  const rulesDir = (0, _path.join)(__dirname, 'rules');
19
21
  const excludedFiles = ['__tests__', 'detectJestVersion', 'utils'];
20
- const rules = (0, _fs.readdirSync)(rulesDir).map(rule => (0, _path.parse)(rule).name).filter(rule => !excludedFiles.includes(rule)).reduce((acc, curr) => ({
21
- ...acc,
22
- [curr]: importDefault((0, _path.join)(rulesDir, curr))
23
- }), {});
24
- const recommendedRules = Object.entries(rules).filter(([, rule]) => rule.meta.docs.recommended).reduce((acc, [name, rule]) => ({
25
- ...acc,
26
- [`jest/${name}`]: rule.meta.docs.recommended
27
- }), {});
28
- const allRules = Object.entries(rules).filter(([, rule]) => !rule.meta.deprecated).reduce((acc, [name]) => ({
29
- ...acc,
30
- [`jest/${name}`]: 'error'
31
- }), {});
22
+ const rules = Object.fromEntries((0, _fs.readdirSync)(rulesDir).map(rule => (0, _path.parse)(rule).name).filter(rule => !excludedFiles.includes(rule)).map(rule => [rule, importDefault((0, _path.join)(rulesDir, rule))]));
23
+ const recommendedRules = Object.fromEntries(Object.entries(rules).filter(([, rule]) => rule.meta.docs.recommended).map(([name, rule]) => [`jest/${name}`, rule.meta.docs.recommended]));
24
+ const allRules = Object.fromEntries(Object.entries(rules).filter(([, rule]) => !rule.meta.deprecated).map(([name]) => [`jest/${name}`, 'error']));
32
25
  const createConfig = rules => ({
33
26
  plugins: ['jest'],
34
27
  env: {
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var snapshotProcessor = _interopRequireWildcard(require("../snapshot-processor"));
4
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
5
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
6
+ describe('snapshot-processor', () => {
7
+ it('exports an object with preprocess and postprocess functions', () => {
8
+ expect(snapshotProcessor).toMatchObject({
9
+ preprocess: expect.any(Function),
10
+ postprocess: expect.any(Function)
11
+ });
12
+ });
13
+ describe('preprocess function', () => {
14
+ it('should pass on untouched source code to source array', () => {
15
+ const {
16
+ preprocess
17
+ } = snapshotProcessor;
18
+ const sourceCode = "const name = 'johnny bravo';";
19
+ const result = preprocess(sourceCode);
20
+ expect(result).toEqual([sourceCode]);
21
+ });
22
+ });
23
+ describe('postprocess function', () => {
24
+ it('should only return messages about snapshot specific rules', () => {
25
+ const {
26
+ postprocess
27
+ } = snapshotProcessor;
28
+ const result = postprocess([['no-console', 'global-require', 'jest/no-large-snapshots'].map(ruleId => ({
29
+ ruleId
30
+ }))]);
31
+ expect(result).toEqual([{
32
+ ruleId: 'jest/no-large-snapshots'
33
+ }]);
34
+ });
35
+ });
36
+ });