@aerogel/playwright 0.1.2-next.b337e50bd4974df4723468abf6bea181f182e2f6

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,56 @@
1
+ import { expect } from '@playwright/test';
2
+ import { GetModelInput } from 'soukai-bis';
3
+ import { Locator } from '@playwright/test';
4
+ import { ModelsRegistry } from 'soukai-bis';
5
+ import { Page } from '@playwright/test';
6
+ import { PlaywrightTestArgs } from '@playwright/test';
7
+ import { PlaywrightTestOptions } from '@playwright/test';
8
+ import { PlaywrightWorkerArgs } from '@playwright/test';
9
+ import { PlaywrightWorkerOptions } from '@playwright/test';
10
+ import { TestType } from '@playwright/test';
11
+
12
+ export declare function a11yGet(page: Page, text: string): Locator;
13
+
14
+ export declare function ariaInput(page: Page, label: string, options?: AriaInputOptions): Locator;
15
+
16
+ export declare type AriaInputOptions = {
17
+ description?: string;
18
+ };
19
+
20
+ export declare function ariaLabel(page: Page, label: string): Locator;
21
+
22
+ export declare function comboboxSelect(page: Page, labelOrSelector: string, value: string): Promise<void>;
23
+
24
+ export declare function count<T extends keyof ModelsRegistry>(page: Page, name: T): Promise<number>;
25
+
26
+ export declare function create<T extends keyof ModelsRegistry>(page: Page, name: T, data: GetModelInput<ModelsRegistry[T]>): Promise<void>;
27
+
28
+ export declare function disableErrorHandling(page: Page): Promise<void>;
29
+
30
+ export declare function dontSee(page: Page, text: string, options?: {
31
+ timeout?: number;
32
+ }): Promise<void>;
33
+
34
+ export { expect }
35
+
36
+ export declare function matchImageSnapshot(page: Page, name?: string): Promise<void>;
37
+
38
+ export declare function press(page: Page, label: string, selector?: string): Promise<void>;
39
+
40
+ export declare function see(page: Page, text: string, selectorOrOptions?: string | SeeOptions, options?: SeeOptions): Promise<Locator>;
41
+
42
+ export declare function seeImage(page: Page, alt: string): Promise<void>;
43
+
44
+ export declare type SeeOptions = {
45
+ srOnly?: boolean;
46
+ timeout?: number;
47
+ };
48
+
49
+ export declare const test: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
50
+
51
+ export declare function waitSync(page: Page): Promise<void>;
52
+
53
+
54
+ export * from "playwright-solid";
55
+
56
+ export { }
@@ -0,0 +1,104 @@
1
+ import { expect as n, test as u } from "@playwright/test";
2
+ import { expect as p } from "@playwright/test";
3
+ export * from "playwright-solid";
4
+ function l(t, i) {
5
+ return t.getByText(i, { exact: !1 }).or(t.locator(`[aria-label="${i}"]`)).first();
6
+ }
7
+ function y(t, i) {
8
+ return t.locator(`[aria-label="${i}"]`);
9
+ }
10
+ function g(t, i, e = {}) {
11
+ const a = t.getByLabel(i, { exact: !0 });
12
+ return e.description ? a.filter({
13
+ has: t.locator(`[aria-description="${e.description}"], [aria-describedby]`)
14
+ }) : a;
15
+ }
16
+ async function w(t, i, e) {
17
+ await n(l(t, i)).not.toBeVisible({ timeout: e == null ? void 0 : e.timeout });
18
+ }
19
+ async function h(t, i, e) {
20
+ const a = e ?? 'button:visible, a:visible, label:visible, details:visible, [role="menuitem"]:visible', r = t.locator('[role="dialog"][data-state="open"]:not([aria-hidden="true"])').last().locator(a).filter({ hasText: i });
21
+ await (await r.count() > 0 ? r.first() : t.locator(a).filter({ hasText: i }).first()).click();
22
+ }
23
+ async function f(t, i, e = {}, a = {}) {
24
+ const o = typeof e == "string" ? a.srOnly : e.srOnly, s = (typeof e == "string" ? a : e).timeout, c = typeof e == "string" ? t.locator(e).filter({ hasText: i }).first() : l(t, i);
25
+ return o ? await n(c).toBeAttached({ timeout: s }) : await n(c).toBeVisible({ timeout: s }), c;
26
+ }
27
+ async function S(t, i) {
28
+ const e = t.locator(`img[alt="${i}"]`).first();
29
+ await e.scrollIntoViewIfNeeded(), await n(e).toBeVisible();
30
+ }
31
+ async function T(t, i, e) {
32
+ await t.waitForTimeout(300);
33
+ const o = await t.locator("label[for]").filter({ hasText: i }).first().getAttribute("for");
34
+ await t.locator(o ? `#${o}` : i).click(), await t.waitForTimeout(300), await t.locator('*[role="option"]').filter({ hasText: e }).first().click();
35
+ }
36
+ async function v(t) {
37
+ await t.addInitScript(() => {
38
+ window.__aerogelDisableErrorHandling__ = !0;
39
+ });
40
+ }
41
+ async function _(t, i, e) {
42
+ await t.evaluate(
43
+ async ({ modelName: a, modelData: o }) => {
44
+ if (!window.testingRuntime)
45
+ throw new Error("Testing runtime is not available");
46
+ await window.testingRuntime.model(a).create(o);
47
+ },
48
+ { modelName: i, modelData: e }
49
+ );
50
+ }
51
+ async function x(t, i) {
52
+ return t.evaluate(async (e) => {
53
+ if (!window.testingRuntime)
54
+ throw new Error("Testing runtime is not available");
55
+ return (await window.testingRuntime.model(e).all()).length;
56
+ }, i);
57
+ }
58
+ async function E(t, i) {
59
+ !process.env.SNAPSHOTS && !process.env.PLAYWRIGHT_SNAPSHOTS || (i ? await n(t).toHaveScreenshot(`${i}.png`, { animations: "disabled" }) : await n(t).toHaveScreenshot({ animations: "disabled" }));
60
+ }
61
+ async function H(t) {
62
+ await f(t, "Synchronization in progress"), await w(t, "Synchronization in progress", { timeout: 1e4 }), await t.waitForTimeout(100);
63
+ }
64
+ async function d(t) {
65
+ await t.addInitScript(() => {
66
+ window.__aerogelEvents__ = {
67
+ error: ({ error: i, message: e }) => {
68
+ if (window.__aerogelDisableErrorHandling__)
69
+ return;
70
+ const a = i instanceof Error ? i : new Error(e || String(i));
71
+ setTimeout(() => {
72
+ throw a;
73
+ });
74
+ }
75
+ };
76
+ }), t.on("pageerror", (i) => {
77
+ if (!i.message.includes("ResizeObserver loop completed with undelivered notifications."))
78
+ throw i;
79
+ });
80
+ }
81
+ const m = u.extend({
82
+ page: async ({ page: t }, i) => {
83
+ await d(t), await i(t);
84
+ }
85
+ });
86
+ m.use({ storageState: { cookies: [], origins: [] } });
87
+ export {
88
+ l as a11yGet,
89
+ g as ariaInput,
90
+ y as ariaLabel,
91
+ T as comboboxSelect,
92
+ x as count,
93
+ _ as create,
94
+ v as disableErrorHandling,
95
+ w as dontSee,
96
+ p as expect,
97
+ E as matchImageSnapshot,
98
+ h as press,
99
+ f as see,
100
+ S as seeImage,
101
+ m as test,
102
+ H as waitSync
103
+ };
104
+ //# 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/models.ts","../src/lib/snapshots.ts","../src/lib/sync.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 SeeOptions = {\n srOnly?: boolean;\n timeout?: number;\n};\n\nexport type AriaInputOptions = {\n description?: string;\n};\n\nexport function a11yGet(page: Page, text: string): Locator {\n return page\n .getByText(text, { exact: false })\n .or(page.locator(`[aria-label=\"${text}\"]`))\n .first();\n}\n\nexport function ariaLabel(page: Page, label: string): Locator {\n return page.locator(`[aria-label=\"${label}\"]`);\n}\n\nexport function ariaInput(page: Page, label: string, options: AriaInputOptions = {}): 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 dontSee(page: Page, text: string, options?: { timeout?: number }): Promise<void> {\n await expect(a11yGet(page, text)).not.toBeVisible({ timeout: options?.timeout });\n}\n\nexport async function press(page: Page, label: string, selector?: string): Promise<void> {\n const targetSelector =\n selector ?? 'button:visible, a:visible, label:visible, details:visible, [role=\"menuitem\"]:visible';\n const dialog = page.locator('[role=\"dialog\"][data-state=\"open\"]:not([aria-hidden=\"true\"])').last();\n const inDialog = dialog.locator(targetSelector).filter({ hasText: label });\n const locator =\n (await inDialog.count()) > 0\n ? inDialog.first()\n : page.locator(targetSelector).filter({ hasText: label }).first();\n\n await locator.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 locator =\n typeof selectorOrOptions === 'string'\n ? page.locator(selectorOrOptions).filter({ hasText: text }).first()\n : a11yGet(page, 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 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","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 } from '@playwright/test';\nimport type { GetModelInput, ModelsRegistry } from 'soukai-bis';\n\nexport async function create<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 count<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 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 { test as base, expect } from '@playwright/test';\n\nimport { setupErrorListener } from './errors';\n\nexport const test = base.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":["a11yGet","page","text","ariaLabel","label","ariaInput","options","locator","dontSee","expect","press","selector","targetSelector","inDialog","see","selectorOrOptions","srOnly","timeout","seeImage","alt","comboboxSelect","labelOrSelector","value","id","disableErrorHandling","create","name","data","modelName","modelData","count","matchImageSnapshot","waitSync","setupErrorListener","error","message","errorToThrow","exception","test","base","use"],"mappings":";;;AAYO,SAASA,EAAQC,GAAYC,GAAuB;AACvD,SAAOD,EACF,UAAUC,GAAM,EAAE,OAAO,IAAO,EAChC,GAAGD,EAAK,QAAQ,gBAAgBC,CAAI,IAAI,CAAC,EACzC,MAAA;AACT;AAEO,SAASC,EAAUF,GAAYG,GAAwB;AAC1D,SAAOH,EAAK,QAAQ,gBAAgBG,CAAK,IAAI;AACjD;AAEO,SAASC,EAAUJ,GAAYG,GAAeE,IAA4B,CAAA,GAAa;AAC1F,QAAMC,IAAUN,EAAK,WAAWG,GAAO,EAAE,OAAO,IAAM;AAEtD,SAAIE,EAAQ,cACDC,EAAQ,OAAO;AAAA,IAClB,KAAKN,EAAK,QAAQ,sBAAsBK,EAAQ,WAAW,wBAAwB;AAAA,EAAA,CACtF,IAGEC;AACX;AAEA,eAAsBC,EAAQP,GAAYC,GAAcI,GAA+C;AACnG,QAAMG,EAAOT,EAAQC,GAAMC,CAAI,CAAC,EAAE,IAAI,YAAY,EAAE,SAASI,KA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E,QAAMA,EAAK,cAAc,MAAM;AAC3B,WAAO,oBAAoB;AAAA,MACvB,OAAO,CAAC,EAAE,OAAAiC,GAAO,SAAAC,QAAoD;AACjE,YAAI,OAAO;AACP;AAGJ,cAAMC,IAAeF,aAAiB,QAAQA,IAAQ,IAAI,MAAMC,KAAW,OAAOD,CAAK,CAAC;AAExF,mBAAW,MAAM;AACb,gBAAME;AAAA,QACV,CAAC;AAAA,MACL;AAAA,IAAA;AAAA,EAER,CAAC,GAEDnC,EAAK,GAAG,aAAa,CAACoC,MAAc;AAChC,QAAI,CAAAA,EAAU,QAAQ,SAAS,+DAA+D;AAI9F,YAAMA;AAAA,EACV,CAAC;AACL;ACtBO,MAAMC,IAAOC,EAAK,OAAO;AAAA,EAC5B,MAAM,OAAO,EAAE,MAAAtC,EAAA,GAAQuC,MAAQ;AAC3B,UAAMP,EAAmBhC,CAAI,GAC7B,MAAMuC,EAAIvC,CAAI;AAAA,EAClB;AACJ,CAAC;AAEDqC,EAAK,IAAI,EAAE,cAAc,EAAE,SAAS,CAAA,GAAI,SAAS,CAAA,EAAC,GAAK;"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@aerogel/playwright",
3
+ "version": "0.1.2-next.b337e50bd4974df4723468abf6bea181f182e2f6",
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": "*"
21
+ },
22
+ "dependencies": {
23
+ "playwright-solid": "next"
24
+ },
25
+ "devDependencies": {
26
+ "@arethetypeswrong/cli": "^0.18.3",
27
+ "@noeldemartin/scripts": "next",
28
+ "@playwright/test": "^1.59.0",
29
+ "@types/node": "^24.10.4",
30
+ "eslint": "^8.57.1",
31
+ "prettier-eslint-cli": "^8.0.1",
32
+ "publint": "^0.3.12",
33
+ "soukai-bis": "next",
34
+ "@aerogel/plugin-solid": "0.1.2"
35
+ },
36
+ "eslintConfig": {
37
+ "extends": [
38
+ "@noeldemartin/eslint-config-typescript"
39
+ ]
40
+ },
41
+ "prettier": {
42
+ "printWidth": 120
43
+ },
44
+ "scripts": {
45
+ "build": "vite build",
46
+ "lint": "noeldemartin-lint src",
47
+ "verify": "noeldemartin-verify"
48
+ }
49
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './lib';
2
+ export * from './solid';
3
+ export * from './setup';
@@ -0,0 +1,91 @@
1
+ import { expect } from '@playwright/test';
2
+ import type { Locator, Page } from '@playwright/test';
3
+
4
+ export type SeeOptions = {
5
+ srOnly?: boolean;
6
+ timeout?: number;
7
+ };
8
+
9
+ export type AriaInputOptions = {
10
+ description?: string;
11
+ };
12
+
13
+ export function a11yGet(page: Page, text: string): Locator {
14
+ return page
15
+ .getByText(text, { exact: false })
16
+ .or(page.locator(`[aria-label="${text}"]`))
17
+ .first();
18
+ }
19
+
20
+ export function ariaLabel(page: Page, label: string): Locator {
21
+ return page.locator(`[aria-label="${label}"]`);
22
+ }
23
+
24
+ export function ariaInput(page: Page, label: string, options: AriaInputOptions = {}): Locator {
25
+ const locator = page.getByLabel(label, { exact: true });
26
+
27
+ if (options.description) {
28
+ return locator.filter({
29
+ has: page.locator(`[aria-description="${options.description}"], [aria-describedby]`),
30
+ });
31
+ }
32
+
33
+ return locator;
34
+ }
35
+
36
+ export async function dontSee(page: Page, text: string, options?: { timeout?: number }): Promise<void> {
37
+ await expect(a11yGet(page, text)).not.toBeVisible({ timeout: options?.timeout });
38
+ }
39
+
40
+ export async function press(page: Page, label: string, selector?: string): Promise<void> {
41
+ const targetSelector =
42
+ selector ?? 'button:visible, a:visible, label:visible, details:visible, [role="menuitem"]:visible';
43
+ const dialog = page.locator('[role="dialog"][data-state="open"]:not([aria-hidden="true"])').last();
44
+ const inDialog = dialog.locator(targetSelector).filter({ hasText: label });
45
+ const locator =
46
+ (await inDialog.count()) > 0
47
+ ? inDialog.first()
48
+ : page.locator(targetSelector).filter({ hasText: label }).first();
49
+
50
+ await locator.click();
51
+ }
52
+
53
+ export async function see(
54
+ page: Page,
55
+ text: string,
56
+ selectorOrOptions: string | SeeOptions = {},
57
+ options: SeeOptions = {},
58
+ ): Promise<Locator> {
59
+ const srOnly = typeof selectorOrOptions === 'string' ? options.srOnly : selectorOrOptions.srOnly;
60
+ const baseOptions = typeof selectorOrOptions === 'string' ? options : selectorOrOptions;
61
+ const timeout = baseOptions.timeout;
62
+ const locator =
63
+ typeof selectorOrOptions === 'string'
64
+ ? page.locator(selectorOrOptions).filter({ hasText: text }).first()
65
+ : a11yGet(page, text);
66
+
67
+ if (srOnly) {
68
+ await expect(locator).toBeAttached({ timeout });
69
+ } else {
70
+ await expect(locator).toBeVisible({ timeout });
71
+ }
72
+
73
+ return locator;
74
+ }
75
+
76
+ export async function seeImage(page: Page, alt: string): Promise<void> {
77
+ const locator = page.locator(`img[alt="${alt}"]`).first();
78
+
79
+ await locator.scrollIntoViewIfNeeded();
80
+ await expect(locator).toBeVisible();
81
+ }
82
+
83
+ export async function comboboxSelect(page: Page, labelOrSelector: string, value: string): Promise<void> {
84
+ await page.waitForTimeout(300);
85
+ const label = page.locator('label[for]').filter({ hasText: labelOrSelector }).first();
86
+ const id = await label.getAttribute('for');
87
+
88
+ await page.locator(id ? `#${id}` : labelOrSelector).click();
89
+ await page.waitForTimeout(300);
90
+ await page.locator('*[role="option"]').filter({ hasText: value }).first().click();
91
+ }
@@ -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,5 @@
1
+ export * from './a11y';
2
+ export * from './errors';
3
+ export * from './models';
4
+ export * from './snapshots';
5
+ export * from './sync';
@@ -0,0 +1,31 @@
1
+ import type { Page } from '@playwright/test';
2
+ import type { GetModelInput, ModelsRegistry } from 'soukai-bis';
3
+
4
+ export async function create<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 count<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,14 @@
1
+ import { test as base, expect } from '@playwright/test';
2
+
3
+ import { setupErrorListener } from './errors';
4
+
5
+ export const test = base.extend({
6
+ page: async ({ page }, use) => {
7
+ await setupErrorListener(page);
8
+ await use(page);
9
+ },
10
+ });
11
+
12
+ test.use({ storageState: { cookies: [], origins: [] } });
13
+
14
+ export { expect };
@@ -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 @@
1
+ /// <reference types="@aerogel/plugin-solid" />