@atomicsmash/test-utils 3.0.0 → 4.0.0-beta.1
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/dist/index.d.ts +17 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +77 -38
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type { Page,
|
|
1
|
+
import type { Page, Browser, PlaywrightTestConfig, PlaywrightTestArgs, PlaywrightTestOptions } from "@playwright/test";
|
|
2
2
|
import type { SerialFrameSelector } from "axe-core";
|
|
3
|
+
export type WordPressUserRole = "unauthenticated" | "subscriber" | "contributor" | "author" | "editor" | "admin" | "super-admin";
|
|
4
|
+
export type WooCommerceUserRole = "customer" | "shop-manager";
|
|
5
|
+
export type UserRole = WordPressUserRole | WooCommerceUserRole;
|
|
3
6
|
export type PageList = {
|
|
4
7
|
url: string;
|
|
5
8
|
name: string;
|
|
6
9
|
slug?: string;
|
|
7
|
-
|
|
10
|
+
minimumUserPrivilege?: UserRole;
|
|
8
11
|
}[];
|
|
12
|
+
export declare function doesRoleHaveHighEnoughPermissions(userRole: WordPressUserRole | WooCommerceUserRole, minimumRolePermission: WordPressUserRole | WooCommerceUserRole): boolean;
|
|
9
13
|
export type AuthenticatePageFunction = ({ page }: {
|
|
10
14
|
page: Page;
|
|
11
15
|
}, use: (r: Page) => Promise<void>) => Promise<void>;
|
|
@@ -27,14 +31,16 @@ export declare const playwrightConfig: {
|
|
|
27
31
|
snapshotDir: string;
|
|
28
32
|
snapshotPathTemplate: string;
|
|
29
33
|
};
|
|
30
|
-
export declare const
|
|
31
|
-
authenticatedPage: Page;
|
|
32
|
-
context: BrowserContext;
|
|
33
|
-
}, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & {
|
|
34
|
+
export declare const lighthouseTest: import("playwright/test").TestType<PlaywrightTestArgs & PlaywrightTestOptions, import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions & {
|
|
34
35
|
port: number;
|
|
36
|
+
browser: Browser;
|
|
35
37
|
}>;
|
|
36
|
-
type LighthouseTestFunction = Parameters<
|
|
37
|
-
export declare const doLighthouseTest: (pageToTest:
|
|
38
|
+
type LighthouseTestFunction = Parameters<typeof lighthouseTest>[2];
|
|
39
|
+
export declare const doLighthouseTest: (pageToTest: {
|
|
40
|
+
url: string | (() => string | Promise<string>);
|
|
41
|
+
name: string;
|
|
42
|
+
slug?: string;
|
|
43
|
+
}, type: "desktop" | "mobile", disableAuditLogs?: boolean) => LighthouseTestFunction;
|
|
38
44
|
export declare function checkAccessibility(page: Page, { includes, excludes, }?: {
|
|
39
45
|
includes?: SerialFrameSelector[];
|
|
40
46
|
excludes?: SerialFrameSelector[];
|
|
@@ -42,10 +48,10 @@ export declare function checkAccessibility(page: Page, { includes, excludes, }?:
|
|
|
42
48
|
export declare const checkPrivilegedPages: (pagesToTest: PageList) => ({ page }: {
|
|
43
49
|
page: Page;
|
|
44
50
|
}) => Promise<void>;
|
|
45
|
-
export declare const checkForLoremIpsum: (pagesToTest: PageList) => ({
|
|
46
|
-
|
|
51
|
+
export declare const checkForLoremIpsum: (pagesToTest: PageList) => ({ page }: {
|
|
52
|
+
page: Page;
|
|
47
53
|
}) => Promise<void>;
|
|
48
54
|
export declare function slugify(stringToSlugify: string): string;
|
|
49
|
-
export declare function generateProjectsForAllBrowsers(baseProject: NonNullable<PlaywrightTestConfig["projects"]>[number]): import("
|
|
55
|
+
export declare function generateProjectsForAllBrowsers(baseProject: NonNullable<PlaywrightTestConfig["projects"]>[number]): import("playwright/test").Project<PlaywrightTestOptions & {}, import("playwright/test").PlaywrightWorkerOptions & {}>[];
|
|
50
56
|
export {};
|
|
51
57
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src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AC,CAAC,CAAC,CAAC,CAAC;AAEnE,eAAO,MAAM,gBAAgB,EAAE,CAC9B,UAAU,EAAE;IACX,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACd,EACD,IAAI,EAAE,SAAS,GAAG,QAAQ,EAC1B,gBAAgB,CAAC,EAAE,OAAO,KACtB,sBAkCH,CAAC;AAEH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,IAAI,EACV,EACC,QAAQ,EACR,QAAQ,GACR,GAAE;IACF,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAC;CAC5B,iBAiCN;AAED,eAAO,MAAM,oBAAoB,gBAClB,QAAQ,gBACL;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,kBAO9B,CAAC;AACH,eAAO,MAAM,kBAAkB,gBAChB,QAAQ,gBACL;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,kBAO9B,CAAC;AAEH,wBAAgB,OAAO,CAAC,eAAe,EAAE,MAAM,UAU9C;AAED,wBAAgB,8BAA8B,CAC7C,WAAW,EAAE,WAAW,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,2HAqDlE"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import os from "node:os";
|
|
2
|
-
import path from "node:path";
|
|
3
1
|
import { AxeBuilder } from "@axe-core/playwright";
|
|
4
2
|
import { test as base, chromium, devices } from "@playwright/test";
|
|
5
3
|
import getPort from "get-port";
|
|
@@ -7,6 +5,52 @@ import lighthouseDesktopConfig from "lighthouse/core/config/lr-desktop-config.js
|
|
|
7
5
|
import lighthouseMobileConfig from "lighthouse/core/config/lr-mobile-config.js";
|
|
8
6
|
import { playAudit } from "playwright-lighthouse";
|
|
9
7
|
const { expect } = base;
|
|
8
|
+
export function doesRoleHaveHighEnoughPermissions(userRole, minimumRolePermission) {
|
|
9
|
+
if (userRole === minimumRolePermission) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
switch (userRole) {
|
|
13
|
+
case "super-admin":
|
|
14
|
+
return true;
|
|
15
|
+
case "admin":
|
|
16
|
+
return minimumRolePermission !== "super-admin";
|
|
17
|
+
case "shop-manager":
|
|
18
|
+
return !["super-admin", "admin"].includes(minimumRolePermission);
|
|
19
|
+
case "editor":
|
|
20
|
+
return !["super-admin", "admin", "shop-manager"].includes(minimumRolePermission);
|
|
21
|
+
case "author":
|
|
22
|
+
return !["super-admin", "admin", "shop-manager", "editor"].includes(minimumRolePermission);
|
|
23
|
+
case "contributor":
|
|
24
|
+
return ![
|
|
25
|
+
"super-admin",
|
|
26
|
+
"admin",
|
|
27
|
+
"shop-manager",
|
|
28
|
+
"editor",
|
|
29
|
+
"author",
|
|
30
|
+
].includes(minimumRolePermission);
|
|
31
|
+
case "customer":
|
|
32
|
+
return ![
|
|
33
|
+
"super-admin",
|
|
34
|
+
"admin",
|
|
35
|
+
"shop-manager",
|
|
36
|
+
"editor",
|
|
37
|
+
"author",
|
|
38
|
+
"contributor",
|
|
39
|
+
].includes(minimumRolePermission);
|
|
40
|
+
case "subscriber":
|
|
41
|
+
return ![
|
|
42
|
+
"super-admin",
|
|
43
|
+
"admin",
|
|
44
|
+
"shop-manager",
|
|
45
|
+
"editor",
|
|
46
|
+
"author",
|
|
47
|
+
"contributor",
|
|
48
|
+
"customer",
|
|
49
|
+
].includes(minimumRolePermission);
|
|
50
|
+
case "unauthenticated":
|
|
51
|
+
return minimumRolePermission === "unauthenticated";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
10
54
|
export const playwrightConfig = {
|
|
11
55
|
testDir: "./tests/e2e",
|
|
12
56
|
timeout: 30 * 1000,
|
|
@@ -25,44 +69,39 @@ export const playwrightConfig = {
|
|
|
25
69
|
snapshotDir: "./screenshots",
|
|
26
70
|
snapshotPathTemplate: "{snapshotDir}/{platform}/{testFileName}-snapshots/{arg}{ext}",
|
|
27
71
|
};
|
|
28
|
-
export const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return lighthouseTest;
|
|
53
|
-
};
|
|
54
|
-
export const doLighthouseTest = (pageToTest, type, disableAuditLogs = false) => async function ({ port, authenticatedPage }) {
|
|
55
|
-
await authenticatedPage.goto(pageToTest.url);
|
|
72
|
+
export const lighthouseTest = base.extend({
|
|
73
|
+
port: [
|
|
74
|
+
// eslint-disable-next-line no-empty-pattern -- destructure pattern is required by playwright
|
|
75
|
+
async ({}, use) => {
|
|
76
|
+
// Assign a unique port for each playwright worker to support parallel tests
|
|
77
|
+
const port = await getPort();
|
|
78
|
+
await use(port);
|
|
79
|
+
},
|
|
80
|
+
{ scope: "worker" },
|
|
81
|
+
],
|
|
82
|
+
browser: [
|
|
83
|
+
async ({ port }, use) => {
|
|
84
|
+
const browser = await chromium.launch({
|
|
85
|
+
args: [`--remote-debugging-port=${port}`],
|
|
86
|
+
});
|
|
87
|
+
await use(browser);
|
|
88
|
+
},
|
|
89
|
+
{ scope: "worker" },
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
export const doLighthouseTest = (pageToTest, type, disableAuditLogs = false) => async function ({ page, port }) {
|
|
93
|
+
await page.goto(typeof pageToTest.url === "string"
|
|
94
|
+
? pageToTest.url
|
|
95
|
+
: await pageToTest.url());
|
|
56
96
|
await playAudit({
|
|
57
|
-
|
|
58
|
-
|
|
97
|
+
page,
|
|
98
|
+
port,
|
|
59
99
|
thresholds: {
|
|
60
100
|
performance: 85,
|
|
61
101
|
accessibility: 85,
|
|
62
102
|
"best-practices": 85,
|
|
63
103
|
seo: 85,
|
|
64
104
|
},
|
|
65
|
-
port: port,
|
|
66
105
|
reports: {
|
|
67
106
|
formats: {
|
|
68
107
|
html: true,
|
|
@@ -76,7 +115,7 @@ export const doLighthouseTest = (pageToTest, type, disableAuditLogs = false) =>
|
|
|
76
115
|
ignoreError: true,
|
|
77
116
|
disableLogs: disableAuditLogs,
|
|
78
117
|
});
|
|
79
|
-
await
|
|
118
|
+
await page.goto(`file://${process.cwd()}/lighthouse/latest-lighthouse-report/${pageToTest.slug ?? slugify(pageToTest.name)}-${type}.html`);
|
|
80
119
|
};
|
|
81
120
|
export async function checkAccessibility(page, { includes, excludes, } = {}) {
|
|
82
121
|
let builder;
|
|
@@ -105,17 +144,17 @@ export async function checkAccessibility(page, { includes, excludes, } = {}) {
|
|
|
105
144
|
})).toEqual([]);
|
|
106
145
|
}
|
|
107
146
|
export const checkPrivilegedPages = (pagesToTest) => async ({ page }) => {
|
|
108
|
-
for (const pageToTest of pagesToTest
|
|
147
|
+
for (const pageToTest of pagesToTest) {
|
|
109
148
|
const response = await page.goto(pageToTest.url);
|
|
110
149
|
expect(response).not.toBeNull();
|
|
111
150
|
const nonNullResponse = response;
|
|
112
151
|
expect(nonNullResponse.status()).toBe(401);
|
|
113
152
|
}
|
|
114
153
|
};
|
|
115
|
-
export const checkForLoremIpsum = (pagesToTest) => async ({
|
|
154
|
+
export const checkForLoremIpsum = (pagesToTest) => async ({ page }) => {
|
|
116
155
|
for (const pageToTest of pagesToTest) {
|
|
117
|
-
await
|
|
118
|
-
await expect(
|
|
156
|
+
await page.goto(pageToTest.url);
|
|
157
|
+
await expect(page.getByText("Lorem ipsum")).not.toBeAttached({
|
|
119
158
|
timeout: 100,
|
|
120
159
|
});
|
|
121
160
|
}
|