eslint-plugin-jest-formatting 2.0.1 → 3.0.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 +6 -0
- package/lib/rules/padding.js +9 -4
- package/package.json +1 -1
- package/src/rules/padding.ts +13 -6
- package/tests/lib/rules/padding-around-expect-groups.spec.js +64 -2
- package/.nvmrc +0 -1
package/CHANGELOG.md
CHANGED
package/lib/rules/padding.js
CHANGED
|
@@ -26,10 +26,15 @@ var PaddingType;
|
|
|
26
26
|
})(PaddingType = exports.PaddingType || (exports.PaddingType = {}));
|
|
27
27
|
const createTokenTester = (tokenName) => {
|
|
28
28
|
return (node, sourceCode) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
let activeNode = node;
|
|
30
|
+
if (activeNode.type === 'ExpressionStatement') {
|
|
31
|
+
if (activeNode.expression.type === 'AwaitExpression') {
|
|
32
|
+
activeNode = activeNode.expression.argument;
|
|
33
|
+
}
|
|
34
|
+
const token = sourceCode.getFirstToken(activeNode);
|
|
35
|
+
return token.type === 'Identifier' && token.value === tokenName;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
33
38
|
};
|
|
34
39
|
};
|
|
35
40
|
const statementTesters = {
|
package/package.json
CHANGED
package/src/rules/padding.ts
CHANGED
|
@@ -79,13 +79,20 @@ interface PaddingContext {
|
|
|
79
79
|
// Creates a StatementTester to test an ExpressionStatement's first token name
|
|
80
80
|
const createTokenTester = (tokenName: string): StatementTester => {
|
|
81
81
|
return (node: Node, sourceCode: SourceCode): boolean => {
|
|
82
|
-
|
|
82
|
+
let activeNode = node;
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
if (activeNode.type === 'ExpressionStatement') {
|
|
85
|
+
// In the case of `await`, we actually care about its argument
|
|
86
|
+
if (activeNode.expression.type === 'AwaitExpression') {
|
|
87
|
+
activeNode = activeNode.expression.argument;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const token = sourceCode.getFirstToken(activeNode);
|
|
91
|
+
|
|
92
|
+
return token.type === 'Identifier' && token.value === tokenName;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return false;
|
|
89
96
|
};
|
|
90
97
|
};
|
|
91
98
|
|
|
@@ -11,7 +11,7 @@ const rule = require('../../../lib').rules['padding-around-expect-groups'];
|
|
|
11
11
|
|
|
12
12
|
const ruleTester = new RuleTester({
|
|
13
13
|
parserOptions: {
|
|
14
|
-
ecmaVersion:
|
|
14
|
+
ecmaVersion: 2017,
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -63,6 +63,29 @@ describe('someText', () => {
|
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
|
+
|
|
67
|
+
test('awaited expect', async () => {
|
|
68
|
+
const abc = 123;
|
|
69
|
+
const hasAPromise = () => Promise.resolve('foo');
|
|
70
|
+
|
|
71
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
72
|
+
expect(abc).toEqual(123);
|
|
73
|
+
|
|
74
|
+
const efg = 456;
|
|
75
|
+
|
|
76
|
+
expect(123).toEqual(abc);
|
|
77
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
78
|
+
|
|
79
|
+
const hij = 789;
|
|
80
|
+
|
|
81
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
82
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
83
|
+
|
|
84
|
+
const somethingElseAsync = () => Promise.resolve('bar');
|
|
85
|
+
await somethingElseAsync();
|
|
86
|
+
|
|
87
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
88
|
+
});
|
|
66
89
|
`;
|
|
67
90
|
|
|
68
91
|
const invalid = `
|
|
@@ -103,6 +126,25 @@ describe('someText', () => {
|
|
|
103
126
|
});
|
|
104
127
|
});
|
|
105
128
|
});
|
|
129
|
+
|
|
130
|
+
test('awaited expect', async () => {
|
|
131
|
+
const abc = 123;
|
|
132
|
+
const hasAPromise = () => Promise.resolve('foo');
|
|
133
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
134
|
+
expect(abc).toEqual(123);
|
|
135
|
+
|
|
136
|
+
const efg = 456;
|
|
137
|
+
expect(123).toEqual(abc);
|
|
138
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
139
|
+
|
|
140
|
+
const hij = 789;
|
|
141
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
142
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
143
|
+
|
|
144
|
+
const somethingElseAsync = () => Promise.resolve('bar');
|
|
145
|
+
await somethingElseAsync();
|
|
146
|
+
await expect(hasAPromise()).resolves.toEqual('foo');
|
|
147
|
+
});
|
|
106
148
|
`;
|
|
107
149
|
|
|
108
150
|
ruleTester.run('padding-around-expect-groups', rule, {
|
|
@@ -111,7 +153,7 @@ ruleTester.run('padding-around-expect-groups', rule, {
|
|
|
111
153
|
{
|
|
112
154
|
code: invalid,
|
|
113
155
|
filename: 'src/component.test.jsx',
|
|
114
|
-
errors:
|
|
156
|
+
errors: 10,
|
|
115
157
|
output: valid,
|
|
116
158
|
},
|
|
117
159
|
{
|
|
@@ -148,6 +190,26 @@ ruleTester.run('padding-around-expect-groups', rule, {
|
|
|
148
190
|
line: 32,
|
|
149
191
|
column: 7
|
|
150
192
|
},
|
|
193
|
+
{
|
|
194
|
+
message: 'Expected blank line before this statement.',
|
|
195
|
+
line: 43,
|
|
196
|
+
column: 3
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
message: 'Expected blank line before this statement.',
|
|
200
|
+
line: 47,
|
|
201
|
+
column: 3
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
message: 'Expected blank line before this statement.',
|
|
205
|
+
line: 51,
|
|
206
|
+
column: 3
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
message: 'Expected blank line before this statement.',
|
|
210
|
+
line: 56,
|
|
211
|
+
column: 3
|
|
212
|
+
},
|
|
151
213
|
],
|
|
152
214
|
output: valid,
|
|
153
215
|
},
|
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
v8.10.0
|