@aerogel/playwright 0.1.2-next.172d94733294f11f2f2d6f15f09acf7ed6381bb3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Noel De Martin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,83 @@
1
+ import { Expect } from '@playwright/test';
2
+ import { ExpectMatcherState } from '@playwright/test';
3
+ import { GetModelInput } from 'soukai-bis';
4
+ import { Locator } from '@playwright/test';
5
+ import { ModelsRegistry } from 'soukai-bis';
6
+ import { Page } from '@playwright/test';
7
+ import { PlaywrightTestArgs } from '@playwright/test';
8
+ import { PlaywrightTestOptions } from '@playwright/test';
9
+ import { PlaywrightWorkerArgs } from '@playwright/test';
10
+ import { PlaywrightWorkerOptions } from '@playwright/test';
11
+ import { Request as Request_2 } from '@playwright/test';
12
+ import { Response as Response_2 } from '@playwright/test';
13
+ import { TestType } from '@playwright/test';
14
+
15
+ export declare function comboboxSelect(page: Page, labelOrSelector: string, value: string): Promise<void>;
16
+
17
+ export declare function countModels<T extends keyof ModelsRegistry>(page: Page, name: T): Promise<number>;
18
+
19
+ export declare function createModel<T extends keyof ModelsRegistry>(page: Page, name: T, data: GetModelInput<ModelsRegistry[T]>): Promise<void>;
20
+
21
+ export declare function disableErrorHandling(page: Page): Promise<void>;
22
+
23
+ export declare function dontSee(page: Page, text: string, options?: SeeOptions): Promise<void>;
24
+
25
+ export declare const expect: Expect< {
26
+ toEqualSparql(this: ExpectMatcherState, received: unknown, expected: string): {
27
+ pass: boolean;
28
+ message: () => string;
29
+ };
30
+ }>;
31
+
32
+ export declare function input(page: Page, label: string, options?: InputOptions): Locator;
33
+
34
+ export declare type InputOptions = {
35
+ description?: string;
36
+ };
37
+
38
+ export declare type InterceptedCall = {
39
+ url: string;
40
+ method: string;
41
+ body: string | null;
42
+ status: number;
43
+ request: Request_2;
44
+ response: Response_2;
45
+ };
46
+
47
+ export declare type InterceptHandle = {
48
+ readonly all: InterceptedCall[];
49
+ slice(start: number, end: number): InterceptedCall[];
50
+ nth(index: number): InterceptedCall | undefined;
51
+ };
52
+
53
+ export declare function interceptRequests(page: Page, url: string): InterceptHandle;
54
+
55
+ export declare function interceptRequests(page: Page, method: string, url: string): InterceptHandle;
56
+
57
+ export declare function matchImageSnapshot(page: Page, name?: string): Promise<void>;
58
+
59
+ export declare function press(page: Page, label: string, options?: PressOptions): Promise<void>;
60
+
61
+ export declare type PressOptions = {
62
+ within?: Locator;
63
+ selector?: string;
64
+ };
65
+
66
+ export declare function see(page: Page, text: string, selectorOrOptions?: string | SeeOptions, options?: SeeOptions): Promise<Locator>;
67
+
68
+ export declare function seeImage(page: Page, alt: string): Promise<void>;
69
+
70
+ export declare type SeeOptions = {
71
+ srOnly?: boolean;
72
+ timeout?: number;
73
+ within?: Locator;
74
+ };
75
+
76
+ export declare const test: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
77
+
78
+ export declare function waitSync(page: Page): Promise<void>;
79
+
80
+
81
+ export * from "playwright-solid";
82
+
83
+ export { }
@@ -0,0 +1,147 @@
1
+ import w, { expect as l } from "@playwright/test";
2
+ export * from "playwright-solid";
3
+ import { normalizeSparql as u } from "@noeldemartin/solid-utils";
4
+ import { sparqlEquals as d } from "@noeldemartin/solid-utils/testing";
5
+ function f(t, e) {
6
+ return t.getByText(e, { exact: !1 }).or(t.locator(`[aria-label="${e}"]`)).first();
7
+ }
8
+ function x(t, e, i = {}) {
9
+ const n = t.getByLabel(e, { exact: !0 });
10
+ return i.description ? n.filter({
11
+ has: t.locator(`[aria-description="${i.description}"], [aria-describedby]`)
12
+ }) : n;
13
+ }
14
+ async function _(t, e, i = {}) {
15
+ const n = i.selector ?? 'button:visible, a:visible, label:visible, details:visible, [role="menuitem"]:visible', o = (a) => a.locator(n).filter({ hasText: e }).or(a.locator(`[aria-label="${e}"]`)).first();
16
+ if (i.within) {
17
+ await o(i.within).click();
18
+ return;
19
+ }
20
+ const s = t.locator('[role="dialog"][data-state="open"]:not([aria-hidden="true"])').last(), c = o(s);
21
+ await (await c.count() > 0 ? c : o(t)).click();
22
+ }
23
+ async function E(t, e, i) {
24
+ await t.waitForTimeout(300);
25
+ const o = await t.locator("label[for]").filter({ hasText: e }).first().getAttribute("for");
26
+ await t.locator(o ? `#${o}` : e).click(), await t.waitForTimeout(300), await t.locator('*[role="option"]').filter({ hasText: i }).first().click();
27
+ }
28
+ async function m(t, e, i = {}, n = {}) {
29
+ const o = typeof i == "string" ? n.srOnly : i.srOnly, s = typeof i == "string" ? n : i, c = s.timeout, r = s.within ?? t, a = typeof i == "string" ? r.locator(i).filter({ hasText: e }).first() : f(r, e);
30
+ return o ? await l(a).toBeAttached({ timeout: c }) : await l(a).toBeVisible({ timeout: c }), a;
31
+ }
32
+ async function R(t, e) {
33
+ const i = t.locator(`img[alt="${e}"]`).first();
34
+ await i.scrollIntoViewIfNeeded(), await l(i).toBeVisible();
35
+ }
36
+ async function h(t, e, i = {}) {
37
+ const n = i.within ?? t;
38
+ await l(f(n, e)).not.toBeVisible({ timeout: i.timeout });
39
+ }
40
+ async function q(t) {
41
+ await t.addInitScript(() => {
42
+ window.__aerogelDisableErrorHandling__ = !0;
43
+ });
44
+ }
45
+ function b(t, e) {
46
+ return t.endsWith("*") ? e.startsWith(t.slice(0, -1)) : e === t;
47
+ }
48
+ function y(t, e, i) {
49
+ return i && t.method().toUpperCase() !== i.toUpperCase() ? !1 : b(e, t.url());
50
+ }
51
+ function H(t, e, i) {
52
+ const n = i === void 0 ? void 0 : e, o = i ?? e, s = [], c = (r) => {
53
+ const a = r.request();
54
+ y(a, o, n) && s.push({
55
+ url: a.url(),
56
+ method: a.method(),
57
+ body: a.postData(),
58
+ status: r.status(),
59
+ request: a,
60
+ response: r
61
+ });
62
+ };
63
+ return t.on("response", c), {
64
+ get all() {
65
+ return s;
66
+ },
67
+ slice(r, a) {
68
+ return s.slice(r, a);
69
+ },
70
+ nth(r) {
71
+ return s[r - 1];
72
+ }
73
+ };
74
+ }
75
+ async function A(t, e, i) {
76
+ await t.evaluate(
77
+ async ({ modelName: n, modelData: o }) => {
78
+ if (!window.testingRuntime)
79
+ throw new Error("Testing runtime is not available");
80
+ await window.testingRuntime.model(n).create(o);
81
+ },
82
+ { modelName: e, modelData: i }
83
+ );
84
+ }
85
+ async function B(t, e) {
86
+ return t.evaluate(async (i) => {
87
+ if (!window.testingRuntime)
88
+ throw new Error("Testing runtime is not available");
89
+ return (await window.testingRuntime.model(i).all()).length;
90
+ }, e);
91
+ }
92
+ async function I(t, e) {
93
+ !process.env.SNAPSHOTS && !process.env.PLAYWRIGHT_SNAPSHOTS || (e ? await l(t).toHaveScreenshot(`${e}.png`, { animations: "disabled" }) : await l(t).toHaveScreenshot({ animations: "disabled" }));
94
+ }
95
+ async function $(t) {
96
+ await m(t, "Synchronization in progress"), await h(t, "Synchronization in progress", { timeout: 1e4 }), await t.waitForTimeout(100);
97
+ }
98
+ const k = l.extend({
99
+ toEqualSparql(t, e) {
100
+ const i = String(t ?? ""), n = d(e, i);
101
+ return {
102
+ pass: n.success,
103
+ message: () => n.success ? "Expected SPARQL not to match." : [n.message, this.utils.diff(u(e), u(i))].join(`
104
+ `)
105
+ };
106
+ }
107
+ });
108
+ async function g(t) {
109
+ await t.addInitScript(() => {
110
+ window.__aerogelEvents__ = {
111
+ error: ({ error: e, message: i }) => {
112
+ if (window.__aerogelDisableErrorHandling__)
113
+ return;
114
+ const n = e instanceof Error ? e : new Error(i || String(e));
115
+ setTimeout(() => {
116
+ throw n;
117
+ });
118
+ }
119
+ };
120
+ }), t.on("pageerror", (e) => {
121
+ if (!e.message.includes("ResizeObserver loop completed with undelivered notifications."))
122
+ throw e;
123
+ });
124
+ }
125
+ const S = w.extend({
126
+ page: async ({ page: t }, e) => {
127
+ await g(t), await e(t);
128
+ }
129
+ });
130
+ S.use({ storageState: { cookies: [], origins: [] } });
131
+ export {
132
+ E as comboboxSelect,
133
+ B as countModels,
134
+ A as createModel,
135
+ q as disableErrorHandling,
136
+ h as dontSee,
137
+ k as expect,
138
+ x as input,
139
+ H as interceptRequests,
140
+ I as matchImageSnapshot,
141
+ _ as press,
142
+ m as see,
143
+ R as seeImage,
144
+ S as test,
145
+ $ as waitSync
146
+ };
147
+ //# sourceMappingURL=aerogel-playwright.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aerogel-playwright.js","sources":["../src/lib/a11y.ts","../src/lib/errors.ts","../src/lib/intercept.ts","../src/lib/models.ts","../src/lib/snapshots.ts","../src/lib/sync.ts","../src/setup/matchers.ts","../src/setup/errors.ts","../src/setup/index.ts"],"sourcesContent":["import { expect } from '@playwright/test';\nimport type { Locator, Page } from '@playwright/test';\n\nexport type InputOptions = {\n description?: string;\n};\n\nexport type PressOptions = {\n within?: Locator;\n selector?: string;\n};\n\nexport type SeeOptions = {\n srOnly?: boolean;\n timeout?: number;\n within?: Locator;\n};\n\nfunction findByA11yText(scope: Page | Locator, text: string): Locator {\n return scope\n .getByText(text, { exact: false })\n .or(scope.locator(`[aria-label=\"${text}\"]`))\n .first();\n}\n\nexport function input(page: Page, label: string, options: InputOptions = {}): Locator {\n const locator = page.getByLabel(label, { exact: true });\n\n if (options.description) {\n return locator.filter({\n has: page.locator(`[aria-description=\"${options.description}\"], [aria-describedby]`),\n });\n }\n\n return locator;\n}\n\nexport async function press(page: Page, label: string, options: PressOptions = {}): Promise<void> {\n const targetSelector =\n options.selector ?? 'button:visible, a:visible, label:visible, details:visible, [role=\"menuitem\"]:visible';\n const findTarget = (scope: Page | Locator) =>\n scope\n .locator(targetSelector)\n .filter({ hasText: label })\n .or(scope.locator(`[aria-label=\"${label}\"]`))\n .first();\n\n if (options.within) {\n await findTarget(options.within).click();\n\n return;\n }\n\n const dialog = page.locator('[role=\"dialog\"][data-state=\"open\"]:not([aria-hidden=\"true\"])').last();\n const inDialog = findTarget(dialog);\n const locator = (await inDialog.count()) > 0 ? inDialog : findTarget(page);\n\n await locator.click();\n}\n\nexport async function comboboxSelect(page: Page, labelOrSelector: string, value: string): Promise<void> {\n await page.waitForTimeout(300);\n const label = page.locator('label[for]').filter({ hasText: labelOrSelector }).first();\n const id = await label.getAttribute('for');\n\n await page.locator(id ? `#${id}` : labelOrSelector).click();\n await page.waitForTimeout(300);\n await page.locator('*[role=\"option\"]').filter({ hasText: value }).first().click();\n}\n\nexport async function see(\n page: Page,\n text: string,\n selectorOrOptions: string | SeeOptions = {},\n options: SeeOptions = {},\n): Promise<Locator> {\n const srOnly = typeof selectorOrOptions === 'string' ? options.srOnly : selectorOrOptions.srOnly;\n const baseOptions = typeof selectorOrOptions === 'string' ? options : selectorOrOptions;\n const timeout = baseOptions.timeout;\n const scope = baseOptions.within ?? page;\n const locator =\n typeof selectorOrOptions === 'string'\n ? scope.locator(selectorOrOptions).filter({ hasText: text }).first()\n : findByA11yText(scope, text);\n\n if (srOnly) {\n await expect(locator).toBeAttached({ timeout });\n } else {\n await expect(locator).toBeVisible({ timeout });\n }\n\n return locator;\n}\n\nexport async function seeImage(page: Page, alt: string): Promise<void> {\n const locator = page.locator(`img[alt=\"${alt}\"]`).first();\n\n await locator.scrollIntoViewIfNeeded();\n await expect(locator).toBeVisible();\n}\n\nexport async function dontSee(page: Page, text: string, options: SeeOptions = {}): Promise<void> {\n const scope = options.within ?? page;\n\n await expect(findByA11yText(scope, text)).not.toBeVisible({ timeout: options.timeout });\n}\n","import type { Page } from '@playwright/test';\n\nexport async function disableErrorHandling(page: Page): Promise<void> {\n await page.addInitScript(() => {\n window.__aerogelDisableErrorHandling__ = true;\n });\n}\n","import type { Page, Request, Response } from '@playwright/test';\n\nexport type InterceptedCall = {\n url: string;\n method: string;\n body: string | null;\n status: number;\n request: Request;\n response: Response;\n};\n\nexport type InterceptHandle = {\n readonly all: InterceptedCall[];\n slice(start: number, end: number): InterceptedCall[];\n nth(index: number): InterceptedCall | undefined;\n};\n\nfunction matchesUrl(glob: string, url: string): boolean {\n if (glob.endsWith('*')) {\n return url.startsWith(glob.slice(0, -1));\n }\n\n return url === glob;\n}\n\nfunction matchesRequest(request: Request, glob: string, method?: string): boolean {\n if (method && request.method().toUpperCase() !== method.toUpperCase()) {\n return false;\n }\n\n return matchesUrl(glob, request.url());\n}\n\nexport function interceptRequests(page: Page, url: string): InterceptHandle;\nexport function interceptRequests(page: Page, method: string, url: string): InterceptHandle;\nexport function interceptRequests(page: Page, methodOrUrl: string, url?: string): InterceptHandle {\n const method = url === undefined ? undefined : methodOrUrl;\n const glob = url ?? methodOrUrl;\n const calls: InterceptedCall[] = [];\n\n const onResponse = (response: Response) => {\n const request = response.request();\n\n if (!matchesRequest(request, glob, method)) {\n return;\n }\n\n calls.push({\n url: request.url(),\n method: request.method(),\n body: request.postData(),\n status: response.status(),\n request,\n response,\n });\n };\n\n page.on('response', onResponse);\n\n return {\n get all() {\n return calls;\n },\n slice(start: number, end: number) {\n return calls.slice(start, end);\n },\n nth(index: number) {\n return calls[index - 1];\n },\n };\n}\n","import type { Page } from '@playwright/test';\nimport type { GetModelInput, ModelsRegistry } from 'soukai-bis';\n\nexport async function createModel<T extends keyof ModelsRegistry>(\n page: Page,\n name: T,\n data: GetModelInput<ModelsRegistry[T]>,\n): Promise<void> {\n await page.evaluate(\n async ({ modelName, modelData }) => {\n if (!window.testingRuntime) {\n throw new Error('Testing runtime is not available');\n }\n\n await window.testingRuntime.model(modelName as string).create(modelData);\n },\n { modelName: name, modelData: data },\n );\n}\n\nexport async function countModels<T extends keyof ModelsRegistry>(page: Page, name: T): Promise<number> {\n return page.evaluate(async (modelName) => {\n if (!window.testingRuntime) {\n throw new Error('Testing runtime is not available');\n }\n\n const instances = await window.testingRuntime.model(modelName as string).all();\n\n return instances.length;\n }, name);\n}\n","import { expect } from '@playwright/test';\nimport type { Page } from '@playwright/test';\n\nexport async function matchImageSnapshot(page: Page, name?: string): Promise<void> {\n if (!process.env.SNAPSHOTS && !process.env.PLAYWRIGHT_SNAPSHOTS) {\n return;\n }\n\n if (name) {\n await expect(page).toHaveScreenshot(`${name}.png`, { animations: 'disabled' });\n } else {\n await expect(page).toHaveScreenshot({ animations: 'disabled' });\n }\n}\n","import type { Page } from '@playwright/test';\n\nimport { dontSee, see } from './a11y';\n\nexport async function waitSync(page: Page): Promise<void> {\n await see(page, 'Synchronization in progress');\n await dontSee(page, 'Synchronization in progress', { timeout: 10000 });\n await page.waitForTimeout(100);\n}\n","import { normalizeSparql } from '@noeldemartin/solid-utils';\nimport { sparqlEquals } from '@noeldemartin/solid-utils/testing';\nimport { expect as baseExpect } from '@playwright/test';\n\nexport const expect = baseExpect.extend({\n toEqualSparql(received: unknown, expected: string) {\n const actual = String(received ?? '');\n const result = sparqlEquals(expected, actual);\n\n return {\n pass: result.success,\n message: () => {\n if (result.success) {\n return 'Expected SPARQL not to match.';\n }\n\n return [result.message, this.utils.diff(normalizeSparql(expected), normalizeSparql(actual))].join('\\n');\n },\n };\n },\n});\n","import type { Page } from '@playwright/test';\n\nexport async function setupErrorListener(page: Page): Promise<void> {\n await page.addInitScript(() => {\n window.__aerogelEvents__ = {\n error: ({ error, message }: { error: unknown; message?: string }) => {\n if (window.__aerogelDisableErrorHandling__) {\n return;\n }\n\n const errorToThrow = error instanceof Error ? error : new Error(message || String(error));\n\n setTimeout(() => {\n throw errorToThrow;\n });\n },\n };\n });\n\n page.on('pageerror', (exception) => {\n if (exception.message.includes('ResizeObserver loop completed with undelivered notifications.')) {\n return;\n }\n\n throw exception;\n });\n}\n","import baseTest from '@playwright/test';\n\nimport { expect } from './matchers';\nimport { setupErrorListener } from './errors';\n\nexport const test = baseTest.extend({\n page: async ({ page }, use) => {\n await setupErrorListener(page);\n await use(page);\n },\n});\n\ntest.use({ storageState: { cookies: [], origins: [] } });\n\nexport { expect };\n"],"names":["findByA11yText","scope","text","input","page","label","options","locator","press","targetSelector","findTarget","dialog","inDialog","comboboxSelect","labelOrSelector","value","id","see","selectorOrOptions","srOnly","baseOptions","timeout","expect","seeImage","alt","dontSee","disableErrorHandling","matchesUrl","glob","url","matchesRequest","request","method","interceptRequests","methodOrUrl","calls","onResponse","response","start","end","index","createModel","name","data","modelName","modelData","countModels","matchImageSnapshot","waitSync","baseExpect","received","expected","actual","result","sparqlEquals","normalizeSparql","setupErrorListener","error","message","errorToThrow","exception","test","baseTest","use"],"mappings":";;;;AAkBA,SAASA,EAAeC,GAAuBC,GAAuB;AAClE,SAAOD,EACF,UAAUC,GAAM,EAAE,OAAO,IAAO,EAChC,GAAGD,EAAM,QAAQ,gBAAgBC,CAAI,IAAI,CAAC,EAC1C,MAAA;AACT;AAEO,SAASC,EAAMC,GAAYC,GAAeC,IAAwB,CAAA,GAAa;AAClF,QAAMC,IAAUH,EAAK,WAAWC,GAAO,EAAE,OAAO,IAAM;AAEtD,SAAIC,EAAQ,cACDC,EAAQ,OAAO;AAAA,IAClB,KAAKH,EAAK,QA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E,cAAc,EAAE,SAAS,CAAA,GAAI,SAAS,CAAA,EAAC,GAAK;"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@aerogel/playwright",
3
+ "version": "0.1.2-next.172d94733294f11f2f2d6f15f09acf7ed6381bb3",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/aerogel-playwright.d.ts",
9
+ "default": "./dist/aerogel-playwright.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "src",
14
+ "dist"
15
+ ],
16
+ "license": "MIT",
17
+ "author": "Noel De Martin",
18
+ "repository": "github:NoelDeMartin/aerogel",
19
+ "peerDependencies": {
20
+ "@playwright/test": "^1.60.0"
21
+ },
22
+ "dependencies": {
23
+ "@noeldemartin/solid-utils": "next",
24
+ "playwright-solid": "next"
25
+ },
26
+ "devDependencies": {
27
+ "@arethetypeswrong/cli": "^0.18.3",
28
+ "@noeldemartin/scripts": "next",
29
+ "@playwright/test": "^1.60.0",
30
+ "@types/node": "^24.10.4",
31
+ "eslint": "^8.57.1",
32
+ "prettier-eslint-cli": "^8.0.1",
33
+ "publint": "^0.3.12",
34
+ "soukai-bis": "next",
35
+ "@aerogel/plugin-solid": "0.1.2"
36
+ },
37
+ "eslintConfig": {
38
+ "extends": [
39
+ "@noeldemartin/eslint-config-typescript"
40
+ ]
41
+ },
42
+ "prettier": {
43
+ "printWidth": 120
44
+ },
45
+ "scripts": {
46
+ "build": "vite build",
47
+ "lint": "noeldemartin-lint src",
48
+ "verify": "noeldemartin-verify"
49
+ }
50
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './lib';
2
+ export * from './solid';
3
+ export * from './setup';
@@ -0,0 +1,106 @@
1
+ import { expect } from '@playwright/test';
2
+ import type { Locator, Page } from '@playwright/test';
3
+
4
+ export type InputOptions = {
5
+ description?: string;
6
+ };
7
+
8
+ export type PressOptions = {
9
+ within?: Locator;
10
+ selector?: string;
11
+ };
12
+
13
+ export type SeeOptions = {
14
+ srOnly?: boolean;
15
+ timeout?: number;
16
+ within?: Locator;
17
+ };
18
+
19
+ function findByA11yText(scope: Page | Locator, text: string): Locator {
20
+ return scope
21
+ .getByText(text, { exact: false })
22
+ .or(scope.locator(`[aria-label="${text}"]`))
23
+ .first();
24
+ }
25
+
26
+ export function input(page: Page, label: string, options: InputOptions = {}): Locator {
27
+ const locator = page.getByLabel(label, { exact: true });
28
+
29
+ if (options.description) {
30
+ return locator.filter({
31
+ has: page.locator(`[aria-description="${options.description}"], [aria-describedby]`),
32
+ });
33
+ }
34
+
35
+ return locator;
36
+ }
37
+
38
+ export async function press(page: Page, label: string, options: PressOptions = {}): Promise<void> {
39
+ const targetSelector =
40
+ options.selector ?? 'button:visible, a:visible, label:visible, details:visible, [role="menuitem"]:visible';
41
+ const findTarget = (scope: Page | Locator) =>
42
+ scope
43
+ .locator(targetSelector)
44
+ .filter({ hasText: label })
45
+ .or(scope.locator(`[aria-label="${label}"]`))
46
+ .first();
47
+
48
+ if (options.within) {
49
+ await findTarget(options.within).click();
50
+
51
+ return;
52
+ }
53
+
54
+ const dialog = page.locator('[role="dialog"][data-state="open"]:not([aria-hidden="true"])').last();
55
+ const inDialog = findTarget(dialog);
56
+ const locator = (await inDialog.count()) > 0 ? inDialog : findTarget(page);
57
+
58
+ await locator.click();
59
+ }
60
+
61
+ export async function comboboxSelect(page: Page, labelOrSelector: string, value: string): Promise<void> {
62
+ await page.waitForTimeout(300);
63
+ const label = page.locator('label[for]').filter({ hasText: labelOrSelector }).first();
64
+ const id = await label.getAttribute('for');
65
+
66
+ await page.locator(id ? `#${id}` : labelOrSelector).click();
67
+ await page.waitForTimeout(300);
68
+ await page.locator('*[role="option"]').filter({ hasText: value }).first().click();
69
+ }
70
+
71
+ export async function see(
72
+ page: Page,
73
+ text: string,
74
+ selectorOrOptions: string | SeeOptions = {},
75
+ options: SeeOptions = {},
76
+ ): Promise<Locator> {
77
+ const srOnly = typeof selectorOrOptions === 'string' ? options.srOnly : selectorOrOptions.srOnly;
78
+ const baseOptions = typeof selectorOrOptions === 'string' ? options : selectorOrOptions;
79
+ const timeout = baseOptions.timeout;
80
+ const scope = baseOptions.within ?? page;
81
+ const locator =
82
+ typeof selectorOrOptions === 'string'
83
+ ? scope.locator(selectorOrOptions).filter({ hasText: text }).first()
84
+ : findByA11yText(scope, text);
85
+
86
+ if (srOnly) {
87
+ await expect(locator).toBeAttached({ timeout });
88
+ } else {
89
+ await expect(locator).toBeVisible({ timeout });
90
+ }
91
+
92
+ return locator;
93
+ }
94
+
95
+ export async function seeImage(page: Page, alt: string): Promise<void> {
96
+ const locator = page.locator(`img[alt="${alt}"]`).first();
97
+
98
+ await locator.scrollIntoViewIfNeeded();
99
+ await expect(locator).toBeVisible();
100
+ }
101
+
102
+ export async function dontSee(page: Page, text: string, options: SeeOptions = {}): Promise<void> {
103
+ const scope = options.within ?? page;
104
+
105
+ await expect(findByA11yText(scope, text)).not.toBeVisible({ timeout: options.timeout });
106
+ }
@@ -0,0 +1,7 @@
1
+ import type { Page } from '@playwright/test';
2
+
3
+ export async function disableErrorHandling(page: Page): Promise<void> {
4
+ await page.addInitScript(() => {
5
+ window.__aerogelDisableErrorHandling__ = true;
6
+ });
7
+ }
@@ -0,0 +1,6 @@
1
+ export * from './a11y';
2
+ export * from './errors';
3
+ export * from './intercept';
4
+ export * from './models';
5
+ export * from './snapshots';
6
+ export * from './sync';
@@ -0,0 +1,71 @@
1
+ import type { Page, Request, Response } from '@playwright/test';
2
+
3
+ export type InterceptedCall = {
4
+ url: string;
5
+ method: string;
6
+ body: string | null;
7
+ status: number;
8
+ request: Request;
9
+ response: Response;
10
+ };
11
+
12
+ export type InterceptHandle = {
13
+ readonly all: InterceptedCall[];
14
+ slice(start: number, end: number): InterceptedCall[];
15
+ nth(index: number): InterceptedCall | undefined;
16
+ };
17
+
18
+ function matchesUrl(glob: string, url: string): boolean {
19
+ if (glob.endsWith('*')) {
20
+ return url.startsWith(glob.slice(0, -1));
21
+ }
22
+
23
+ return url === glob;
24
+ }
25
+
26
+ function matchesRequest(request: Request, glob: string, method?: string): boolean {
27
+ if (method && request.method().toUpperCase() !== method.toUpperCase()) {
28
+ return false;
29
+ }
30
+
31
+ return matchesUrl(glob, request.url());
32
+ }
33
+
34
+ export function interceptRequests(page: Page, url: string): InterceptHandle;
35
+ export function interceptRequests(page: Page, method: string, url: string): InterceptHandle;
36
+ export function interceptRequests(page: Page, methodOrUrl: string, url?: string): InterceptHandle {
37
+ const method = url === undefined ? undefined : methodOrUrl;
38
+ const glob = url ?? methodOrUrl;
39
+ const calls: InterceptedCall[] = [];
40
+
41
+ const onResponse = (response: Response) => {
42
+ const request = response.request();
43
+
44
+ if (!matchesRequest(request, glob, method)) {
45
+ return;
46
+ }
47
+
48
+ calls.push({
49
+ url: request.url(),
50
+ method: request.method(),
51
+ body: request.postData(),
52
+ status: response.status(),
53
+ request,
54
+ response,
55
+ });
56
+ };
57
+
58
+ page.on('response', onResponse);
59
+
60
+ return {
61
+ get all() {
62
+ return calls;
63
+ },
64
+ slice(start: number, end: number) {
65
+ return calls.slice(start, end);
66
+ },
67
+ nth(index: number) {
68
+ return calls[index - 1];
69
+ },
70
+ };
71
+ }
@@ -0,0 +1,31 @@
1
+ import type { Page } from '@playwright/test';
2
+ import type { GetModelInput, ModelsRegistry } from 'soukai-bis';
3
+
4
+ export async function createModel<T extends keyof ModelsRegistry>(
5
+ page: Page,
6
+ name: T,
7
+ data: GetModelInput<ModelsRegistry[T]>,
8
+ ): Promise<void> {
9
+ await page.evaluate(
10
+ async ({ modelName, modelData }) => {
11
+ if (!window.testingRuntime) {
12
+ throw new Error('Testing runtime is not available');
13
+ }
14
+
15
+ await window.testingRuntime.model(modelName as string).create(modelData);
16
+ },
17
+ { modelName: name, modelData: data },
18
+ );
19
+ }
20
+
21
+ export async function countModels<T extends keyof ModelsRegistry>(page: Page, name: T): Promise<number> {
22
+ return page.evaluate(async (modelName) => {
23
+ if (!window.testingRuntime) {
24
+ throw new Error('Testing runtime is not available');
25
+ }
26
+
27
+ const instances = await window.testingRuntime.model(modelName as string).all();
28
+
29
+ return instances.length;
30
+ }, name);
31
+ }
@@ -0,0 +1,14 @@
1
+ import { expect } from '@playwright/test';
2
+ import type { Page } from '@playwright/test';
3
+
4
+ export async function matchImageSnapshot(page: Page, name?: string): Promise<void> {
5
+ if (!process.env.SNAPSHOTS && !process.env.PLAYWRIGHT_SNAPSHOTS) {
6
+ return;
7
+ }
8
+
9
+ if (name) {
10
+ await expect(page).toHaveScreenshot(`${name}.png`, { animations: 'disabled' });
11
+ } else {
12
+ await expect(page).toHaveScreenshot({ animations: 'disabled' });
13
+ }
14
+ }
@@ -0,0 +1,9 @@
1
+ import type { Page } from '@playwright/test';
2
+
3
+ import { dontSee, see } from './a11y';
4
+
5
+ export async function waitSync(page: Page): Promise<void> {
6
+ await see(page, 'Synchronization in progress');
7
+ await dontSee(page, 'Synchronization in progress', { timeout: 10000 });
8
+ await page.waitForTimeout(100);
9
+ }
@@ -0,0 +1,27 @@
1
+ import type { Page } from '@playwright/test';
2
+
3
+ export async function setupErrorListener(page: Page): Promise<void> {
4
+ await page.addInitScript(() => {
5
+ window.__aerogelEvents__ = {
6
+ error: ({ error, message }: { error: unknown; message?: string }) => {
7
+ if (window.__aerogelDisableErrorHandling__) {
8
+ return;
9
+ }
10
+
11
+ const errorToThrow = error instanceof Error ? error : new Error(message || String(error));
12
+
13
+ setTimeout(() => {
14
+ throw errorToThrow;
15
+ });
16
+ },
17
+ };
18
+ });
19
+
20
+ page.on('pageerror', (exception) => {
21
+ if (exception.message.includes('ResizeObserver loop completed with undelivered notifications.')) {
22
+ return;
23
+ }
24
+
25
+ throw exception;
26
+ });
27
+ }
@@ -0,0 +1,15 @@
1
+ import baseTest from '@playwright/test';
2
+
3
+ import { expect } from './matchers';
4
+ import { setupErrorListener } from './errors';
5
+
6
+ export const test = baseTest.extend({
7
+ page: async ({ page }, use) => {
8
+ await setupErrorListener(page);
9
+ await use(page);
10
+ },
11
+ });
12
+
13
+ test.use({ storageState: { cookies: [], origins: [] } });
14
+
15
+ export { expect };
@@ -0,0 +1,21 @@
1
+ import { normalizeSparql } from '@noeldemartin/solid-utils';
2
+ import { sparqlEquals } from '@noeldemartin/solid-utils/testing';
3
+ import { expect as baseExpect } from '@playwright/test';
4
+
5
+ export const expect = baseExpect.extend({
6
+ toEqualSparql(received: unknown, expected: string) {
7
+ const actual = String(received ?? '');
8
+ const result = sparqlEquals(expected, actual);
9
+
10
+ return {
11
+ pass: result.success,
12
+ message: () => {
13
+ if (result.success) {
14
+ return 'Expected SPARQL not to match.';
15
+ }
16
+
17
+ return [result.message, this.utils.diff(normalizeSparql(expected), normalizeSparql(actual))].join('\n');
18
+ },
19
+ };
20
+ },
21
+ });
@@ -0,0 +1 @@
1
+ export * from 'playwright-solid';
@@ -0,0 +1,7 @@
1
+ export {};
2
+
3
+ declare global {
4
+ interface Window {
5
+ __aerogelDisableErrorHandling__?: boolean;
6
+ }
7
+ }
@@ -0,0 +1,10 @@
1
+ export {};
2
+
3
+ declare global {
4
+ namespace PlaywrightTest {
5
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ interface Matchers<R, T> {
7
+ toEqualSparql(expected: string): R;
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="@aerogel/plugin-solid" />