|
1 |
| -import type {Locator, Page, PlaywrightTestArgs, TestFixture} from '@playwright/test' |
| 1 | +import type {Locator, PlaywrightTestArgs, TestFixture} from '@playwright/test' |
2 | 2 | import {selectors} from '@playwright/test'
|
3 |
| -import {queries} from '@testing-library/dom' |
4 | 3 |
|
5 |
| -import {replacer} from '../helpers' |
6 |
| -import type { |
7 |
| - Config, |
8 |
| - LocatorQueries as Queries, |
9 |
| - Query, |
10 |
| - SelectorEngine, |
11 |
| - SupportedQuery, |
12 |
| -} from '../types' |
| 4 | +import type {Config, LocatorQueries as Queries, SelectorEngine, SynchronousQuery} from '../types' |
13 | 5 |
|
14 |
| -import {buildTestingLibraryScript, isAllQuery, isNotFindQuery, queryToSelector} from './helpers' |
| 6 | +import { |
| 7 | + buildTestingLibraryScript, |
| 8 | + isAllQuery, |
| 9 | + queriesFor, |
| 10 | + queryToSelector, |
| 11 | + synchronousQueryNames, |
| 12 | +} from './helpers' |
15 | 13 |
|
16 |
| -const allQueryNames = Object.keys(queries) as Query[] |
17 |
| - |
18 |
| -const queryNames = allQueryNames.filter(isNotFindQuery) |
19 | 14 | const defaultConfig: Config = {testIdAttribute: 'data-testid', asyncUtilTimeout: 1000}
|
20 | 15 |
|
21 | 16 | const options = Object.fromEntries(
|
22 | 17 | Object.entries(defaultConfig).map(([key, value]) => [key, [value, {option: true}] as const]),
|
23 | 18 | )
|
24 | 19 |
|
25 |
| -const queriesFor = (pageOrLocator: Page | Locator) => |
26 |
| - queryNames.reduce( |
27 |
| - (rest, query) => ({ |
28 |
| - ...rest, |
29 |
| - [query]: (...args: Parameters<Queries[keyof Queries]>) => |
30 |
| - pageOrLocator.locator(`${queryToSelector(query)}=${JSON.stringify(args, replacer)}`), |
31 |
| - }), |
32 |
| - {} as Queries, |
33 |
| - ) |
34 |
| - |
35 | 20 | const queriesFixture: TestFixture<Queries, PlaywrightTestArgs> = async ({page}, use) =>
|
36 | 21 | use(queriesFor(page))
|
37 | 22 |
|
38 | 23 | const within = (locator: Locator): Queries => queriesFor(locator)
|
39 | 24 |
|
40 |
| -declare const queryName: SupportedQuery |
| 25 | +declare const queryName: SynchronousQuery |
41 | 26 |
|
42 | 27 | const engine: () => SelectorEngine = () => ({
|
43 | 28 | query(root, selector) {
|
@@ -77,7 +62,7 @@ const registerSelectorsFixture: [
|
77 | 62 | async ({}, use) => {
|
78 | 63 | try {
|
79 | 64 | await Promise.all(
|
80 |
| - queryNames.map(async name => |
| 65 | + synchronousQueryNames.map(async name => |
81 | 66 | selectors.register(
|
82 | 67 | queryToSelector(name),
|
83 | 68 | `(${engine.toString().replace(/queryName/g, `"${name}"`)})()`,
|
|
0 commit comments