Skip to content

Commit 022368a

Browse files
authored
feat: add shareable framework configs (#7)
* Setup eslint plugins for jest * Add snapshot test for recommended config * Revert unnecessary eslint env * Add configs for angular, react and vue * Add frameworks column to Supported Rules table * Fix framework logos links * Add category section within Shareable configurations section * Edit headers * Simplify configs tests cases with each util * feat: add commitlint and commit-msg hook (#8) * feat: add commitlint and commit-msg hook (#8) * Setup eslint plugins for jest * build: merge package-lock * Setup eslint plugins for jest * Add snapshot test for recommended config * Revert unnecessary eslint env * Add configs for angular, react and vue * Add frameworks column to Supported Rules table * Fix framework logos links * Add category section within Shareable configurations section * Edit headers * Simplify configs tests cases with each util * Setup eslint plugins for jest * build: merge package-lock
1 parent 5446f66 commit 022368a

File tree

8 files changed

+228
-19
lines changed

8 files changed

+228
-19
lines changed

.eslintrc.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
"env": {
33
"commonjs": true,
44
"es6": true,
5-
"node": true
5+
"node": true,
6+
"jest/globals": true
67
},
78
"extends": [
89
"standard",
9-
"prettier"
10+
"prettier",
11+
"plugin:jest/recommended",
12+
"plugin:jest-formatting/recommended"
1013
],
1114
"plugins": [
12-
"prettier"
15+
"prettier",
16+
"jest",
17+
"jest-formatting"
1318
],
1419
"globals": {
1520
"Atomics": "readonly",

README.md

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ Then configure the rules you want to use under the rules section.
4040
```json
4141
{
4242
"rules": {
43-
"testing-library/await-async-query": "warn",
44-
"testing-library/no-await-sync-query": "error"
43+
"testing-library/await-async-query": "error",
44+
"testing-library/no-await-sync-query": "error",
45+
"testing-library/no-debug": "warn"
4546
}
4647
}
4748
```
@@ -50,22 +51,77 @@ Then configure the rules you want to use under the rules section.
5051

5152
### Recommended
5253

53-
This plugin exports a recommended configuration that enforces good Testing Library practices.
54+
This plugin exports a recommended configuration that enforces good
55+
Testing Library practices _(you can find more info about enabled rules
56+
in [Supported Rules section](#supported-rules) within Recommended
57+
column)_.
5458

55-
To enable this configuration use the `extends` property in your `.eslintrc` config file:
59+
To enable this configuration use the `extends` property in your
60+
`.eslintrc` config file:
5661

5762
```json
5863
{
5964
"extends": ["plugin:testing-library/recommended"]
6065
}
6166
```
6267

68+
### Frameworks
69+
70+
Starting from the premise that
71+
[DOM Testing Library](https://testing-library.com/docs/dom-testing-library/intro)
72+
is the base for the rest of Testing Library frameworks wrappers, this
73+
plugin also exports different configuration for those frameworks that
74+
enforces good practices for specific rules that only apply to them _(you
75+
can find more info about enabled rules in
76+
[Supported Rules section](#supported-rules) within Frameworks column)_.
77+
78+
**Note that frameworks configurations enable their specific rules +
79+
recommended rules.**
80+
81+
Available frameworks configurations are:
82+
83+
#### Angular
84+
85+
To enable this configuration use the `extends` property in your
86+
`.eslintrc` config file:
87+
88+
```json
89+
{
90+
"extends": ["plugin:testing-library/angular"]
91+
}
92+
```
93+
94+
#### React
95+
96+
To enable this configuration use the `extends` property in your
97+
`.eslintrc` config file:
98+
99+
```json
100+
{
101+
"extends": ["plugin:testing-library/react"]
102+
}
103+
```
104+
105+
#### Vue
106+
107+
To enable this configuration use the `extends` property in your
108+
`.eslintrc` config file:
109+
110+
```json
111+
{
112+
"extends": ["plugin:testing-library/vue"]
113+
}
114+
```
115+
63116
## Supported Rules
64117

65-
| Rule | Description | Recommended |
66-
| -------------------------------------------------------- | --------------------------------------------- | ---------------- |
67-
| [await-async-query](docs/rules/await-async-query.md) | Enforce async queries to have proper `await` | ![recommended][] |
68-
| [no-await-sync-query](docs/rules/no-await-sync-query.md) | Disallow unnecessary `await` for sync queries | ![recommended][] |
69-
| [no-debug](docs/rules/no-debug.md) | Disallow the use of `debug` | |
118+
| Rule | Description | Recommended | Frameworks |
119+
| -------------------------------------------------------- | --------------------------------------------- | ---------------- | -------------------------------- |
120+
| [await-async-query](docs/rules/await-async-query.md) | Enforce async queries to have proper `await` | ![recommended][] | |
121+
| [no-await-sync-query](docs/rules/no-await-sync-query.md) | Disallow unnecessary `await` for sync queries | ![recommended][] | |
122+
| [no-debug](docs/rules/no-debug.md) | Disallow the use of `debug` | | ![angular][] ![react][] ![vue][] |
70123

71124
[recommended]: https://img.shields.io/badge/recommended-lightgrey?style=flat-square
125+
[angular]: https://img.shields.io/badge/-Angular-black?style=flat-square&logo=angular&logoColor=white&labelColor=DD0031&color=black
126+
[react]: https://img.shields.io/badge/-React-black?style=flat-square&logo=react&logoColor=white&labelColor=61DAFB&color=black
127+
[vue]: https://img.shields.io/badge/-Vue-black?style=flat-square&logo=vue.js&logoColor=white&labelColor=4FC08D&color=black

lib/index.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@ const rules = {
55
'no-await-sync-query': require('./rules/no-await-sync-query'),
66
};
77

8+
const recommendedRules = {
9+
'testing-library/await-async-query': 'error',
10+
'testing-library/no-await-sync-query': 'error',
11+
};
12+
813
module.exports = {
914
rules,
1015
configs: {
1116
recommended: {
1217
plugins: ['testing-library'],
13-
rules: {
14-
'testing-library/await-async-query': 'error',
15-
'testing-library/no-await-sync-query': 'error',
16-
},
18+
rules: recommendedRules,
19+
},
20+
angular: {
21+
plugins: ['testing-library'],
22+
rules: { ...recommendedRules, 'testing-library/no-debug': 'warn' },
23+
},
24+
react: {
25+
plugins: ['testing-library'],
26+
rules: { ...recommendedRules, 'testing-library/no-debug': 'warn' },
27+
},
28+
vue: {
29+
plugins: ['testing-library'],
30+
rules: { ...recommendedRules, 'testing-library/no-debug': 'warn' },
1731
},
1832
},
1933
};

lib/rules/await-async-query.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ function isPromiseResolved(node) {
9797
return hasAThenProperty(parent);
9898
}
9999

100-
function findParent(node, test) {
101-
if (test(node)) {
100+
function findParent(node, check) {
101+
if (check(node)) {
102102
return node;
103103
} else if (node.parent) {
104-
return findParent(node.parent, test);
104+
return findParent(node.parent, check);
105105
}
106106
return null;
107107
}

package-lock.json

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"eslint-config-prettier": "^6.1.0",
3636
"eslint-config-standard": "^14.1.0",
3737
"eslint-plugin-import": "^2.18.2",
38+
"eslint-plugin-jest": "^22.17.0",
39+
"eslint-plugin-jest-formatting": "^1.1.0",
3840
"eslint-plugin-node": "^9.2.0",
3941
"eslint-plugin-prettier": "^3.1.0",
4042
"eslint-plugin-promise": "^4.2.1",

tests/__snapshots__/index.js.snap

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`shareable configs should export proper "angular" config 1`] = `
4+
Object {
5+
"plugins": Array [
6+
"testing-library",
7+
],
8+
"rules": Object {
9+
"testing-library/await-async-query": "error",
10+
"testing-library/no-await-sync-query": "error",
11+
"testing-library/no-debug": "warn",
12+
},
13+
}
14+
`;
15+
16+
exports[`shareable configs should export proper "react" config 1`] = `
17+
Object {
18+
"plugins": Array [
19+
"testing-library",
20+
],
21+
"rules": Object {
22+
"testing-library/await-async-query": "error",
23+
"testing-library/no-await-sync-query": "error",
24+
"testing-library/no-debug": "warn",
25+
},
26+
}
27+
`;
28+
29+
exports[`shareable configs should export proper "recommended" config 1`] = `
30+
Object {
31+
"plugins": Array [
32+
"testing-library",
33+
],
34+
"rules": Object {
35+
"testing-library/await-async-query": "error",
36+
"testing-library/no-await-sync-query": "error",
37+
},
38+
}
39+
`;
40+
41+
exports[`shareable configs should export proper "vue" config 1`] = `
42+
Object {
43+
"plugins": Array [
44+
"testing-library",
45+
],
46+
"rules": Object {
47+
"testing-library/await-async-query": "error",
48+
"testing-library/no-await-sync-query": "error",
49+
"testing-library/no-debug": "warn",
50+
},
51+
}
52+
`;

tests/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const { configs } = require('../lib');
4+
5+
describe('shareable configs', () => {
6+
it.each(['recommended', 'angular', 'react', 'vue'])(
7+
'should export proper "%s" config',
8+
configName => {
9+
expect(configs[configName]).toMatchSnapshot();
10+
}
11+
);
12+
});

0 commit comments

Comments
 (0)