@atomicsmash/init-testing 2.0.0-beta.0 → 2.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/cli.js +23 -3
- package/package.json +1 -1
- package/toCopy/playwright.config.mts +7 -4
- package/toCopy/tests/auth/admin.setup.ts +17 -0
- package/toCopy/tests/auth/admin.teardown.ts +7 -0
- package/toCopy/tests/auth/index.ts +20 -0
- package/toCopy/tests/e2e/example/index.mts +10 -0
- package/toCopy/tests/e2e/{universal.spec.mts → universal/authenticated.test.mts} +1 -9
- package/toCopy/tests/e2e/universal/index.mts +18 -0
- package/toCopy/tests/e2e/universal/unauthenticated.test.mts +11 -0
- package/toCopy/tests/mocks/index.mts +0 -1
- package/toCopy/tests/playwright-utils.mts +1 -1
- /package/toCopy/tests/e2e/{example.spec.mts → example/example.test.mts} +0 -0
package/dist/cli.js
CHANGED
|
@@ -56,13 +56,13 @@ for (const dirent of copyFiles) {
|
|
|
56
56
|
if (!dirent.isFile()) {
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
|
-
if (argv.noExample && dirent.name
|
|
59
|
+
if (argv.noExample && dirent.name.includes("example")) {
|
|
60
60
|
continue;
|
|
61
61
|
}
|
|
62
|
-
if (argv.noUniversal && dirent.name
|
|
62
|
+
if (argv.noUniversal && dirent.name.includes("universal")) {
|
|
63
63
|
continue;
|
|
64
64
|
}
|
|
65
|
-
fileCopies.push(readFile(`${dirent.
|
|
65
|
+
fileCopies.push(readFile(`${dirent.parentPath}/${dirent.name}`, "utf8")
|
|
66
66
|
.then(async (data) => {
|
|
67
67
|
for (const [search, replace] of [
|
|
68
68
|
["%%BASE_URL%%", argv.baseUrl],
|
|
@@ -72,6 +72,26 @@ for (const dirent of copyFiles) {
|
|
|
72
72
|
? "../tsconfig.json"
|
|
73
73
|
: "@atomicsmash/coding-standards/typescript/base",
|
|
74
74
|
],
|
|
75
|
+
[
|
|
76
|
+
"%%EXAMPLE_TEST_IMPORT%%",
|
|
77
|
+
argv.noExample
|
|
78
|
+
? ""
|
|
79
|
+
: '\nimport { projects as exampleProjects } from "./tests/e2e/example/index.mjs";',
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
"%%EXAMPLE_TEST_PROJECTS%%",
|
|
83
|
+
argv.noExample ? "" : "\n...exampleProjects,",
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
"%%UNIVERSAL_TEST_IMPORT%%",
|
|
87
|
+
argv.noUniversal
|
|
88
|
+
? ""
|
|
89
|
+
: '\nimport { projects as universalProjects } from "./tests/e2e/universal/index.mjs";',
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
"%%UNIVERSAL_TEST_PROJECTS%%",
|
|
93
|
+
argv.noUniversal ? "" : "\n...universalProjects,",
|
|
94
|
+
],
|
|
75
95
|
]) {
|
|
76
96
|
data = data.replace(search, replace);
|
|
77
97
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { defineConfig } from "@playwright/test";
|
|
1
|
+
import { defineConfig, devices, 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%%
|
|
4
|
+
|
|
5
|
+
const playwrightProjectsConfig = [
|
|
6
|
+
...authProjects,%%EXAMPLE_TEST_PROJECTS%%%%UNIVERSAL_TEST_PROJECTS%%
|
|
7
|
+
] satisfies PlaywrightTestConfig["projects"];
|
|
3
8
|
|
|
4
9
|
export default defineConfig(playwrightConfig, {
|
|
5
|
-
use: {
|
|
6
|
-
baseURL: `%%BASE_URL%%`,
|
|
7
|
-
},
|
|
10
|
+
use: { baseURL: `%%BASE_URL%%` },
|
|
8
11
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { test as setup } from "@playwright/test";
|
|
2
|
+
import { storageState } from "./index.js";
|
|
3
|
+
|
|
4
|
+
setup("Login as admin", async ({ page }) => {
|
|
5
|
+
await page.goto("/wp/wp-admin/");
|
|
6
|
+
|
|
7
|
+
await page
|
|
8
|
+
.getByLabel("Username or Email Address", { exact: true })
|
|
9
|
+
.fill("Bot");
|
|
10
|
+
await page.getByLabel("Password", { exact: true }).fill("password");
|
|
11
|
+
|
|
12
|
+
await page.getByRole("button", { name: "Log In", exact: true }).click();
|
|
13
|
+
|
|
14
|
+
await page.waitForURL("/wp/wp-admin/");
|
|
15
|
+
|
|
16
|
+
await page.context().storageState({ path: storageState });
|
|
17
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { devices, PlaywrightTestConfig } from "@playwright/test";
|
|
2
|
+
|
|
3
|
+
export const setupName = "Admin login";
|
|
4
|
+
export const tearDownName = "Admin teardown";
|
|
5
|
+
export const storageState = "tests/.tmp/admin.auth.json";
|
|
6
|
+
export const projects = [
|
|
7
|
+
{
|
|
8
|
+
name: setupName,
|
|
9
|
+
use: { ...devices["Desktop Chrome"] },
|
|
10
|
+
testDir: "./tests/auth",
|
|
11
|
+
testMatch: /admin\.setup\.ts/,
|
|
12
|
+
teardown: "Admin teardown",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: tearDownName,
|
|
16
|
+
use: { ...devices["Desktop Chrome"] },
|
|
17
|
+
testDir: "./tests/auth",
|
|
18
|
+
testMatch: /admin\.teardown\.ts/,
|
|
19
|
+
},
|
|
20
|
+
] satisfies PlaywrightTestConfig["projects"];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PlaywrightTestConfig } from "@playwright/test";
|
|
2
|
+
import { generateProjectsForAllBrowsers } from "@atomicsmash/test-utils";
|
|
3
|
+
|
|
4
|
+
export const projects = [
|
|
5
|
+
...generateProjectsForAllBrowsers({
|
|
6
|
+
name: "example_tests",
|
|
7
|
+
testDir: "./tests/e2e/example",
|
|
8
|
+
testMatch: /.*example\.test\.ts/,
|
|
9
|
+
}),
|
|
10
|
+
] satisfies PlaywrightTestConfig["projects"];
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
doLighthouseTest,
|
|
3
3
|
lighthouseTest,
|
|
4
|
-
checkPrivilegedPages,
|
|
5
|
-
checkForLoremIpsum,
|
|
6
4
|
} from "@atomicsmash/test-utils";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
test(
|
|
10
|
-
"privileged pages of the site to ensure non-logged in users can't access them",
|
|
11
|
-
checkPrivilegedPages(pagesToTest),
|
|
12
|
-
);
|
|
13
|
-
test("No lingering lorem ipsum on the site", checkForLoremIpsum(pagesToTest));
|
|
5
|
+
import { pagesToTest } from "../../playwright-utils.mjs";
|
|
14
6
|
|
|
15
7
|
for (const pageToTest of pagesToTest) {
|
|
16
8
|
lighthouseTest(
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PlaywrightTestConfig } from "@playwright/test";
|
|
2
|
+
import { generateProjectsForAllBrowsers } from "@atomicsmash/test-utils";
|
|
3
|
+
import { setupName, storageState } from "../../auth/index.js";
|
|
4
|
+
|
|
5
|
+
export const projects = [
|
|
6
|
+
...generateProjectsForAllBrowsers({
|
|
7
|
+
name: "universal_tests_unauthenticated",
|
|
8
|
+
testDir: "./tests/e2e/universal",
|
|
9
|
+
testMatch: /.*unauthenticated\.test\.ts/,
|
|
10
|
+
}),
|
|
11
|
+
...generateProjectsForAllBrowsers({
|
|
12
|
+
name: "universal_tests_authenticated",
|
|
13
|
+
testDir: "./tests/e2e/universal",
|
|
14
|
+
testMatch: /.*authenticated\.test\.ts/,
|
|
15
|
+
dependencies: [setupName],
|
|
16
|
+
use: { storageState },
|
|
17
|
+
}),
|
|
18
|
+
] satisfies PlaywrightTestConfig["projects"];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
checkPrivilegedPages,
|
|
3
|
+
checkForLoremIpsum,
|
|
4
|
+
} from "@atomicsmash/test-utils";
|
|
5
|
+
import { test, pagesToTest } from "../../playwright-utils.mjs";
|
|
6
|
+
|
|
7
|
+
test(
|
|
8
|
+
"privileged pages of the site to ensure non-logged in users can't access them",
|
|
9
|
+
checkPrivilegedPages(pagesToTest),
|
|
10
|
+
);
|
|
11
|
+
test("No lingering lorem ipsum on the site", checkForLoremIpsum(pagesToTest));
|
|
@@ -7,7 +7,7 @@ type CustomFixtures = { testData: typeof testData };
|
|
|
7
7
|
|
|
8
8
|
export const test = base.extend<CustomFixtures>({
|
|
9
9
|
testData: async (
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Playwright requires destructuring of the page variable even when not used.
|
|
11
11
|
{ page },
|
|
12
12
|
use,
|
|
13
13
|
) => {
|
|
File without changes
|