@atomicsmash/init-testing 2.0.0-beta.1 → 2.0.0-beta.3
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/cli.js +3 -2
- package/package.json +1 -1
- package/toCopy/playwright.config.mts +4 -2
- package/toCopy/tests/auth/{admin.setup.ts → admin.setup.mts} +5 -3
- package/toCopy/tests/auth/{admin.teardown.ts → admin.teardown.mts} +1 -1
- package/toCopy/tests/auth/{index.ts → index.mts} +2 -2
- package/toCopy/tests/e2e/example/index.mts +2 -2
- package/toCopy/tests/e2e/universal/authenticated.test.mts +20 -8
- package/toCopy/tests/e2e/universal/index.mts +4 -4
- package/toCopy/tests/e2e/universal/unauthenticated.test.mts +44 -4
- package/toCopy/tests/playwright-utils.mts +2 -2
package/dist/cli.js
CHANGED
|
@@ -80,7 +80,7 @@ for (const dirent of copyFiles) {
|
|
|
80
80
|
],
|
|
81
81
|
[
|
|
82
82
|
"%%EXAMPLE_TEST_PROJECTS%%",
|
|
83
|
-
argv.noExample ? "" : "\n...exampleProjects,",
|
|
83
|
+
argv.noExample ? "" : "\n ...exampleProjects,",
|
|
84
84
|
],
|
|
85
85
|
[
|
|
86
86
|
"%%UNIVERSAL_TEST_IMPORT%%",
|
|
@@ -90,7 +90,7 @@ for (const dirent of copyFiles) {
|
|
|
90
90
|
],
|
|
91
91
|
[
|
|
92
92
|
"%%UNIVERSAL_TEST_PROJECTS%%",
|
|
93
|
-
argv.noUniversal ? "" : "\n...universalProjects,",
|
|
93
|
+
argv.noUniversal ? "" : "\n ...universalProjects,",
|
|
94
94
|
],
|
|
95
95
|
]) {
|
|
96
96
|
data = data.replace(search, replace);
|
|
@@ -178,6 +178,7 @@ await Promise.all([
|
|
|
178
178
|
"/blob-report/",
|
|
179
179
|
"/playwright/.cache/",
|
|
180
180
|
"/lighthouse/",
|
|
181
|
+
"/tests/.tmp/",
|
|
181
182
|
];
|
|
182
183
|
const linesToAddToGitignore = [];
|
|
183
184
|
for (const line of linesToCheck) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { defineConfig,
|
|
1
|
+
import { defineConfig, PlaywrightTestConfig } from "@playwright/test";
|
|
2
2
|
import { playwrightConfig } from "@atomicsmash/test-utils";
|
|
3
|
-
import { projects as authProjects } from "./tests/auth";%%EXAMPLE_TEST_IMPORT%%%%UNIVERSAL_TEST_IMPORT%%
|
|
3
|
+
import { projects as authProjects } from "./tests/auth/index.mjs";%%EXAMPLE_TEST_IMPORT%%%%UNIVERSAL_TEST_IMPORT%%
|
|
4
4
|
|
|
5
5
|
const playwrightProjectsConfig = [
|
|
6
6
|
...authProjects,%%EXAMPLE_TEST_PROJECTS%%%%UNIVERSAL_TEST_PROJECTS%%
|
|
7
7
|
] satisfies PlaywrightTestConfig["projects"];
|
|
8
8
|
|
|
9
9
|
export default defineConfig(playwrightConfig, {
|
|
10
|
+
testDir: "./tests",
|
|
10
11
|
use: { baseURL: `%%BASE_URL%%` },
|
|
12
|
+
projects: playwrightProjectsConfig,
|
|
11
13
|
});
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { test as setup } from "@playwright/test";
|
|
2
|
-
import { storageState } from "./index.
|
|
2
|
+
import { storageState } from "./index.mjs";
|
|
3
3
|
|
|
4
4
|
setup("Login as admin", async ({ page }) => {
|
|
5
5
|
await page.goto("/wp/wp-admin/");
|
|
6
6
|
|
|
7
7
|
await page
|
|
8
8
|
.getByLabel("Username or Email Address", { exact: true })
|
|
9
|
-
.fill("Bot");
|
|
10
|
-
await page
|
|
9
|
+
.fill(process.env.WORDPRESS_AUTOMATION_USER ?? "Bot");
|
|
10
|
+
await page
|
|
11
|
+
.getByLabel("Password", { exact: true })
|
|
12
|
+
.fill(process.env.WORDPRESS_AUTOMATION_PASSWORD ?? "password");
|
|
11
13
|
|
|
12
14
|
await page.getByRole("button", { name: "Log In", exact: true }).click();
|
|
13
15
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { unlink } from "node:fs/promises";
|
|
2
2
|
import { test as teardown } from "@playwright/test";
|
|
3
|
-
import { storageState } from "./index.
|
|
3
|
+
import { storageState } from "./index.mjs";
|
|
4
4
|
|
|
5
5
|
teardown("Login as admin teardown", async () => {
|
|
6
6
|
await unlink(storageState);
|
|
@@ -8,13 +8,13 @@ export const projects = [
|
|
|
8
8
|
name: setupName,
|
|
9
9
|
use: { ...devices["Desktop Chrome"] },
|
|
10
10
|
testDir: "./tests/auth",
|
|
11
|
-
testMatch: /admin\.setup\.
|
|
11
|
+
testMatch: /admin\.setup\.mts/,
|
|
12
12
|
teardown: "Admin teardown",
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
15
|
name: tearDownName,
|
|
16
16
|
use: { ...devices["Desktop Chrome"] },
|
|
17
17
|
testDir: "./tests/auth",
|
|
18
|
-
testMatch: /admin\.teardown\.
|
|
18
|
+
testMatch: /admin\.teardown\.mts/,
|
|
19
19
|
},
|
|
20
20
|
] satisfies PlaywrightTestConfig["projects"];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { PlaywrightTestConfig } from "@playwright/test";
|
|
2
1
|
import { generateProjectsForAllBrowsers } from "@atomicsmash/test-utils";
|
|
2
|
+
import { PlaywrightTestConfig } from "@playwright/test";
|
|
3
3
|
|
|
4
4
|
export const projects = [
|
|
5
5
|
...generateProjectsForAllBrowsers({
|
|
6
6
|
name: "example_tests",
|
|
7
7
|
testDir: "./tests/e2e/example",
|
|
8
|
-
testMatch: /.*example\.test\.
|
|
8
|
+
testMatch: /.*example\.test\.mts/,
|
|
9
9
|
}),
|
|
10
10
|
] satisfies PlaywrightTestConfig["projects"];
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
doLighthouseTest,
|
|
3
3
|
lighthouseTest,
|
|
4
|
+
doesRoleHaveHighEnoughPermissions,
|
|
4
5
|
} from "@atomicsmash/test-utils";
|
|
5
6
|
import { pagesToTest } from "../../playwright-utils.mjs";
|
|
6
7
|
|
|
8
|
+
lighthouseTest.describe.configure({ mode: "parallel", retries: 3 });
|
|
7
9
|
for (const pageToTest of pagesToTest) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
if (
|
|
11
|
+
// If a page requires any kind of login
|
|
12
|
+
!doesRoleHaveHighEnoughPermissions(
|
|
13
|
+
"unauthenticated",
|
|
14
|
+
pageToTest.minimumUserPrivilege ?? "unauthenticated",
|
|
15
|
+
)
|
|
16
|
+
) {
|
|
17
|
+
lighthouseTest.describe(`${pageToTest.name} Lighthouse tests`, () => {
|
|
18
|
+
lighthouseTest(
|
|
19
|
+
`${pageToTest.name} @desktop @lighthouse`,
|
|
20
|
+
doLighthouseTest(pageToTest, "desktop", true),
|
|
21
|
+
);
|
|
22
|
+
lighthouseTest(
|
|
23
|
+
`${pageToTest.name} @mobile @lighthouse`,
|
|
24
|
+
doLighthouseTest(pageToTest, "mobile", true),
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
16
28
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { PlaywrightTestConfig } from "@playwright/test";
|
|
2
1
|
import { generateProjectsForAllBrowsers } from "@atomicsmash/test-utils";
|
|
3
|
-
import {
|
|
2
|
+
import { PlaywrightTestConfig } from "@playwright/test";
|
|
3
|
+
import { setupName, storageState } from "../../auth/index.mjs";
|
|
4
4
|
|
|
5
5
|
export const projects = [
|
|
6
6
|
...generateProjectsForAllBrowsers({
|
|
7
7
|
name: "universal_tests_unauthenticated",
|
|
8
8
|
testDir: "./tests/e2e/universal",
|
|
9
|
-
testMatch:
|
|
9
|
+
testMatch: /.*\/unauthenticated\.test\.mts/,
|
|
10
10
|
}),
|
|
11
11
|
...generateProjectsForAllBrowsers({
|
|
12
12
|
name: "universal_tests_authenticated",
|
|
13
13
|
testDir: "./tests/e2e/universal",
|
|
14
|
-
testMatch:
|
|
14
|
+
testMatch: /.*\/authenticated\.test\.mts/,
|
|
15
15
|
dependencies: [setupName],
|
|
16
16
|
use: { storageState },
|
|
17
17
|
}),
|
|
@@ -1,11 +1,51 @@
|
|
|
1
1
|
import {
|
|
2
|
+
doLighthouseTest,
|
|
3
|
+
lighthouseTest,
|
|
2
4
|
checkPrivilegedPages,
|
|
3
5
|
checkForLoremIpsum,
|
|
6
|
+
doesRoleHaveHighEnoughPermissions,
|
|
4
7
|
} from "@atomicsmash/test-utils";
|
|
5
8
|
import { test, pagesToTest } from "../../playwright-utils.mjs";
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const pagesRequiringAuthentication = pagesToTest.filter(
|
|
11
|
+
(page) =>
|
|
12
|
+
// If a page requires any kind of login
|
|
13
|
+
!doesRoleHaveHighEnoughPermissions(
|
|
14
|
+
"unauthenticated",
|
|
15
|
+
page.minimumUserPrivilege ?? "unauthenticated",
|
|
16
|
+
),
|
|
10
17
|
);
|
|
11
|
-
|
|
18
|
+
|
|
19
|
+
if (pagesRequiringAuthentication.length) {
|
|
20
|
+
test(
|
|
21
|
+
"privileged pages of the site to ensure non-logged in users can't access them",
|
|
22
|
+
checkPrivilegedPages(pagesRequiringAuthentication),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (pagesToTest.length) {
|
|
27
|
+
test("No lingering lorem ipsum on the site", checkForLoremIpsum(pagesToTest));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
lighthouseTest.describe.configure({ mode: "parallel", retries: 3 });
|
|
31
|
+
for (const pageToTest of pagesToTest) {
|
|
32
|
+
if (
|
|
33
|
+
// If a page requires any kind of login
|
|
34
|
+
!doesRoleHaveHighEnoughPermissions(
|
|
35
|
+
"unauthenticated",
|
|
36
|
+
pageToTest.minimumUserPrivilege ?? "unauthenticated",
|
|
37
|
+
)
|
|
38
|
+
) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
lighthouseTest.describe(`${pageToTest.name} Lighthouse tests`, () => {
|
|
42
|
+
lighthouseTest(
|
|
43
|
+
`${pageToTest.name} @desktop @lighthouse`,
|
|
44
|
+
doLighthouseTest(pageToTest, "desktop", true),
|
|
45
|
+
);
|
|
46
|
+
lighthouseTest(
|
|
47
|
+
`${pageToTest.name} @mobile @lighthouse`,
|
|
48
|
+
doLighthouseTest(pageToTest, "mobile", true),
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -19,9 +19,9 @@ export const test = base.extend<CustomFixtures>({
|
|
|
19
19
|
export type TestFunctionType = Parameters<typeof base>[2];
|
|
20
20
|
export { checkAccessibility } from "@atomicsmash/test-utils";
|
|
21
21
|
|
|
22
|
-
export const pagesToTest = [
|
|
22
|
+
export const pagesToTest: PageList = [
|
|
23
23
|
// hover over PageList to see the format required for each page
|
|
24
|
-
]
|
|
24
|
+
];
|
|
25
25
|
|
|
26
26
|
// Used to set the WP version for WordPressAdminInteraction. Supports major dot minor syntax, or "latest"
|
|
27
27
|
export const CURRENT_WORDPRESS_VERSION: ConstructorParameters<
|