@atomicsmash/init-testing 1.1.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 +29 -15
- package/dist/utils.d.ts.map +1 -1
- 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} +2 -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 +10 -23
- /package/toCopy/tests/e2e/{example.spec.mts → example/example.test.mts} +0 -0
package/dist/cli.js
CHANGED
|
@@ -5,16 +5,12 @@ import { resolve as pathResolve, relative as pathRelative } from "node:path";
|
|
|
5
5
|
import yargs from "yargs";
|
|
6
6
|
import { hideBin } from "yargs/helpers";
|
|
7
7
|
import { PackageManager } from "./utils.js";
|
|
8
|
-
const packageManager = new PackageManager(await import(`${process.cwd()}/package.json`, {
|
|
9
|
-
with: { type: "json" },
|
|
10
|
-
})
|
|
8
|
+
const packageManager = new PackageManager(await import(`${process.cwd()}/package.json`, { with: { type: "json" } })
|
|
11
9
|
.then((module) => module.default)
|
|
12
10
|
.catch((error) => {
|
|
13
11
|
console.log({ error });
|
|
14
12
|
throw new Error("Unable to find package.json in your cwd. Make sure you're running this command in the right folder.");
|
|
15
|
-
}), await import(`${process.cwd()}/package-lock.json`, {
|
|
16
|
-
with: { type: "json" },
|
|
17
|
-
})
|
|
13
|
+
}), await import(`${process.cwd()}/package-lock.json`, { with: { type: "json" } })
|
|
18
14
|
.then((module) => module.default)
|
|
19
15
|
.catch((error) => {
|
|
20
16
|
console.log({ error });
|
|
@@ -60,13 +56,13 @@ for (const dirent of copyFiles) {
|
|
|
60
56
|
if (!dirent.isFile()) {
|
|
61
57
|
continue;
|
|
62
58
|
}
|
|
63
|
-
if (argv.noExample && dirent.name
|
|
59
|
+
if (argv.noExample && dirent.name.includes("example")) {
|
|
64
60
|
continue;
|
|
65
61
|
}
|
|
66
|
-
if (argv.noUniversal && dirent.name
|
|
62
|
+
if (argv.noUniversal && dirent.name.includes("universal")) {
|
|
67
63
|
continue;
|
|
68
64
|
}
|
|
69
|
-
fileCopies.push(readFile(`${dirent.
|
|
65
|
+
fileCopies.push(readFile(`${dirent.parentPath}/${dirent.name}`, "utf8")
|
|
70
66
|
.then(async (data) => {
|
|
71
67
|
for (const [search, replace] of [
|
|
72
68
|
["%%BASE_URL%%", argv.baseUrl],
|
|
@@ -76,16 +72,33 @@ for (const dirent of copyFiles) {
|
|
|
76
72
|
? "../tsconfig.json"
|
|
77
73
|
: "@atomicsmash/coding-standards/typescript/base",
|
|
78
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
|
+
],
|
|
79
95
|
]) {
|
|
80
96
|
data = data.replace(search, replace);
|
|
81
97
|
}
|
|
82
98
|
await mkdir(`${process.cwd()}/${relativePath}`.slice(0, -1), {
|
|
83
99
|
recursive: true,
|
|
84
100
|
});
|
|
85
|
-
await writeFile(`${process.cwd()}/${relativePath}${dirent.name}`, data, {
|
|
86
|
-
encoding: "utf8",
|
|
87
|
-
flag: argv.overwriteFiles ? "w" : "wx",
|
|
88
|
-
});
|
|
101
|
+
await writeFile(`${process.cwd()}/${relativePath}${dirent.name}`, data, { encoding: "utf8", flag: argv.overwriteFiles ? "w" : "wx" });
|
|
89
102
|
return `${relativePath}${dirent.name} copied successfully.`;
|
|
90
103
|
})
|
|
91
104
|
.catch((error) => `${relativePath}${dirent.name} failed to copy. Error: ${error}`));
|
|
@@ -93,9 +106,10 @@ for (const dirent of copyFiles) {
|
|
|
93
106
|
await Promise.all([
|
|
94
107
|
Promise.allSettled([
|
|
95
108
|
packageManager.ensurePackageIsInstalled("@atomicsmash/test-utils", {
|
|
96
|
-
packageConstraint: "^
|
|
109
|
+
packageConstraint: "^4.0.0",
|
|
97
110
|
type: "dev",
|
|
98
111
|
}),
|
|
112
|
+
packageManager.ensurePackageIsInstalled("@atomicsmash/wordpress-tests-helper", { packageConstraint: "^1.0.0", type: "dev" }),
|
|
99
113
|
packageManager.ensurePackageIsInstalled("@playwright/test", {
|
|
100
114
|
packageConstraint: "^1.0.0",
|
|
101
115
|
type: "dev",
|
|
@@ -121,7 +135,7 @@ await Promise.all([
|
|
|
121
135
|
},
|
|
122
136
|
!hasRootTSConfig
|
|
123
137
|
? packageManager.ensurePackageIsInstalled("typescript", {
|
|
124
|
-
packageConstraint: "
|
|
138
|
+
packageConstraint: "~5.8.0",
|
|
125
139
|
type: "dev",
|
|
126
140
|
})
|
|
127
141
|
: false,
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAqBA,qBAAa,cAAc;IAC1B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,eAAe,CAAkB;IACzC,QAAQ;QACP;;WAEG;;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAqBA,qBAAa,cAAc;IAC1B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,eAAe,CAAkB;IACzC,QAAQ;QACP;;WAEG;eACU,MAAM,EAAE;QACrB;;WAEG;iBACY,MAAM,EAAE;QACvB;;WAEG;oBACe,MAAM,EAAE;MACzB;gBAEU,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IAK1D;;OAEG;IACH,WAAW;IA2BX;;;;OAIG;IACH,iBAAiB,CAAC,WAAW,EAAE,MAAM;;;;;;;;;IA2BrC;;;;;;;;OAQG;IACG,wBAAwB,CAC7B,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;QACT,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;KACxB;CAkGF"}
|
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,15 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
doLighthouseTest,
|
|
3
|
-
|
|
4
|
-
checkForLoremIpsum,
|
|
3
|
+
lighthouseTest,
|
|
5
4
|
} from "@atomicsmash/test-utils";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
test(
|
|
9
|
-
"privileged pages of the site to ensure non-logged in users can't access them",
|
|
10
|
-
checkPrivilegedPages(pagesToTest),
|
|
11
|
-
);
|
|
12
|
-
test("No lingering lorem ipsum on the site", checkForLoremIpsum(pagesToTest));
|
|
5
|
+
import { pagesToTest } from "../../playwright-utils.mjs";
|
|
13
6
|
|
|
14
7
|
for (const pageToTest of pagesToTest) {
|
|
15
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));
|
|
@@ -1,42 +1,29 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
PageList,
|
|
4
|
-
} from "@atomicsmash/test-utils";
|
|
5
|
-
import type { Page } from "@playwright/test";
|
|
6
|
-
import { getLighthouseTest } from "@atomicsmash/test-utils";
|
|
1
|
+
import type { PageList } from "@atomicsmash/test-utils";
|
|
2
|
+
import type { WordPressAdminInteraction } from "@atomicsmash/wordpress-tests-helper";
|
|
7
3
|
import { test as base } from "@playwright/test";
|
|
8
4
|
import { testData } from "./fixtures/testData.mjs";
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
* Fixtures
|
|
12
|
-
*/
|
|
13
|
-
const logInUser: AuthenticatePageFunction = async function ({ page }, use) {
|
|
14
|
-
// Do any actions here to log a user in so you can access logged in areas of the site.
|
|
15
|
-
// This is useful for testing my account pages, etc.
|
|
16
|
-
await use(page);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type CustomFixtures = {
|
|
20
|
-
testData: typeof testData;
|
|
21
|
-
authenticatedPage: Page;
|
|
22
|
-
};
|
|
6
|
+
type CustomFixtures = { testData: typeof testData };
|
|
23
7
|
|
|
24
8
|
export const test = base.extend<CustomFixtures>({
|
|
25
9
|
testData: async (
|
|
26
|
-
// 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.
|
|
27
11
|
{ page },
|
|
28
12
|
use,
|
|
29
13
|
) => {
|
|
30
14
|
// Use the fixture value in the test.
|
|
31
15
|
await use(testData);
|
|
32
16
|
},
|
|
33
|
-
authenticatedPage: [logInUser, { scope: "test" }],
|
|
34
17
|
});
|
|
35
18
|
|
|
36
|
-
export
|
|
37
|
-
export const { expect } = test; // re-export expect to cleanup imports in tests
|
|
19
|
+
export type TestFunctionType = Parameters<typeof base>[2];
|
|
38
20
|
export { checkAccessibility } from "@atomicsmash/test-utils";
|
|
39
21
|
|
|
40
22
|
export const pagesToTest = [
|
|
41
23
|
// hover over PageList to see the format required for each page
|
|
42
24
|
] satisfies PageList;
|
|
25
|
+
|
|
26
|
+
// Used to set the WP version for WordPressAdminInteraction. Supports major dot minor syntax, or "latest"
|
|
27
|
+
export const CURRENT_WORDPRESS_VERSION: ConstructorParameters<
|
|
28
|
+
typeof WordPressAdminInteraction
|
|
29
|
+
>[2] = "6.7";
|
|
File without changes
|