Skip to content

Support Promise.all for missing-playwright-await #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
213217f
Better scope for no-skipped-tests
mskelton Jan 14, 2023
5a16fde
Add examples folder for testing
mskelton Jan 15, 2023
484f243
Better scope for no-useless-not
mskelton Jan 15, 2023
89a16b0
max-nested-describe
mskelton Jan 15, 2023
93649d6
missing-playwright-await
mskelton Jan 15, 2023
b324d3a
no-focused-test
mskelton Jan 15, 2023
f34f23d
no-force-option
mskelton Jan 15, 2023
3a67a69
no-page-pause
mskelton Jan 15, 2023
8aa5782
no-restricted-matchers
mskelton Jan 15, 2023
0a449d3
Update ecma version
mskelton Jan 15, 2023
49a2eb9
no-wait-for-timeout
mskelton Jan 15, 2023
693ee8f
prefer-lowercase-title
mskelton Jan 15, 2023
3898539
prefer-strict-equal
mskelton Jan 15, 2023
ca83913
prefer-to-be
mskelton Jan 15, 2023
c449a00
prefer-to-have-length
mskelton Jan 15, 2023
74a24e4
require-top-level-describe
mskelton Jan 15, 2023
1b14ced
valid-expect
mskelton Jan 15, 2023
f16684e
no-conditional-in-test
mskelton Jan 15, 2023
5701fac
Update example eslintrc
mskelton Jan 15, 2023
0eed273
Merge branch 'main' into error-scope
mskelton Jan 15, 2023
a9f84ae
no-eval
mskelton Jan 15, 2023
ed607bb
Cleanup
mskelton Jan 15, 2023
252ec10
no-element-handle
mskelton Jan 15, 2023
4746570
Order
mskelton Jan 15, 2023
e32e4a0
Use dedent
mskelton Jan 15, 2023
c851876
Update examples
mskelton Jan 15, 2023
75f8238
Tests
mskelton Jan 16, 2023
62fdae8
Support `Promise.all`
mskelton Jan 16, 2023
8d052ad
Merge branch 'main' into missing-await-all
Jan 17, 2023
d8d2e70
Merge branch 'main' into missing-await-all
Jan 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/rules/missing-playwright-await.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,22 @@ function getCallType(
}
}

function isPromiseAll(node: Rule.Node) {
return node.type === 'ArrayExpression' &&
node.parent.type === 'CallExpression' &&
node.parent.callee.type === 'MemberExpression' &&
isIdentifier(node.parent.callee.object, 'Promise') &&
isIdentifier(node.parent.callee.property, 'all')
? node.parent
: null;
}

function checkValidity(node: Rule.Node): ESTree.Node | undefined {
return validTypes.has(node.parent.type)
? undefined
if (validTypes.has(node.parent.type)) return;

const promiseAll = isPromiseAll(node.parent);
return promiseAll
? checkValidity(promiseAll)
: node.parent.type === 'MemberExpression' ||
(node.parent.type === 'CallExpression' && node.parent.callee === node)
? checkValidity(node.parent)
Expand Down
32 changes: 32 additions & 0 deletions test/spec/missing-playwright-await.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { runRuleTester, test } from '../utils/rule-tester';
import rule from '../../src/rules/missing-playwright-await';
import * as dedent from 'dedent';

runRuleTester('missing-playwright-await', rule, {
valid: [
Expand Down Expand Up @@ -32,6 +33,15 @@ runRuleTester('missing-playwright-await', rule, {
{ code: test('await expect[`poll`](() => foo).toBeTruthy()') },
// test.step
{ code: test("await test.step('foo', async () => {})") },
// Promise.all
{
code: test(`
await Promise.all([
expect(page.locator("foo")).toHaveText("bar"),
expect(page).toHaveTitle("baz"),
])
`),
},
],
invalid: [
{
Expand Down Expand Up @@ -196,5 +206,27 @@ runRuleTester('missing-playwright-await', rule, {
},
],
},
{
code: dedent(
test(`
const promises = [
expect(page.locator("foo")).toHaveText("bar"),
expect(page).toHaveTitle("baz"),
]
`)
),
output: dedent(
test(`
const promises = [
await expect(page.locator("foo")).toHaveText("bar"),
await expect(page).toHaveTitle("baz"),
]
`)
),
errors: [
{ messageId: 'expect', line: 3, column: 4, endLine: 3, endColumn: 10 },
{ messageId: 'expect', line: 4, column: 4, endLine: 4, endColumn: 10 },
],
},
],
});