@virtocommerce/test-automation-framework 0.0.0-stage → 0.1.0-alpha.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/.biome/formatter.json +11 -0
- package/.biome/imports.json +52 -0
- package/.biome/preset.json +4 -0
- package/.biome/rules.json +45 -0
- package/.claude/agents/qa-automation-expert.md +119 -0
- package/.claude/agents/qa-coverage.md +96 -0
- package/.claude/agents/qa-explorer.md +112 -0
- package/.claude/agents/qa-healer.md +88 -0
- package/.claude/agents/qa-judge.md +102 -0
- package/.claude/agents/qa-planner.md +104 -0
- package/.claude/agents/qa-reviewer.md +121 -0
- package/.claude/checks/browser-secrets.mts +107 -0
- package/.claude/checks/contract.mts +469 -0
- package/.claude/checks/expectation-guard.mts +665 -0
- package/.claude/checks/explore-extractors.mts +4 -0
- package/.claude/checks/judge-verdict.mts +165 -0
- package/.claude/checks/project-facts.mts +491 -0
- package/.claude/checks/prove-fails.mts +770 -0
- package/.claude/checks/rank-gaps.mts +177 -0
- package/.claude/checks/readonly-shell.mts +740 -0
- package/.claude/checks/reconcile-run.mts +270 -0
- package/.claude/checks/scan-prompts.mts +351 -0
- package/.claude/checks/stand.mts +45 -0
- package/.claude/checks/test-duration.mts +134 -0
- package/.claude/checks/test-shape.mts +224 -0
- package/.claude/checks/ticket-card.mts +195 -0
- package/.claude/commands/qa-coverage.md +13 -0
- package/.claude/commands/qa-explore.md +17 -0
- package/.claude/commands/qa-heal.md +44 -0
- package/.claude/commands/qa-implement.md +60 -0
- package/.claude/commands/qa-plan.md +55 -0
- package/.claude/commands/qa-review.md +90 -0
- package/.claude/commands/qa.md +156 -0
- package/.claude/hooks/readonly-shell.mts +65 -0
- package/.claude/settings.json +15 -0
- package/.claude/skills/coverage-analysis/SKILL.md +107 -0
- package/.claude/skills/create-graphql-layer/SKILL.md +159 -0
- package/.claude/skills/create-ui-layer/SKILL.md +189 -0
- package/.claude/skills/explore-api/SKILL.md +74 -0
- package/.claude/skills/explore-frontend/SKILL.md +85 -0
- package/.claude/skills/framework-rules/SKILL.md +189 -0
- package/.claude/skills/heal-tests/SKILL.md +197 -0
- package/.claude/skills/heal-tests/guard-recipe.md +53 -0
- package/.claude/skills/judge-criteria/SKILL.md +40 -0
- package/.claude/skills/judge-criteria/coverage.md +9 -0
- package/.claude/skills/judge-criteria/expert.md +23 -0
- package/.claude/skills/judge-criteria/explorer.md +9 -0
- package/.claude/skills/judge-criteria/healer.md +13 -0
- package/.claude/skills/judge-criteria/planner.md +12 -0
- package/.claude/skills/plan-implementation/SKILL.md +82 -0
- package/.claude/skills/plan-implementation/contract-template.md +72 -0
- package/.claude/skills/plan-test-strategy/SKILL.md +100 -0
- package/.claude/skills/project-facts/SKILL.md +130 -0
- package/.claude/skills/read-change/SKILL.md +64 -0
- package/.claude/skills/read-ticket/SKILL.md +63 -0
- package/.claude/skills/read-ticket/providers.md +58 -0
- package/.claude/skills/review-pr/SKILL.md +152 -0
- package/.claude/skills/review-test-code/SKILL.md +208 -0
- package/.claude/skills/write-e2e-test/SKILL.md +175 -0
- package/.claude/skills/write-graphql-test/SKILL.md +158 -0
- package/.claude/skills/write-rest-api-test/SKILL.md +182 -0
- package/.claude/skills/write-security-test/SKILL.md +253 -0
- package/.qa/project.example.json +71 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE +12 -0
- package/README.md +53 -2
- package/bin/install-qa-agents.mjs +94 -0
- package/dist/auth/credentials.d.ts +10 -0
- package/dist/auth/credentials.js +2 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/frontend-browser-sessions.d.ts +71 -0
- package/dist/auth/frontend-browser-sessions.js +130 -0
- package/dist/auth/frontend-browser-sessions.js.map +1 -0
- package/dist/auth/index.d.ts +9 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/platform-browser-sessions.d.ts +47 -0
- package/dist/auth/platform-browser-sessions.js +92 -0
- package/dist/auth/platform-browser-sessions.js.map +1 -0
- package/dist/auth/sign-in-lock.d.ts +14 -0
- package/dist/auth/sign-in-lock.js +70 -0
- package/dist/auth/sign-in-lock.js.map +1 -0
- package/dist/auth/storage-state.d.ts +3 -0
- package/dist/auth/storage-state.js +2 -0
- package/dist/auth/storage-state.js.map +1 -0
- package/dist/auth/token-client.d.ts +82 -0
- package/dist/auth/token-client.js +111 -0
- package/dist/auth/token-client.js.map +1 -0
- package/dist/auth/token-manager.d.ts +67 -0
- package/dist/auth/token-manager.js +138 -0
- package/dist/auth/token-manager.js.map +1 -0
- package/dist/core/default-reporters.d.ts +31 -0
- package/dist/core/default-reporters.js +36 -0
- package/dist/core/default-reporters.js.map +1 -0
- package/dist/core/default-use.d.ts +28 -0
- package/dist/core/default-use.js +25 -0
- package/dist/core/default-use.js.map +1 -0
- package/dist/core/env.d.ts +24 -0
- package/dist/core/env.js +33 -0
- package/dist/core/env.js.map +1 -0
- package/dist/core/error-message.d.ts +10 -0
- package/dist/core/error-message.js +13 -0
- package/dist/core/error-message.js.map +1 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/is-ci.d.ts +14 -0
- package/dist/core/is-ci.js +18 -0
- package/dist/core/is-ci.js.map +1 -0
- package/dist/core/parse-env.d.ts +13 -0
- package/dist/core/parse-env.js +21 -0
- package/dist/core/parse-env.js.map +1 -0
- package/dist/core/projects.d.ts +24 -0
- package/dist/core/projects.js +33 -0
- package/dist/core/projects.js.map +1 -0
- package/dist/core/run-options.d.ts +31 -0
- package/dist/core/run-options.js +43 -0
- package/dist/core/run-options.js.map +1 -0
- package/dist/core/secret.d.ts +105 -0
- package/dist/core/secret.js +167 -0
- package/dist/core/secret.js.map +1 -0
- package/dist/core/string-schemas.d.ts +39 -0
- package/dist/core/string-schemas.js +56 -0
- package/dist/core/string-schemas.js.map +1 -0
- package/dist/core/url-path.d.ts +7 -0
- package/dist/core/url-path.js +2 -0
- package/dist/core/url-path.js.map +1 -0
- package/dist/dataset/collection.d.ts +44 -0
- package/dist/dataset/collection.js +76 -0
- package/dist/dataset/collection.js.map +1 -0
- package/dist/dataset/index.d.ts +11 -0
- package/dist/dataset/index.js +6 -0
- package/dist/dataset/index.js.map +1 -0
- package/dist/dataset/load-dataset.d.ts +39 -0
- package/dist/dataset/load-dataset.js +62 -0
- package/dist/dataset/load-dataset.js.map +1 -0
- package/dist/dataset/manifest.d.ts +77 -0
- package/dist/dataset/manifest.js +10 -0
- package/dist/dataset/manifest.js.map +1 -0
- package/dist/dataset/placeholders.d.ts +66 -0
- package/dist/dataset/placeholders.js +87 -0
- package/dist/dataset/placeholders.js.map +1 -0
- package/dist/dataset/seed-collection.d.ts +53 -0
- package/dist/dataset/seed-collection.js +115 -0
- package/dist/dataset/seed-collection.js.map +1 -0
- package/dist/dataset/seed-dataset.d.ts +70 -0
- package/dist/dataset/seed-dataset.js +138 -0
- package/dist/dataset/seed-dataset.js.map +1 -0
- package/dist/dataset/seed-events.d.ts +81 -0
- package/dist/dataset/seed-events.js +2 -0
- package/dist/dataset/seed-events.js.map +1 -0
- package/dist/dataset/seed-requests.d.ts +102 -0
- package/dist/dataset/seed-requests.js +160 -0
- package/dist/dataset/seed-requests.js.map +1 -0
- package/dist/dataset/seed-scope.d.ts +39 -0
- package/dist/dataset/seed-scope.js +67 -0
- package/dist/dataset/seed-scope.js.map +1 -0
- package/dist/fixtures/default-fixtures.d.ts +93 -0
- package/dist/fixtures/default-fixtures.js +105 -0
- package/dist/fixtures/default-fixtures.js.map +1 -0
- package/dist/fixtures/index.d.ts +2 -0
- package/dist/fixtures/index.js +2 -0
- package/dist/fixtures/index.js.map +1 -0
- package/dist/graphql/graphql-client.d.ts +78 -0
- package/dist/graphql/graphql-client.js +83 -0
- package/dist/graphql/graphql-client.js.map +1 -0
- package/dist/graphql/graphql-codegen.d.ts +56 -0
- package/dist/graphql/graphql-codegen.js +42 -0
- package/dist/graphql/graphql-codegen.js.map +1 -0
- package/dist/graphql/graphql-error.d.ts +54 -0
- package/dist/graphql/graphql-error.js +74 -0
- package/dist/graphql/graphql-error.js.map +1 -0
- package/dist/graphql/index.d.ts +6 -0
- package/dist/graphql/index.js +4 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/http/authentication.d.ts +16 -0
- package/dist/http/authentication.js +2 -0
- package/dist/http/authentication.js.map +1 -0
- package/dist/http/http-client.d.ts +110 -0
- package/dist/http/http-client.js +237 -0
- package/dist/http/http-client.js.map +1 -0
- package/dist/http/http-error.d.ts +26 -0
- package/dist/http/http-error.js +34 -0
- package/dist/http/http-error.js.map +1 -0
- package/dist/http/http-method.d.ts +2 -0
- package/dist/http/http-method.js +2 -0
- package/dist/http/http-method.js.map +1 -0
- package/dist/http/http-response.d.ts +137 -0
- package/dist/http/http-response.js +166 -0
- package/dist/http/http-response.js.map +1 -0
- package/dist/http/index.d.ts +7 -0
- package/dist/http/index.js +4 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/request-options.d.ts +62 -0
- package/dist/http/request-options.js +2 -0
- package/dist/http/request-options.js.map +1 -0
- package/dist/modules/index.d.ts +2 -0
- package/dist/modules/index.js +2 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/installed-modules.d.ts +86 -0
- package/dist/modules/installed-modules.js +135 -0
- package/dist/modules/installed-modules.js.map +1 -0
- package/docs/README.md +43 -0
- package/docs/concepts/areas.md +38 -0
- package/docs/concepts/auth.md +92 -0
- package/docs/concepts/config.md +102 -0
- package/docs/concepts/dataset.md +183 -0
- package/docs/concepts/environment.md +54 -0
- package/docs/concepts/fixtures.md +109 -0
- package/docs/concepts/graphql.md +76 -0
- package/docs/concepts/http.md +88 -0
- package/docs/concepts/modules.md +63 -0
- package/docs/concepts/secrets.md +50 -0
- package/docs/contributing/architecture.md +67 -0
- package/docs/contributing/conventions.md +39 -0
- package/docs/contributing/documentation.md +37 -0
- package/docs/contributing/releasing.md +76 -0
- package/docs/examples/auth.ts +20 -0
- package/docs/examples/config.ts +36 -0
- package/docs/examples/dataset.ts +70 -0
- package/docs/examples/environment.ts +8 -0
- package/docs/examples/fixtures.ts +41 -0
- package/docs/examples/getting-started.ts +22 -0
- package/docs/examples/graphql-codegen.ts +9 -0
- package/docs/examples/graphql.ts +32 -0
- package/docs/examples/http.ts +18 -0
- package/docs/examples/modules.ts +19 -0
- package/docs/examples/secrets.ts +11 -0
- package/docs/examples/tsconfig.json +10 -0
- package/docs/getting-started.md +106 -0
- package/docs/guides/generating-types.md +75 -0
- package/docs/guides/qa-agents.md +66 -0
- package/package.json +156 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installed-modules.js","sourceRoot":"","sources":["../../src/modules/installed-modules.ts"],"names":[],"mappings":"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","sourcesContent":["import type { HttpClient } from \"@/http\";\n\nimport { array, boolean, object, string } from \"zod\";\n\nimport { errorMessage, nonBlankString } from \"@/core\";\n\nconst MODULES_PATH = \"/api/platform/modules\";\nconst VERSION_PATTERN = /^(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?(?:-([^+]+))?(?:\\+.+)?$/;\n\nconst moduleDescriptorsSchema = array(\n object({\n id: nonBlankString,\n version: string(),\n isInstalled: boolean(),\n }),\n);\n\n/**\n * A platform module that a test or a dataset collection needs, with an optional range of versions.\n *\n * @remarks\n * Without a range, any installed version meets the requirement. Set `minVersion` when the code relies on a fix or a\n * feature of that version, and `beforeVersion` when a later version changes the behaviour that the code checks.\n */\nexport interface ModuleRequirement {\n /** The identifier of the module, such as `VirtoCommerce.Catalog`. */\n readonly id: string;\n /** The oldest version that meets the requirement, inclusive. */\n readonly minVersion?: string | undefined;\n /** The first version that no longer meets the requirement, exclusive. */\n readonly beforeVersion?: string | undefined;\n}\n\n/** Represents the modules installed on a platform, with their versions. */\nexport class InstalledModules {\n readonly #versions: ReadonlyMap<string, string>;\n\n /**\n * Creates a set of installed modules.\n *\n * @remarks\n * A version is checked only when a requirement with a range of versions compares it, so a module whose version is in\n * another form fails only the requirements on that module.\n *\n * @param versions - The version of each module by module identifier.\n */\n constructor(versions: Readonly<Record<string, string>>) {\n this.#versions = new Map(Object.entries(versions));\n }\n\n /**\n * Reads the modules installed on a platform.\n *\n * @param httpClient - A client signed in as a platform administrator.\n * @returns The installed modules. Modules that the platform knows but has not installed are left out.\n * @throws {HttpError} The platform rejects the request, or the response is not a list of modules.\n */\n static async read(httpClient: HttpClient): Promise<InstalledModules> {\n const modules = (await httpClient.get(MODULES_PATH)).parse(moduleDescriptorsSchema);\n return new InstalledModules(\n Object.fromEntries(modules.filter((module) => module.isInstalled).map((module) => [module.id, module.version])),\n );\n }\n\n /** Gets the number of installed modules. */\n get count(): number {\n return this.#versions.size;\n }\n\n /**\n * Returns the installed version of a module.\n *\n * @param id - The identifier of the module.\n * @returns The version, or `undefined` when the module is not installed.\n */\n versionOf(id: string): string | undefined {\n return this.#versions.get(id);\n }\n\n /**\n * Returns why the installed modules do not meet a requirement.\n *\n * @param requirement - The module and the range of versions that are needed.\n * @returns The reason, such as `VirtoCommerce.Quote 3.1010.0 is older than 3.1020.0`, or `undefined` when the\n * requirement is met.\n * @throws {Error} The requirement has a range of versions, and the installed version or a version of the range is not\n * in the form `major[.minor[.patch]][-suffix][+metadata]`. The message names the module.\n */\n unmetReason(requirement: ModuleRequirement): string | undefined {\n const { id, minVersion, beforeVersion } = requirement;\n const version = this.versionOf(id);\n if (version === undefined) {\n return `${id} is not installed`;\n }\n try {\n if (minVersion !== undefined && compareModuleVersions(version, minVersion) < 0) {\n return `${id} ${version} is older than ${minVersion}`;\n }\n if (beforeVersion !== undefined && compareModuleVersions(version, beforeVersion) >= 0) {\n return `${id} ${version} is not older than ${beforeVersion}`;\n }\n } catch (error) {\n throw new Error(`${id}: ${errorMessage(error)}`, { cause: error });\n }\n return undefined;\n }\n\n /**\n * Returns why the installed modules do not meet several requirements.\n *\n * @param requirements - The requirements to check.\n * @returns The reason of each unmet requirement, in the order of `requirements`. It is empty when all are met.\n * @throws {Error} A version cannot be compared, as for {@link InstalledModules.unmetReason}.\n */\n unmetReasons(requirements: readonly ModuleRequirement[]): string[] {\n return requirements.flatMap((requirement) => this.unmetReason(requirement) ?? []);\n }\n\n /**\n * Returns the version of each module by module identifier, so the set can be saved and read again in another\n * process with the constructor.\n *\n * @returns The versions by module identifier.\n */\n toJSON(): Record<string, string> {\n return Object.fromEntries(this.#versions);\n }\n}\n\n/**\n * Compares two module versions, such as `3.1034.0` and `3.1012.1`.\n *\n * @remarks\n * The parts are compared as numbers, so `3.1034.0` is newer than `3.1012.1`. A missing part counts as 0. A build\n * with a suffix, such as `3.1035.0-pr-12`, comes before the release of the same version. Build metadata after `+`,\n * such as `3.1035.0+sha.5114f85`, is ignored.\n *\n * @param left - The first version.\n * @param right - The second version.\n * @returns A negative number when `left` is older, a positive number when it is newer, and 0 when they are equal.\n * @throws {Error} A version is not in the form `major[.minor[.patch]][-suffix][+metadata]`.\n */\nexport function compareModuleVersions(left: string, right: string): number {\n const [leftParts, leftSuffix] = parseVersion(left);\n const [rightParts, rightSuffix] = parseVersion(right);\n for (const [index, part] of leftParts.entries()) {\n const difference = part - (rightParts[index] ?? 0);\n if (difference !== 0) {\n return difference;\n }\n }\n if (leftSuffix === rightSuffix) {\n return 0;\n }\n if (leftSuffix === undefined || rightSuffix === undefined) {\n return leftSuffix === undefined ? 1 : -1;\n }\n return leftSuffix.localeCompare(rightSuffix, \"en\", { numeric: true });\n}\n\nfunction parseVersion(version: string): readonly [readonly number[], string | undefined] {\n const match = VERSION_PATTERN.exec(version.trim());\n if (match === null) {\n throw new Error(`\"${version}\" is not a module version in the form major[.minor[.patch]][-suffix][+metadata]`);\n }\n const [, major, minor, patch, suffix] = match;\n return [[Number(major), Number(minor ?? 0), Number(patch ?? 0)], suffix];\n}\n"]}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Documentation
|
|
2
|
+
|
|
3
|
+
This is the documentation of `@virtocommerce/test-automation-framework`, a Playwright Test framework for the test
|
|
4
|
+
suites of Virto Commerce-based solutions. It ships with the package, so it always matches the installed version.
|
|
5
|
+
|
|
6
|
+
## Terms
|
|
7
|
+
|
|
8
|
+
| Term | Meaning |
|
|
9
|
+
| ---------- | ------------------------------------------------------------------------------------------------------ |
|
|
10
|
+
| Framework | This package: what is the same on every Virto Commerce platform. |
|
|
11
|
+
| Solution | A company's Virto Commerce-based platform, with its modules, stores and frontends. |
|
|
12
|
+
| Test suite | The tests for one solution. It installs the framework and adds its own clients, page objects and data. |
|
|
13
|
+
|
|
14
|
+
## Start here
|
|
15
|
+
|
|
16
|
+
- [Getting started](getting-started.md): set up a test suite and write its first test.
|
|
17
|
+
- [Generating types](guides/generating-types.md): generate types from the GraphQL schema and the OpenAPI documents.
|
|
18
|
+
- [QA agents](guides/qa-agents.md): install the Claude Code agents that plan, write, check and heal the tests.
|
|
19
|
+
|
|
20
|
+
## Concepts
|
|
21
|
+
|
|
22
|
+
- [Areas](concepts/areas.md): the entry points of the package and what each one contains.
|
|
23
|
+
- [Secrets](concepts/secrets.md): how passwords and tokens are kept out of output.
|
|
24
|
+
- [Environment](concepts/environment.md): the environment variables and how a test suite extends them.
|
|
25
|
+
- [Modules](concepts/modules.md): the installed platform modules and the module requirements of tests and data.
|
|
26
|
+
- [HTTP](concepts/http.md): the HTTP client, its responses and its errors.
|
|
27
|
+
- [Authentication](concepts/auth.md): platform sign-in, token renewal, sign-out and browser sessions.
|
|
28
|
+
- [GraphQL](concepts/graphql.md): the GraphQL client, typed documents and GraphQL errors.
|
|
29
|
+
- [Dataset](concepts/dataset.md): the data of a test suite, its manifest, and how it is loaded and seeded.
|
|
30
|
+
- [Playwright config](concepts/config.md): run options, projects, `use` options and reporting.
|
|
31
|
+
- [Fixtures](concepts/fixtures.md): the default Playwright fixtures, module requirements and browser sessions.
|
|
32
|
+
|
|
33
|
+
## API reference
|
|
34
|
+
|
|
35
|
+
The API reference is generated from the documentation comments in the source. Every exported member is documented,
|
|
36
|
+
and the build fails when one is not. Editors show the same text when you hover over a member.
|
|
37
|
+
|
|
38
|
+
## Contributing to the framework
|
|
39
|
+
|
|
40
|
+
- [Architecture](contributing/architecture.md): areas, their dependencies and how the boundaries are enforced.
|
|
41
|
+
- [Conventions](contributing/conventions.md): naming, documentation comments, tests and error handling.
|
|
42
|
+
- [Documentation](contributing/documentation.md): how this documentation is structured and kept accurate.
|
|
43
|
+
- [Releasing](contributing/releasing.md): versions, changesets and publishing.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Areas
|
|
2
|
+
|
|
3
|
+
The framework is divided into areas. Each area has its own entry point, and the package has no root entry point, so a
|
|
4
|
+
test loads only the areas it uses.
|
|
5
|
+
|
|
6
|
+
| Entry point | Contains |
|
|
7
|
+
| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
8
|
+
| `@virtocommerce/test-automation-framework/core` | Secrets and masking, string schemas, the environment variables and their parsing, Playwright config helpers |
|
|
9
|
+
| `@virtocommerce/test-automation-framework/graphql` | The GraphQL client, its results and errors, and the configuration for generating typed documents |
|
|
10
|
+
| `@virtocommerce/test-automation-framework/http` | The HTTP client, its responses and its errors |
|
|
11
|
+
| `@virtocommerce/test-automation-framework/auth` | Platform sign-in: credentials, access tokens, the token client and manager, and browser sessions |
|
|
12
|
+
| `@virtocommerce/test-automation-framework/modules` | The modules installed on the platform and the module requirements of tests and dataset collections |
|
|
13
|
+
| `@virtocommerce/test-automation-framework/dataset` | Loading a dataset from JSON files and seeding it into the platform, driven by a manifest |
|
|
14
|
+
| `@virtocommerce/test-automation-framework/fixtures` | The default Playwright fixtures: clients, signed-in users, module requirements and browser sessions |
|
|
15
|
+
|
|
16
|
+
Only what an entry point exports is public API. Modules that an entry point does not export can change in any release.
|
|
17
|
+
|
|
18
|
+
## Dependencies between areas
|
|
19
|
+
|
|
20
|
+
An area uses only the areas below it:
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
fixtures → modules, graphql, auth, http, core
|
|
24
|
+
dataset → modules, http, core
|
|
25
|
+
auth → http, core
|
|
26
|
+
graphql → http, core
|
|
27
|
+
modules → http, core
|
|
28
|
+
http → core
|
|
29
|
+
core (no other area)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`http` and `graphql` hold nothing specific to Virto Commerce. `core` holds the setup of the framework itself: secrets,
|
|
33
|
+
the environment variables that every Virto Commerce-based solution needs, and the parts of the Playwright config.
|
|
34
|
+
`auth`, `modules` and `dataset` hold what is the same on every Virto Commerce platform: the token endpoints, the list
|
|
35
|
+
of installed modules, and the way data is seeded. The data itself belongs to the test suite.
|
|
36
|
+
|
|
37
|
+
Nothing in the framework is specific to one solution or one store. Stores, frontends and their settings belong to the
|
|
38
|
+
test suite.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Authentication
|
|
2
|
+
|
|
3
|
+
The `auth` area signs users in to the platform with a password and keeps their access tokens. It works for platform
|
|
4
|
+
users, such as the administrator, and for frontend users of any store.
|
|
5
|
+
|
|
6
|
+
## Credentials
|
|
7
|
+
|
|
8
|
+
`Credentials` holds a user name, a password as a `Secret`, and, for a frontend user, the store the user signs in to.
|
|
9
|
+
Because the password is a `Secret`, credentials are safe to log.
|
|
10
|
+
|
|
11
|
+
## The token client
|
|
12
|
+
|
|
13
|
+
`TokenClient` calls the platform token endpoints:
|
|
14
|
+
|
|
15
|
+
| Method | Does |
|
|
16
|
+
| ---------------------- | ------------------------------------------------------------------------------------------ |
|
|
17
|
+
| `signIn` | Signs a user in with a password and returns the access token |
|
|
18
|
+
| `refresh` | Renews a token with its refresh token, or returns `undefined` when the platform rejects it |
|
|
19
|
+
| `revoke` | Revokes the refresh token of a token; the access token stays valid until it expires |
|
|
20
|
+
| `requestPasswordGrant` | Sends a sign-in request and returns the response whatever its status, for sign-in tests |
|
|
21
|
+
|
|
22
|
+
The client sends each request once and does not retry a failure.
|
|
23
|
+
|
|
24
|
+
The platform returns a 500 status when the same user signs in twice at the same time. Playwright workers are separate
|
|
25
|
+
processes, so `signIn` takes a lock for the user and store in the temporary directory of the system: sign-ins of the
|
|
26
|
+
same user wait for each other, also across workers, while sign-ins of different users run at the same time. A lock
|
|
27
|
+
older than a minute is taken over, because its process ended without releasing it. `requestPasswordGrant` takes no
|
|
28
|
+
lock, so sign-in tests send exactly the requests they mean to.
|
|
29
|
+
|
|
30
|
+
## The token manager
|
|
31
|
+
|
|
32
|
+
Tests usually get tokens through `TokenManager`, which keeps one token for each user in each store:
|
|
33
|
+
|
|
34
|
+
- `signIn` signs a user in and returns an HTTP client that sends the user's current token with each request. Wrong
|
|
35
|
+
credentials fail at this call, not on the first request. Pass a client for the same platform as the token client.
|
|
36
|
+
- Concurrent requests for the same user share one sign-in or renewal. A failed sign-in or renewal is not cached.
|
|
37
|
+
- A token that expires within a minute is renewed with its refresh token. When the platform rejects the refresh
|
|
38
|
+
token, the user signs in again.
|
|
39
|
+
- A token that the platform rejects with a 401 status is forgotten, and the request is sent once more with a new
|
|
40
|
+
token. Concurrent requests that receive the 401 status share one new sign-in.
|
|
41
|
+
- A different password for a cached user starts a new sign-in.
|
|
42
|
+
- `signOut` and `signOutAll` revoke the tokens that have not expired. A token is forgotten even when its revocation
|
|
43
|
+
fails.
|
|
44
|
+
|
|
45
|
+
## Browser sessions
|
|
46
|
+
|
|
47
|
+
Browser tests start signed in, so they do not go through the sign-in pages. The sessions build a Playwright storage
|
|
48
|
+
state, which the test applies to its browser context with `setStorageState`:
|
|
49
|
+
|
|
50
|
+
- `FrontendBrowserSessions.signedIn` requests a token through the frontend's own origin and puts it into the
|
|
51
|
+
frontend's local storage. The entry is `{ expires_at, token_type, access_token, refresh_token }`, the format of the
|
|
52
|
+
Virto Commerce frontend. Its key is `auth`, and `storageKeys` changes it for a frontend that keeps its sign-in
|
|
53
|
+
elsewhere.
|
|
54
|
+
- `FrontendBrowserSessions.anonymous` puts a visitor's identifier into local storage, under the key `user-id`, so the
|
|
55
|
+
test knows whose cart it works with. It sends no requests.
|
|
56
|
+
- `PlatformBrowserSessions.signedIn` signs in to the admin UI of the platform and returns its sign-in cookie.
|
|
57
|
+
|
|
58
|
+
Both keep one sign-in for each user, and concurrent calls share it. A failed sign-in is not kept.
|
|
59
|
+
|
|
60
|
+
`FrontendBrowserSessions.signOut` and `dispose` revoke the frontend tokens. The platform cannot revoke the admin UI
|
|
61
|
+
cookie, so `PlatformBrowserSessions.forget` only drops it, and the next call signs in again.
|
|
62
|
+
|
|
63
|
+
A storage state holds tokens and cookies in plain text. Never log it or attach it to a report.
|
|
64
|
+
|
|
65
|
+
## Several stores
|
|
66
|
+
|
|
67
|
+
The same user can be signed in to several stores at once. Each store has its own token, and signing out of one store
|
|
68
|
+
keeps the others:
|
|
69
|
+
|
|
70
|
+
<!-- example: ../examples/auth.ts -->
|
|
71
|
+
```ts
|
|
72
|
+
import type { Secret } from "@virtocommerce/test-automation-framework/core";
|
|
73
|
+
import type { HttpClient } from "@virtocommerce/test-automation-framework/http";
|
|
74
|
+
|
|
75
|
+
import { expect } from "@playwright/test";
|
|
76
|
+
import { TokenClient, TokenManager } from "@virtocommerce/test-automation-framework/auth";
|
|
77
|
+
|
|
78
|
+
export async function signInToTwoStores(anonymous: HttpClient, password: Secret) {
|
|
79
|
+
const tokens = new TokenManager(new TokenClient(anonymous));
|
|
80
|
+
const buyer = { username: "buyer@example.com", password };
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const inStoreA = await tokens.signIn(anonymous, { ...buyer, storeId: "store-a" });
|
|
84
|
+
const inStoreB = await tokens.signIn(anonymous, { ...buyer, storeId: "store-b" });
|
|
85
|
+
|
|
86
|
+
expect((await inStoreA.get("/api/platform/security/currentuser")).ok).toBe(true);
|
|
87
|
+
expect((await inStoreB.get("/api/platform/security/currentuser")).ok).toBe(true);
|
|
88
|
+
} finally {
|
|
89
|
+
await tokens.signOutAll();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Playwright config
|
|
2
|
+
|
|
3
|
+
The framework returns the parts of a Playwright config that every test suite of a Virto Commerce platform sets the
|
|
4
|
+
same way. The test suite keeps its own config file and its layout: its projects, test directories and setup.
|
|
5
|
+
|
|
6
|
+
<!-- example: ../examples/config.ts -->
|
|
7
|
+
```ts
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
import { defineConfig, devices } from "@playwright/test";
|
|
11
|
+
import {
|
|
12
|
+
apiProject,
|
|
13
|
+
DESTRUCTIVE_TAG,
|
|
14
|
+
defaultReporters,
|
|
15
|
+
defaultRunOptions,
|
|
16
|
+
defaultUse,
|
|
17
|
+
e2eProject,
|
|
18
|
+
envSchema,
|
|
19
|
+
parseEnv,
|
|
20
|
+
} from "@virtocommerce/test-automation-framework/core";
|
|
21
|
+
|
|
22
|
+
const env = parseEnv(envSchema);
|
|
23
|
+
|
|
24
|
+
export default defineConfig({
|
|
25
|
+
...defaultRunOptions(env),
|
|
26
|
+
reporter: defaultReporters({
|
|
27
|
+
outputDir: fileURLToPath(new URL("reports", import.meta.url)),
|
|
28
|
+
environment: { backend: env.BACKEND_BASE_URL },
|
|
29
|
+
}),
|
|
30
|
+
use: defaultUse(env),
|
|
31
|
+
projects: [
|
|
32
|
+
{ name: "seed", testDir: "setup", testMatch: "seed.setup.ts" },
|
|
33
|
+
apiProject(env, { name: "rest", testDir: "tests/rest", dependencies: ["seed"] }),
|
|
34
|
+
e2eProject(env, {
|
|
35
|
+
name: "frontend",
|
|
36
|
+
testDir: "tests/e2e",
|
|
37
|
+
dependencies: ["seed"],
|
|
38
|
+
use: { ...devices["Desktop Chrome"] },
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const destructiveTestDetails = { tag: DESTRUCTIVE_TAG };
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Run options
|
|
47
|
+
|
|
48
|
+
`defaultRunOptions` returns the options of the whole run:
|
|
49
|
+
|
|
50
|
+
| Option | Value | Why |
|
|
51
|
+
| ------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
52
|
+
| `retries` | `0` | A flaky test fails and is fixed, not hidden |
|
|
53
|
+
| `forbidOnly` | `true` on CI | A forgotten `test.only` does not shrink CI runs |
|
|
54
|
+
| `workers` | The larger of `API_WORKERS` and `E2E_WORKERS` | API and browser tests share one worker budget |
|
|
55
|
+
| `grepInvert` | Tests tagged `@destructive`, unless `RUN_DESTRUCTIVE_TESTS`; tests tagged `@platform-defect`, when `SKIP_PLATFORM_DEFECTS` | Shared data is changed only where it is allowed; a defect a ticket tracks does not fail the CI of the platform and its modules |
|
|
56
|
+
|
|
57
|
+
A run counts as CI when the `CI` variable is set to a value other than empty, `false` or `0`; `isCi` from the `core`
|
|
58
|
+
area tells the same. Tag a test that deletes or changes shared data with `DESTRUCTIVE_TAG`, such as
|
|
59
|
+
`test("deletes a store", { tag: DESTRUCTIVE_TAG }, async () => {})`. A project that sets its own `grepInvert` replaces
|
|
60
|
+
the filter.
|
|
61
|
+
|
|
62
|
+
A test that fails because of a known platform defect keeps asserting the right behaviour and gets `PLATFORM_DEFECT_TAG`
|
|
63
|
+
with its ticket, such as
|
|
64
|
+
`test("searches apps by id", { tag: PLATFORM_DEFECT_TAG, annotation: { type: "issue", description: "<ticket URL>" } }, async () => {})`.
|
|
65
|
+
It runs and fails by default, so the defect stays visible. A defect that fails every time can also be marked as a known
|
|
66
|
+
issue with `test.fail(true, "<ticket>: <defect>")` in the test: it then passes while the defect is there, and fails
|
|
67
|
+
as soon as the platform is fixed. A run with `SKIP_PLATFORM_DEFECTS` on leaves it out: the
|
|
68
|
+
shared CI workflow that the platform and its modules run turns it on, so a tracked defect does not fail their checks.
|
|
69
|
+
|
|
70
|
+
## Projects
|
|
71
|
+
|
|
72
|
+
`apiProject` limits a project of REST or GraphQL tests to `API_WORKERS` workers, and `e2eProject` limits a project of
|
|
73
|
+
browser tests to `E2E_WORKERS` workers. A project that sets its own `workers` keeps it. When API and browser projects
|
|
74
|
+
run at the same time, they share the workers of the run, so the run never uses more workers than the larger budget.
|
|
75
|
+
|
|
76
|
+
## `use` options
|
|
77
|
+
|
|
78
|
+
`defaultUse` returns the certificate check from `VERIFY_SSL`, keeps the trace, a screenshot and a video of failed
|
|
79
|
+
tests, and sets the test id attribute to `data-test-id`, the attribute of the Virto Commerce frontend. A test suite
|
|
80
|
+
with its own frontend passes its attribute.
|
|
81
|
+
|
|
82
|
+
## Reporting
|
|
83
|
+
|
|
84
|
+
`defaultReporters` writes a line for each test to the console, and Allure results to `allure-results` in `outputDir`.
|
|
85
|
+
`environment` is shown on the overview of the report; registered secrets in its values are masked.
|
|
86
|
+
|
|
87
|
+
The Allure reporter needs `allure-playwright`, an optional peer dependency of the framework. Install it in the test
|
|
88
|
+
suite, together with `allure`, which generates the report from the results. A test suite that reports in another way
|
|
89
|
+
sets its own `reporter`, or adds its reporters to the default ones.
|
|
90
|
+
|
|
91
|
+
The framework writes nothing to the report itself. What it does reaches the report through Playwright:
|
|
92
|
+
|
|
93
|
+
| Framework output | In the report |
|
|
94
|
+
| ----------------------------------------------------- | ------------------------------- |
|
|
95
|
+
| Steps and fixture titles, such as reading the modules | Steps |
|
|
96
|
+
| Attachments, such as the seed log | Attachments |
|
|
97
|
+
| A test skipped for its required modules | A skipped test, with the reason |
|
|
98
|
+
| Errors, with secrets masked | The failure message |
|
|
99
|
+
|
|
100
|
+
The report groups tests by project, file and `describe` block, so a test directory organized by area gives a
|
|
101
|
+
structured report without labels. For other metadata, use Playwright tags and annotations, which every reporter
|
|
102
|
+
understands, such as `test("…", { tag: "@smoke" })`.
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Dataset
|
|
2
|
+
|
|
3
|
+
A test suite keeps the data its tests rely on, such as catalogs, products, users and pages, as JSON files, and seeds
|
|
4
|
+
them into the platform before the tests run. The framework loads the files and sends them; the test suite owns the
|
|
5
|
+
data, the manifest that describes it, and the record types.
|
|
6
|
+
|
|
7
|
+
## Data layout
|
|
8
|
+
|
|
9
|
+
The data directory holds one directory for each collection, named after the collection in kebab case: the records of
|
|
10
|
+
`productInventories` are in `product-inventories/`. Each `.json` file under it,
|
|
11
|
+
in any subdirectory, is one record. The files are read in the order of their paths, with `/` as the separator, so the
|
|
12
|
+
order is the same on every operating system.
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
data/
|
|
16
|
+
catalogs/
|
|
17
|
+
catalog-b2b.json
|
|
18
|
+
categories/
|
|
19
|
+
b2b/
|
|
20
|
+
category-laptops.json
|
|
21
|
+
product-inventories/
|
|
22
|
+
laptop-main-warehouse.json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
A collection without a directory is empty, so a test suite can seed a subset of its manifest.
|
|
26
|
+
|
|
27
|
+
## The manifest
|
|
28
|
+
|
|
29
|
+
The manifest lists the collections in seed order, and describes how each one is sent. A collection that references
|
|
30
|
+
another, such as a category that references its catalog, comes after it.
|
|
31
|
+
|
|
32
|
+
| Field | Meaning |
|
|
33
|
+
| -------------- | ------------------------------------------------------------------------------------------------- |
|
|
34
|
+
| `module` | The module requirement of the collection. A collection whose module does not qualify is skipped |
|
|
35
|
+
| `method` | The method of the seed request |
|
|
36
|
+
| `path` | The path of the seed request |
|
|
37
|
+
| `send` | `each` sends one request for each record; `all` sends one request with every record |
|
|
38
|
+
| `key` | The field, or the fields, that name a record without an `id` in logs and errors |
|
|
39
|
+
| `findPath` | A path that finds a stored record. A stored record is left as it is; see below |
|
|
40
|
+
| `ifMatchPath` | The path whose `ETag` is sent as `If-Match`, for endpoints that need the current version |
|
|
41
|
+
| `storedIdFrom` | A search that finds the stored copy of a record whose identifier the platform assigns |
|
|
42
|
+
| `parentField` | The field that references a parent in the same collection. Parents are sent before their children |
|
|
43
|
+
|
|
44
|
+
A `findPath` that answers with a 404 status, an empty body, `null` or an empty array means that the record is not
|
|
45
|
+
stored, so it also works with list endpoints. Without `findPath`, every record is sent on every run, and the endpoint
|
|
46
|
+
replaces the stored copy. With `storedIdFrom`,
|
|
47
|
+
the seeder searches for the stored copy first, by the `match` field, and sends the record with the stored identifier,
|
|
48
|
+
so the platform updates that copy instead of adding another. When several stored records match, the first one is used.
|
|
49
|
+
When the `ifMatchPath` is not found or has no `ETag`, the request is sent without `If-Match`.
|
|
50
|
+
|
|
51
|
+
A collection sent in one request (`all`) cannot have a `parentField`, and its `path` and `ifMatchPath` cannot have
|
|
52
|
+
record placeholders. The seeder checks the collections in scope before it sends the first request.
|
|
53
|
+
|
|
54
|
+
## Placeholders
|
|
55
|
+
|
|
56
|
+
Paths and data files can contain placeholders:
|
|
57
|
+
|
|
58
|
+
- `${ENV:key}` is filled from the `placeholders` that the test suite passes, such as a store identifier or a password.
|
|
59
|
+
A `Secret` value is revealed where it is filled in, and masked in errors.
|
|
60
|
+
- `${RECORD:field}` is filled from the record, in `findPath` and `storedIdFrom` of any collection, and in `path` and
|
|
61
|
+
`ifMatchPath` of a collection sent one record at a time.
|
|
62
|
+
|
|
63
|
+
Values in paths are URL-encoded, and values in data files are escaped as JSON string content. A placeholder without a
|
|
64
|
+
value is an error.
|
|
65
|
+
|
|
66
|
+
In TypeScript, `envPlaceholder("STORE_ID")` and `recordPlaceholder("code")` return the placeholders, and compose into
|
|
67
|
+
paths, such as `` `/api/inventory/products/${recordPlaceholder("productId")}` ``. They keep the placeholder syntax in
|
|
68
|
+
one place, and linters do not report them, as they report `${` in a plain string.
|
|
69
|
+
|
|
70
|
+
## Loading
|
|
71
|
+
|
|
72
|
+
`loadDataset` reads every collection of the manifest and returns one `Collection` for each. The records are frozen;
|
|
73
|
+
copy a record to build a request body from it. `get` returns a record by its `id`, and fails for an unknown or a
|
|
74
|
+
duplicated identifier; `all` and `filter` return records in file order.
|
|
75
|
+
|
|
76
|
+
The second type parameter gives the record type of collections by name, such as types generated from the platform.
|
|
77
|
+
Collections that it does not name hold plain JSON objects. The types are not checked at run time.
|
|
78
|
+
|
|
79
|
+
## Seeding
|
|
80
|
+
|
|
81
|
+
`seedDataset` takes the installed modules, read with `InstalledModules.read`, and optionally `only`, the collections
|
|
82
|
+
to seed, which `parseCollectionNames` reads from a list such as `products, prices`. It seeds every collection, or the
|
|
83
|
+
ones in `only`, in seed order, and skips those whose module does not qualify and those without records. It returns the
|
|
84
|
+
collections it seeded and skipped, with the reason for each skip, how many records it sent, and how many were already
|
|
85
|
+
stored.
|
|
86
|
+
|
|
87
|
+
The first failed request stops the run. A success status with `succeeded: false` in the body is also a failure,
|
|
88
|
+
because some endpoints refuse a record that way. The error names the collection and the record, has secrets masked, and
|
|
89
|
+
keeps the original error as its cause. A finisher, given by collection, runs right after its collection, for work such
|
|
90
|
+
as publishing the pages just seeded.
|
|
91
|
+
|
|
92
|
+
`onEvent` receives each step of the run as a `SeedEvent`, which carries facts rather than text:
|
|
93
|
+
|
|
94
|
+
| Event | When |
|
|
95
|
+
| ---------- | ------------------------------------------------------------------------------------------------- |
|
|
96
|
+
| `started` | The manifest is checked; it lists the collections to seed |
|
|
97
|
+
| `skipped` | A collection's module does not qualify, or the collection has no records |
|
|
98
|
+
| `seeded` | A collection is seeded; it has the number of records, how many were sent and how many were stored |
|
|
99
|
+
| `failed` | The manifest is invalid, a record or request of a collection fails, or a finisher fails |
|
|
100
|
+
| `finished` | The run ends, also after a failure; it counts the collections seeded, skipped and failed |
|
|
101
|
+
|
|
102
|
+
A `failed` event comes just before the error is thrown. For a collection, it has the counts reached so far and the
|
|
103
|
+
record or request that failed. The manifest is invalid when an entry breaks the rules above, or when the installed
|
|
104
|
+
version of a module cannot be compared with its range; the error names the collection. The test suite decides how the
|
|
105
|
+
events look, such as coloured counts on the console and plain text in a log it attaches to the report.
|
|
106
|
+
|
|
107
|
+
An error thrown by `onEvent` stops the run, and names the event. When the listener fails while it reports a failure,
|
|
108
|
+
the run throws an `AggregateError` with the failure of the run first, so a bug in the listener does not hide why the
|
|
109
|
+
seed failed.
|
|
110
|
+
|
|
111
|
+
<!-- example: ../examples/dataset.ts -->
|
|
112
|
+
```ts
|
|
113
|
+
import type { Manifest, SeedEvent, SeedSummary } from "@virtocommerce/test-automation-framework/dataset";
|
|
114
|
+
import type { HttpClient } from "@virtocommerce/test-automation-framework/http";
|
|
115
|
+
|
|
116
|
+
import { fileURLToPath } from "node:url";
|
|
117
|
+
|
|
118
|
+
import {
|
|
119
|
+
envPlaceholder,
|
|
120
|
+
loadDataset,
|
|
121
|
+
parseCollectionNames,
|
|
122
|
+
recordPlaceholder,
|
|
123
|
+
seedDataset,
|
|
124
|
+
} from "@virtocommerce/test-automation-framework/dataset";
|
|
125
|
+
import { InstalledModules } from "@virtocommerce/test-automation-framework/modules";
|
|
126
|
+
|
|
127
|
+
const CATALOG = { id: "VirtoCommerce.Catalog", minVersion: "3.1051.0" };
|
|
128
|
+
const SHIPPING = { id: "VirtoCommerce.Shipping", minVersion: "3.1010.0" };
|
|
129
|
+
|
|
130
|
+
export const MANIFEST = {
|
|
131
|
+
catalogs: { module: CATALOG, method: "POST", path: "/api/catalog/catalogs", send: "each" },
|
|
132
|
+
categories: {
|
|
133
|
+
module: CATALOG,
|
|
134
|
+
method: "POST",
|
|
135
|
+
path: "/api/catalog/categories",
|
|
136
|
+
send: "each",
|
|
137
|
+
key: "code",
|
|
138
|
+
parentField: "parentId",
|
|
139
|
+
},
|
|
140
|
+
shippingMethods: {
|
|
141
|
+
module: SHIPPING,
|
|
142
|
+
method: "PUT",
|
|
143
|
+
path: "/api/shipping",
|
|
144
|
+
send: "each",
|
|
145
|
+
key: "code",
|
|
146
|
+
storedIdFrom: {
|
|
147
|
+
searchPath: "/api/shipping/search",
|
|
148
|
+
criteria: { storeId: envPlaceholder("STORE_ID"), codes: [recordPlaceholder("code")] },
|
|
149
|
+
match: "code",
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
} as const satisfies Manifest;
|
|
153
|
+
|
|
154
|
+
type Catalog = { readonly id: string; readonly name: string };
|
|
155
|
+
|
|
156
|
+
const PLACEHOLDERS = { STORE_ID: "B2B-store" };
|
|
157
|
+
|
|
158
|
+
export const dataset = loadDataset<typeof MANIFEST, { readonly catalogs: Catalog }>({
|
|
159
|
+
manifest: MANIFEST,
|
|
160
|
+
dataDir: fileURLToPath(new URL("data", import.meta.url)),
|
|
161
|
+
placeholders: PLACEHOLDERS,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
export function catalogName(id: string): string {
|
|
165
|
+
return dataset.catalogs.get(id).name;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export async function seed(
|
|
169
|
+
admin: HttpClient,
|
|
170
|
+
only: string | undefined,
|
|
171
|
+
onEvent: (event: SeedEvent) => void,
|
|
172
|
+
): Promise<SeedSummary<typeof MANIFEST>> {
|
|
173
|
+
return seedDataset({
|
|
174
|
+
http: admin,
|
|
175
|
+
manifest: MANIFEST,
|
|
176
|
+
dataset,
|
|
177
|
+
installed: await InstalledModules.read(admin),
|
|
178
|
+
only: parseCollectionNames(MANIFEST, only),
|
|
179
|
+
placeholders: PLACEHOLDERS,
|
|
180
|
+
onEvent,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Environment
|
|
2
|
+
|
|
3
|
+
A test suite reads its settings from environment variables. The framework defines the variables that every Virto
|
|
4
|
+
Commerce-based solution needs, and each test suite extends them with its own.
|
|
5
|
+
|
|
6
|
+
## The framework variables
|
|
7
|
+
|
|
8
|
+
`envSchema`, exported from `@virtocommerce/test-automation-framework/core`, describes these variables:
|
|
9
|
+
|
|
10
|
+
| Variable | Required | Default | Meaning |
|
|
11
|
+
| ----------------------- | -------- | ------- | ------------------------------------------------------------------ |
|
|
12
|
+
| `BACKEND_BASE_URL` | Yes | | The origin of the platform, such as `https://platform.example.com` |
|
|
13
|
+
| `ADMIN_USERNAME` | Yes | | The user name of the platform administrator account |
|
|
14
|
+
| `ADMIN_PASSWORD` | Yes | | The password of the administrator account, parsed as a `Secret` |
|
|
15
|
+
| `VERIFY_SSL` | No | `true` | Whether to verify the TLS certificate of the platform |
|
|
16
|
+
| `REQUEST_TIMEOUT_MS` | No | `30000` | The time to wait for a response, in milliseconds |
|
|
17
|
+
| `RUN_DESTRUCTIVE_TESTS` | No | `false` | Whether to run tests that delete or change shared data |
|
|
18
|
+
| `SKIP_PLATFORM_DEFECTS` | No | `false` | Whether to leave out tests tagged `@platform-defect` |
|
|
19
|
+
| `API_WORKERS` | No | `4` | The number of workers that run API tests, such as REST and GraphQL |
|
|
20
|
+
| `E2E_WORKERS` | No | `3` | The number of workers that run end-to-end browser tests |
|
|
21
|
+
|
|
22
|
+
`BACKEND_BASE_URL` must be an origin, without a path, query or fragment, and without a user name or password.
|
|
23
|
+
`API_WORKERS` and `E2E_WORKERS` limit the projects that the [Playwright config](config.md) helpers return.
|
|
24
|
+
|
|
25
|
+
## Extending the variables
|
|
26
|
+
|
|
27
|
+
A test suite extends `envSchema` with its own variables and can redefine a variable to change its default:
|
|
28
|
+
|
|
29
|
+
<!-- example: ../examples/environment.ts -->
|
|
30
|
+
```ts
|
|
31
|
+
import { absoluteUrl, envSchema, parseEnv, positiveInt } from "@virtocommerce/test-automation-framework/core";
|
|
32
|
+
|
|
33
|
+
export const suiteEnvSchema = envSchema.extend({
|
|
34
|
+
API_WORKERS: positiveInt.default(8),
|
|
35
|
+
MAILBOX_URL: absoluteUrl,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const env = parseEnv(suiteEnvSchema);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Use the schemas from `@virtocommerce/test-automation-framework/core` for the values: `nonBlankString`, `absoluteUrl`,
|
|
42
|
+
`originUrl`, `positiveInt`, `booleanString` and `secretString`.
|
|
43
|
+
|
|
44
|
+
Stores are not environment variables, because a solution can have several stores. A test suite describes its stores
|
|
45
|
+
in its own configuration.
|
|
46
|
+
|
|
47
|
+
## Parsing
|
|
48
|
+
|
|
49
|
+
`parseEnv` parses the variables with a schema and returns them typed:
|
|
50
|
+
|
|
51
|
+
- An empty variable counts as unset, so its default applies. A line such as `API_WORKERS=` in a `.env` file does not fail.
|
|
52
|
+
- When variables are invalid, it throws one error that lists each of them. The message does not contain the values,
|
|
53
|
+
so it is safe to print even for passwords.
|
|
54
|
+
- Variables that the schema does not name are left out.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Fixtures
|
|
2
|
+
|
|
3
|
+
`defaultFixtures` returns the Playwright fixtures that tests of a Virto Commerce solution need, for its platform and its
|
|
4
|
+
frontends: clients of the platform, signed-in users, the installed modules and browser sessions. A test suite passes
|
|
5
|
+
them to `test.extend` and adds its own fixtures on top.
|
|
6
|
+
|
|
7
|
+
<!-- example: ../examples/fixtures.ts -->
|
|
8
|
+
```ts
|
|
9
|
+
import type { Credentials } from "@virtocommerce/test-automation-framework/auth";
|
|
10
|
+
import type { DefaultFixtures, DefaultWorkerFixtures } from "@virtocommerce/test-automation-framework/fixtures";
|
|
11
|
+
import type { HttpClient } from "@virtocommerce/test-automation-framework/http";
|
|
12
|
+
import type { ModuleRequirement } from "@virtocommerce/test-automation-framework/modules";
|
|
13
|
+
|
|
14
|
+
import { test as base, expect } from "@playwright/test";
|
|
15
|
+
import { envSchema, originUrl, parseEnv, Secret } from "@virtocommerce/test-automation-framework/core";
|
|
16
|
+
import { defaultFixtures } from "@virtocommerce/test-automation-framework/fixtures";
|
|
17
|
+
|
|
18
|
+
const suiteEnvSchema = envSchema.extend({ FRONTEND_BASE_URL: originUrl });
|
|
19
|
+
type SuiteEnv = ReturnType<typeof suiteEnvSchema.parse>;
|
|
20
|
+
const env = parseEnv(suiteEnvSchema);
|
|
21
|
+
|
|
22
|
+
const QUOTES: ModuleRequirement = { id: "VirtoCommerce.Quote", minVersion: "3.1005.0" };
|
|
23
|
+
|
|
24
|
+
const customer: Credentials = {
|
|
25
|
+
username: "customer@example.com",
|
|
26
|
+
password: Secret.of("Customer-Password-1"),
|
|
27
|
+
storeId: "B2B-store",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const test = base.extend<DefaultFixtures, DefaultWorkerFixtures<SuiteEnv>>(defaultFixtures(env)).extend<{
|
|
31
|
+
customerApi: HttpClient;
|
|
32
|
+
}>({
|
|
33
|
+
customerApi: async ({ signIn }, use) => use(await signIn(customer)),
|
|
34
|
+
context: async ({ context, frontendSessions, env }, use) => {
|
|
35
|
+
await context.setStorageState(await frontendSessions.signedIn(env.FRONTEND_BASE_URL, customer));
|
|
36
|
+
await use(context);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test.describe("quotes", () => {
|
|
41
|
+
test.use({ modules: { QUOTES } });
|
|
42
|
+
|
|
43
|
+
test("a customer sees their quotes", async ({ customerApi, page }) => {
|
|
44
|
+
expect((await customerApi.get("/api/platform/security/currentuser")).ok).toBe(true);
|
|
45
|
+
|
|
46
|
+
await page.goto(new URL("/account/quotes", env.FRONTEND_BASE_URL).href);
|
|
47
|
+
await expect(page.getByRole("heading", { name: "Quotes" })).toBeVisible();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
TypeScript cannot infer the fixture types from the definitions, so the test suite passes `DefaultFixtures` and
|
|
53
|
+
`DefaultWorkerFixtures` to `extend`. The test suite chooses its base test: Playwright's `test`, or a test that it
|
|
54
|
+
combined with others through `mergeTests`.
|
|
55
|
+
|
|
56
|
+
## Worker fixtures
|
|
57
|
+
|
|
58
|
+
A worker creates these once and shares them between its tests:
|
|
59
|
+
|
|
60
|
+
| Fixture | Is |
|
|
61
|
+
| ------------------ | ---------------------------------------------------------------------------------------- |
|
|
62
|
+
| `env` | The environment variables of the test suite |
|
|
63
|
+
| `workerHttp` | A client of the platform without authentication, for the work of the worker |
|
|
64
|
+
| `tokens` | The `TokenManager` of the worker. It signs users out when the worker ends |
|
|
65
|
+
| `workerAdmin` | A client signed in as the administrator, for data that the tests of a file share |
|
|
66
|
+
| `frontendSessions` | The `FrontendBrowserSessions` of the worker. Its tokens are revoked when the worker ends |
|
|
67
|
+
| `platformSessions` | The `PlatformBrowserSessions` of the worker |
|
|
68
|
+
|
|
69
|
+
The other fixtures read the platform's address and the administrator from `env`. A test suite that overrides `env`
|
|
70
|
+
points them all elsewhere.
|
|
71
|
+
|
|
72
|
+
## Test fixtures
|
|
73
|
+
|
|
74
|
+
| Fixture | Is |
|
|
75
|
+
| ------------ | ---------------------------------------------------------------------- |
|
|
76
|
+
| `apiContext` | The request context of the test, disposed of after it |
|
|
77
|
+
| `http` | A client of the platform without authentication |
|
|
78
|
+
| `signIn` | Returns a client signed in as a user. The token is kept for the worker |
|
|
79
|
+
| `graphql` | A GraphQL client of the platform without authentication |
|
|
80
|
+
| `modules` | The modules that the tests need, an option set with `test.use` |
|
|
81
|
+
|
|
82
|
+
Users sign in once for each worker. Each test has its own request context, so cookies of one test never reach another.
|
|
83
|
+
|
|
84
|
+
## Required modules
|
|
85
|
+
|
|
86
|
+
A test whose `modules` are not installed, or not in their range of versions, is skipped, and the reason names each
|
|
87
|
+
module. A version that cannot be compared fails the test. The modules are read, as the administrator, only for a test
|
|
88
|
+
that names requirements, so a worker whose tests need none never signs the administrator in to check them.
|
|
89
|
+
|
|
90
|
+
`modules` is a record of `ModuleRequirement`s, so a test names the test suite's constants with shorthand properties,
|
|
91
|
+
such as `{ QUOTES, XPICKUP }`. The keys are only labels; the reason names the modules. These are the same
|
|
92
|
+
constants that the dataset manifest uses, so a collection that the seed skips and the tests that use its data skip for
|
|
93
|
+
the same reason.
|
|
94
|
+
|
|
95
|
+
An inner `test.use` replaces the requirements of the outer one. To keep them, spread them: `{ ...OUTER, QUOTES }`.
|
|
96
|
+
|
|
97
|
+
## Browser sessions
|
|
98
|
+
|
|
99
|
+
Browser tests start signed in, so they skip the sign-in pages. The test suite overrides `context` and applies a storage
|
|
100
|
+
state of `frontendSessions` or `platformSessions`, as the example does. See
|
|
101
|
+
[Authentication](auth.md#browser-sessions) for how the sessions sign in and when they sign out.
|
|
102
|
+
|
|
103
|
+
A user that a test deletes must be signed out first: call `tokens.signOut`, `frontendSessions.signOut` and
|
|
104
|
+
`platformSessions.forget`. Otherwise the worker fails to revoke a token of the deleted user when it ends.
|
|
105
|
+
|
|
106
|
+
## Traces
|
|
107
|
+
|
|
108
|
+
Every request appears in the trace of the test that runs at the time. Requests of the worker, such as sign-ins and
|
|
109
|
+
reading the modules, appear in the trace of the test that first needs them.
|