Skip to content
Permalink
Browse files
chore: update recommended config
BREAKING CHANGE: new rules added to recommended config

closes #429
  • Loading branch information
SimenB authored and G-Rath committed Oct 27, 2019
1 parent 24ddc1b commit 14cb81579c23a3be34e5e0a989f516a398ec33cb
Showing with 139 additions and 10 deletions.
  1. +8 −8 README.md
  2. +94 −0 src/__tests__/__snapshots__/rules.test.ts.snap
  3. +29 −0 src/__tests__/rules.test.ts
  4. +8 −2 src/index.ts
@@ -111,28 +111,28 @@ installations requiring long-term consistency.
| Rule | Description | Configurations | Fixable |
| ------------------------------ | ----------------------------------------------------------------- | ---------------- | ------------------- |
| [consistent-test-it][] | Enforce consistent test or it keyword | | ![fixable-green][] |
| [expect-expect][] | Enforce assertion to be made in a test body | | |
| [expect-expect][] | Enforce assertion to be made in a test body | ![recommended][] | |
| [lowercase-name][] | Disallow capitalized test names | | ![fixable-green][] |
| [no-alias-methods][] | Disallow alias methods | ![recommended][] | ![fixable-green][] |
| [no-commented-out-tests][] | Disallow commented out tests | | |
| [no-alias-methods][] | Disallow alias methods | ![style][] | ![fixable-green][] |
| [no-commented-out-tests][] | Disallow commented out tests | ![recommended][] | |
| [no-disabled-tests][] | Disallow disabled tests | ![recommended][] | |
| [no-duplicate-hooks][] | Disallow duplicate hooks within a `describe` block | | |
| [no-expect-resolves][] | Disallow using `expect().resolves` | | |
| [no-export][] | Disallow export from test files | | |
| [no-export][] | Disallow export from test files | ![recommended][] | |
| [no-focused-tests][] | Disallow focused tests | ![recommended][] | |
| [no-hooks][] | Disallow setup and teardown hooks | | |
| [no-identical-title][] | Disallow identical titles | ![recommended][] | |
| [no-if][] | Disallow conditional logic | | |
| [no-jasmine-globals][] | Disallow Jasmine globals | ![recommended][] | ![fixable-yellow][] |
| [no-jest-import][] | Disallow importing `jest` | ![recommended][] | |
| [no-large-snapshots][] | Disallow large snapshots | | |
| [no-mocks-import][] | Disallow manually importing from `__mocks__` | | |
| [no-standalone-expect][] | Prevents `expect` statements outside of a `test` or `it` block | | |
| [no-test-callback][] | Using a callback in asynchronous tests | | ![fixable-green][] |
| [no-mocks-import][] | Disallow manually importing from `__mocks__` | ![recommended][] | |
| [no-standalone-expect][] | Prevents `expect` statements outside of a `test` or `it` block | ![recommended][] | |
| [no-test-callback][] | Using a callback in asynchronous tests | ![recommended][] | ![fixable-green][] |
| [no-test-prefixes][] | Disallow using `f` & `x` prefixes to define focused/skipped tests | ![recommended][] | ![fixable-green][] |
| [no-test-return-statement][] | Disallow explicitly returning from tests | | |
| [no-truthy-falsy][] | Disallow using `toBeTruthy()` & `toBeFalsy()` | | |
| [no-try-expect][] | Prevent `catch` assertions in tests | | |
| [no-try-expect][] | Prevent `catch` assertions in tests | ![recommended][] | |
| [prefer-called-with][] | Suggest using `toBeCalledWith()` OR `toHaveBeenCalledWith()` | | |
| [prefer-expect-assertions][] | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | |
| [prefer-hooks-on-top][] | Suggest to have all hooks at top-level before tests | | |
@@ -0,0 +1,94 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`rules should export configs that refer to actual rules 1`] = `
Object {
"all": Object {
"env": Object {
"jest/globals": true,
},
"plugins": Array [
"jest",
],
"rules": Object {
"jest/consistent-test-it": "error",
"jest/expect-expect": "error",
"jest/lowercase-name": "error",
"jest/no-alias-methods": "error",
"jest/no-commented-out-tests": "error",
"jest/no-disabled-tests": "error",
"jest/no-duplicate-hooks": "error",
"jest/no-expect-resolves": "error",
"jest/no-export": "error",
"jest/no-focused-tests": "error",
"jest/no-hooks": "error",
"jest/no-identical-title": "error",
"jest/no-if": "error",
"jest/no-jasmine-globals": "error",
"jest/no-jest-import": "error",
"jest/no-large-snapshots": "error",
"jest/no-mocks-import": "error",
"jest/no-standalone-expect": "error",
"jest/no-test-callback": "error",
"jest/no-test-prefixes": "error",
"jest/no-test-return-statement": "error",
"jest/no-truthy-falsy": "error",
"jest/no-try-expect": "error",
"jest/prefer-called-with": "error",
"jest/prefer-expect-assertions": "error",
"jest/prefer-hooks-on-top": "error",
"jest/prefer-inline-snapshots": "error",
"jest/prefer-spy-on": "error",
"jest/prefer-strict-equal": "error",
"jest/prefer-to-be-null": "error",
"jest/prefer-to-be-undefined": "error",
"jest/prefer-to-contain": "error",
"jest/prefer-to-have-length": "error",
"jest/prefer-todo": "error",
"jest/require-to-throw-message": "error",
"jest/require-top-level-describe": "error",
"jest/valid-describe": "error",
"jest/valid-expect": "error",
"jest/valid-expect-in-promise": "error",
"jest/valid-title": "error",
},
},
"recommended": Object {
"env": Object {
"jest/globals": true,
},
"plugins": Array [
"jest",
],
"rules": Object {
"jest/expect-expect": "warn",
"jest/no-commented-out-tests": "warn",
"jest/no-disabled-tests": "warn",
"jest/no-export": "error",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/no-jasmine-globals": "warn",
"jest/no-jest-import": "error",
"jest/no-mocks-import": "error",
"jest/no-standalone-expect": "error",
"jest/no-test-callback": "error",
"jest/no-test-prefixes": "error",
"jest/no-try-expect": "error",
"jest/valid-describe": "error",
"jest/valid-expect": "error",
"jest/valid-expect-in-promise": "error",
},
},
"style": Object {
"plugins": Array [
"jest",
],
"rules": Object {
"jest/no-alias-methods": "warn",
"jest/prefer-to-be-null": "error",
"jest/prefer-to-be-undefined": "error",
"jest/prefer-to-contain": "error",
"jest/prefer-to-have-length": "error",
},
},
}
`;
@@ -26,4 +26,33 @@ describe('rules', () => {
);
}
});

it('should export configs that refer to actual rules', () => {
const recommendedConfigs = plugin.configs;

expect(recommendedConfigs).toMatchSnapshot();
expect(Object.keys(recommendedConfigs)).toEqual([
'all',
'recommended',
'style',
]);
expect(Object.keys(recommendedConfigs.all.rules)).toHaveLength(
ruleNames.length,
);
const allConfigRules = Object.values(recommendedConfigs)
.map(config => Object.keys(config.rules))
.reduce((previousValue, currentValue) => [
...previousValue,
...currentValue,
]);

allConfigRules.forEach(rule => {
const ruleNamePrefix = 'jest/';
const ruleName = rule.slice(ruleNamePrefix.length);
expect(rule.startsWith(ruleNamePrefix)).toBe(true);
expect(ruleNames).toContain(ruleName);
// eslint-disable-next-line @typescript-eslint/no-require-imports
expect(() => require(`../rules/${ruleName}`)).not.toThrow();
});
});
});
@@ -44,14 +44,19 @@ export = {
'jest/globals': true,
},
rules: {
'jest/no-alias-methods': 'warn',
'jest/expect-expect': 'warn',
'jest/no-commented-out-tests': 'warn',
'jest/no-disabled-tests': 'warn',
'jest/no-export': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/no-jest-import': 'error',
// 'jest/no-mocks-import': 'error',
'jest/no-mocks-import': 'error',
'jest/no-jasmine-globals': 'warn',
'jest/no-standalone-expect': 'error',
'jest/no-test-callback': 'error',
'jest/no-test-prefixes': 'error',
'jest/no-try-expect': 'error',
'jest/valid-describe': 'error',
'jest/valid-expect': 'error',
'jest/valid-expect-in-promise': 'error',
@@ -60,6 +65,7 @@ export = {
style: {
plugins: ['jest'],
rules: {
'jest/no-alias-methods': 'warn',
'jest/prefer-to-be-null': 'error',
'jest/prefer-to-be-undefined': 'error',
'jest/prefer-to-contain': 'error',

0 comments on commit 14cb815

Please sign in to comment.