Skip to content

Commit 1ef7b4a

Browse files
authored
Support Promise.all for missing-playwright-await (#117)
* Better scope for no-skipped-tests * Add examples folder for testing * Better scope for no-useless-not * max-nested-describe * missing-playwright-await * no-focused-test * no-force-option * no-page-pause * no-restricted-matchers * Update ecma version * no-wait-for-timeout * prefer-lowercase-title * prefer-strict-equal * prefer-to-be * prefer-to-have-length * require-top-level-describe * valid-expect * no-conditional-in-test * Update example eslintrc * no-eval * Cleanup * no-element-handle * Order * Use dedent * Update examples * Tests * Support `Promise.all`
1 parent 5c031ef commit 1ef7b4a

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/rules/missing-playwright-await.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,22 @@ function getCallType(
8787
}
8888
}
8989

90+
function isPromiseAll(node: Rule.Node) {
91+
return node.type === 'ArrayExpression' &&
92+
node.parent.type === 'CallExpression' &&
93+
node.parent.callee.type === 'MemberExpression' &&
94+
isIdentifier(node.parent.callee.object, 'Promise') &&
95+
isIdentifier(node.parent.callee.property, 'all')
96+
? node.parent
97+
: null;
98+
}
99+
90100
function checkValidity(node: Rule.Node): ESTree.Node | undefined {
91-
return validTypes.has(node.parent.type)
92-
? undefined
101+
if (validTypes.has(node.parent.type)) return;
102+
103+
const promiseAll = isPromiseAll(node.parent);
104+
return promiseAll
105+
? checkValidity(promiseAll)
93106
: node.parent.type === 'MemberExpression' ||
94107
(node.parent.type === 'CallExpression' && node.parent.callee === node)
95108
? checkValidity(node.parent)

test/spec/missing-playwright-await.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { runRuleTester, test } from '../utils/rule-tester';
22
import rule from '../../src/rules/missing-playwright-await';
3+
import * as dedent from 'dedent';
34

45
runRuleTester('missing-playwright-await', rule, {
56
valid: [
@@ -32,6 +33,15 @@ runRuleTester('missing-playwright-await', rule, {
3233
{ code: test('await expect[`poll`](() => foo).toBeTruthy()') },
3334
// test.step
3435
{ code: test("await test.step('foo', async () => {})") },
36+
// Promise.all
37+
{
38+
code: test(`
39+
await Promise.all([
40+
expect(page.locator("foo")).toHaveText("bar"),
41+
expect(page).toHaveTitle("baz"),
42+
])
43+
`),
44+
},
3545
],
3646
invalid: [
3747
{
@@ -196,5 +206,27 @@ runRuleTester('missing-playwright-await', rule, {
196206
},
197207
],
198208
},
209+
{
210+
code: dedent(
211+
test(`
212+
const promises = [
213+
expect(page.locator("foo")).toHaveText("bar"),
214+
expect(page).toHaveTitle("baz"),
215+
]
216+
`)
217+
),
218+
output: dedent(
219+
test(`
220+
const promises = [
221+
await expect(page.locator("foo")).toHaveText("bar"),
222+
await expect(page).toHaveTitle("baz"),
223+
]
224+
`)
225+
),
226+
errors: [
227+
{ messageId: 'expect', line: 3, column: 4, endLine: 3, endColumn: 10 },
228+
{ messageId: 'expect', line: 4, column: 4, endLine: 4, endColumn: 10 },
229+
],
230+
},
199231
],
200232
});

0 commit comments

Comments
 (0)