@atomicsmash/init-testing 2.0.0-beta.0 → 2.0.0-beta.2

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 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 === "example.spec.ts") {
59
+ if (argv.noExample && dirent.name.includes("example")) {
60
60
  continue;
61
61
  }
62
- if (argv.noUniversal && dirent.name === "universal.spec.ts") {
62
+ if (argv.noUniversal && dirent.name.includes("universal")) {
63
63
  continue;
64
64
  }
65
- fileCopies.push(readFile(`${dirent.path}/${dirent.name}`, "utf8")
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
  }
@@ -158,6 +178,7 @@ await Promise.all([
158
178
  "/blob-report/",
159
179
  "/playwright/.cache/",
160
180
  "/lighthouse/",
181
+ "/tests/.tmp/",
161
182
  ];
162
183
  const linesToAddToGitignore = [];
163
184
  for (const line of linesToCheck) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atomicsmash/init-testing",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.0",
4
+ "version": "2.0.0-beta.2",
5
5
  "description": "Allow us to easily add automated testing setup to any npm setup.",
6
6
  "keywords": [
7
7
  "atomic",
@@ -1,8 +1,13 @@
1
- import { defineConfig } from "@playwright/test";
1
+ import { defineConfig, PlaywrightTestConfig } from "@playwright/test";
2
2
  import { playwrightConfig } from "@atomicsmash/test-utils";
3
+ import { projects as authProjects } from "./tests/auth/index.mjs";%%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
+ testDir: "./tests",
11
+ use: { baseURL: `%%BASE_URL%%` },
12
+ projects: playwrightProjectsConfig,
8
13
  });
@@ -0,0 +1,17 @@
1
+ import { test as setup } from "@playwright/test";
2
+ import { storageState } from "./index.mjs";
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,7 @@
1
+ import { unlink } from "node:fs/promises";
2
+ import { test as teardown } from "@playwright/test";
3
+ import { storageState } from "./index.mjs";
4
+
5
+ teardown("Login as admin teardown", async () => {
6
+ await unlink(storageState);
7
+ });
@@ -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\.mts/,
12
+ teardown: "Admin teardown",
13
+ },
14
+ {
15
+ name: tearDownName,
16
+ use: { ...devices["Desktop Chrome"] },
17
+ testDir: "./tests/auth",
18
+ testMatch: /admin\.teardown\.mts/,
19
+ },
20
+ ] satisfies PlaywrightTestConfig["projects"];
@@ -0,0 +1,10 @@
1
+ import { generateProjectsForAllBrowsers } from "@atomicsmash/test-utils";
2
+ import { PlaywrightTestConfig } from "@playwright/test";
3
+
4
+ export const projects = [
5
+ ...generateProjectsForAllBrowsers({
6
+ name: "example_tests",
7
+ testDir: "./tests/e2e/example",
8
+ testMatch: /.*example\.test\.mts/,
9
+ }),
10
+ ] satisfies PlaywrightTestConfig["projects"];
@@ -0,0 +1,28 @@
1
+ import {
2
+ doLighthouseTest,
3
+ lighthouseTest,
4
+ doesRoleHaveHighEnoughPermissions,
5
+ } from "@atomicsmash/test-utils";
6
+ import { pagesToTest } from "../../playwright-utils.mjs";
7
+
8
+ lighthouseTest.describe.configure({ mode: "parallel", retries: 3 });
9
+ for (const pageToTest of pagesToTest) {
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
+ }
28
+ }
@@ -0,0 +1,18 @@
1
+ import { generateProjectsForAllBrowsers } from "@atomicsmash/test-utils";
2
+ import { PlaywrightTestConfig } from "@playwright/test";
3
+ import { setupName, storageState } from "../../auth/index.mjs";
4
+
5
+ export const projects = [
6
+ ...generateProjectsForAllBrowsers({
7
+ name: "universal_tests_unauthenticated",
8
+ testDir: "./tests/e2e/universal",
9
+ testMatch: /.*unauthenticated\.test\.mts/,
10
+ }),
11
+ ...generateProjectsForAllBrowsers({
12
+ name: "universal_tests_authenticated",
13
+ testDir: "./tests/e2e/universal",
14
+ testMatch: /.*authenticated\.test\.mts/,
15
+ dependencies: [setupName],
16
+ use: { storageState },
17
+ }),
18
+ ] satisfies PlaywrightTestConfig["projects"];
@@ -0,0 +1,48 @@
1
+ import {
2
+ doLighthouseTest,
3
+ lighthouseTest,
4
+ checkPrivilegedPages,
5
+ checkForLoremIpsum,
6
+ doesRoleHaveHighEnoughPermissions,
7
+ } from "@atomicsmash/test-utils";
8
+ import { test, pagesToTest } from "../../playwright-utils.mjs";
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
+ ),
17
+ );
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
+ test("No lingering lorem ipsum on the site", checkForLoremIpsum(pagesToTest));
26
+
27
+ lighthouseTest.describe.configure({ mode: "parallel", retries: 3 });
28
+ for (const pageToTest of pagesToTest) {
29
+ if (
30
+ // If a page requires any kind of login
31
+ !doesRoleHaveHighEnoughPermissions(
32
+ "unauthenticated",
33
+ pageToTest.minimumUserPrivilege ?? "unauthenticated",
34
+ )
35
+ ) {
36
+ continue;
37
+ }
38
+ lighthouseTest.describe(`${pageToTest.name} Lighthouse tests`, () => {
39
+ lighthouseTest(
40
+ `${pageToTest.name} @desktop @lighthouse`,
41
+ doLighthouseTest(pageToTest, "desktop", true),
42
+ );
43
+ lighthouseTest(
44
+ `${pageToTest.name} @mobile @lighthouse`,
45
+ doLighthouseTest(pageToTest, "mobile", true),
46
+ );
47
+ });
48
+ }
@@ -8,7 +8,6 @@ const handlers: RequestHandler[] = [];
8
8
  const server = setupServer(...handlers);
9
9
 
10
10
  server.listen({ onUnhandledRequest: "warn" });
11
- // eslint-disable-next-line no-console
12
11
  console.info("🔶 Mock server installed");
13
12
 
14
13
  closeWithGrace({ delay: 1000 }, () => {
@@ -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
  ) => {
@@ -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
- ] satisfies PageList;
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<
@@ -1,24 +0,0 @@
1
- import {
2
- doLighthouseTest,
3
- lighthouseTest,
4
- checkPrivilegedPages,
5
- checkForLoremIpsum,
6
- } from "@atomicsmash/test-utils";
7
- import { test, pagesToTest } from "../playwright-utils.mjs";
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));
14
-
15
- for (const pageToTest of pagesToTest) {
16
- lighthouseTest(
17
- `${pageToTest.name} @desktop @lighthouse`,
18
- doLighthouseTest(pageToTest, "desktop", true),
19
- );
20
- lighthouseTest(
21
- `${pageToTest.name} @mobile @lighthouse`,
22
- doLighthouseTest(pageToTest, "mobile", true),
23
- );
24
- }