@virtocommerce/test-automation-framework 0.0.0-stage → 0.2.0-alpha.20261126085150

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.
Files changed (264) hide show
  1. package/.biome/formatter.json +11 -0
  2. package/.biome/imports.json +52 -0
  3. package/.biome/preset.json +4 -0
  4. package/.biome/rules.json +45 -0
  5. package/.claude/agents/vc-qa-automation-expert.md +122 -0
  6. package/.claude/agents/vc-qa-coverage.md +99 -0
  7. package/.claude/agents/vc-qa-explorer.md +117 -0
  8. package/.claude/agents/vc-qa-healer.md +90 -0
  9. package/.claude/agents/vc-qa-judge.md +102 -0
  10. package/.claude/agents/vc-qa-planner.md +117 -0
  11. package/.claude/agents/vc-qa-reviewer.md +128 -0
  12. package/.claude/checks/browser-secrets.mts +150 -0
  13. package/.claude/checks/contract.mts +694 -0
  14. package/.claude/checks/expectation-guard.mts +665 -0
  15. package/.claude/checks/explore-extractors.mts +4 -0
  16. package/.claude/checks/facts-consistency.mts +335 -0
  17. package/.claude/checks/introspect.mts +157 -0
  18. package/.claude/checks/judge-verdict.mts +206 -0
  19. package/.claude/checks/probe.mts +91 -0
  20. package/.claude/checks/project-facts.mts +570 -0
  21. package/.claude/checks/prove-fails.mts +965 -0
  22. package/.claude/checks/prune.mts +584 -0
  23. package/.claude/checks/rank-gaps.mts +196 -0
  24. package/.claude/checks/readonly-shell.mts +819 -0
  25. package/.claude/checks/reconcile-run.mts +327 -0
  26. package/.claude/checks/run-record.mts +338 -0
  27. package/.claude/checks/scan-prompts.mts +351 -0
  28. package/.claude/checks/stand-request.mts +76 -0
  29. package/.claude/checks/stand.mts +45 -0
  30. package/.claude/checks/test-duration.mts +134 -0
  31. package/.claude/checks/test-shape.mts +288 -0
  32. package/.claude/checks/ticket-card.mts +195 -0
  33. package/.claude/commands/vc-qa-coverage.md +20 -0
  34. package/.claude/commands/vc-qa-explore.md +17 -0
  35. package/.claude/commands/vc-qa-heal.md +44 -0
  36. package/.claude/commands/vc-qa-implement.md +60 -0
  37. package/.claude/commands/vc-qa-plan.md +64 -0
  38. package/.claude/commands/vc-qa-review.md +90 -0
  39. package/.claude/commands/vc-qa.md +165 -0
  40. package/.claude/hooks/readonly-shell.mts +65 -0
  41. package/.claude/settings.json +15 -0
  42. package/.claude/skills/vc-coverage-analysis/SKILL.md +116 -0
  43. package/.claude/skills/vc-create-graphql-layer/SKILL.md +161 -0
  44. package/.claude/skills/vc-create-ui-layer/SKILL.md +191 -0
  45. package/.claude/skills/vc-explore-api/SKILL.md +93 -0
  46. package/.claude/skills/vc-explore-frontend/SKILL.md +91 -0
  47. package/.claude/skills/vc-framework-rules/SKILL.md +212 -0
  48. package/.claude/skills/vc-heal-tests/SKILL.md +197 -0
  49. package/.claude/skills/vc-heal-tests/guard-recipe.md +53 -0
  50. package/.claude/skills/vc-judge-criteria/SKILL.md +42 -0
  51. package/.claude/skills/vc-judge-criteria/coverage.md +9 -0
  52. package/.claude/skills/vc-judge-criteria/expert.md +28 -0
  53. package/.claude/skills/vc-judge-criteria/explorer.md +9 -0
  54. package/.claude/skills/vc-judge-criteria/healer.md +13 -0
  55. package/.claude/skills/vc-judge-criteria/planner.md +12 -0
  56. package/.claude/skills/vc-plan-implementation/SKILL.md +94 -0
  57. package/.claude/skills/vc-plan-implementation/contract-template.md +86 -0
  58. package/.claude/skills/vc-plan-test-strategy/SKILL.md +110 -0
  59. package/.claude/skills/vc-project-facts/SKILL.md +165 -0
  60. package/.claude/skills/vc-read-change/SKILL.md +64 -0
  61. package/.claude/skills/vc-read-ticket/SKILL.md +63 -0
  62. package/.claude/skills/vc-read-ticket/providers.md +58 -0
  63. package/.claude/skills/vc-review-pr/SKILL.md +152 -0
  64. package/.claude/skills/vc-review-test-code/SKILL.md +222 -0
  65. package/.claude/skills/vc-write-e2e-test/SKILL.md +179 -0
  66. package/.claude/skills/vc-write-graphql-test/SKILL.md +162 -0
  67. package/.claude/skills/vc-write-rest-api-test/SKILL.md +187 -0
  68. package/.claude/skills/vc-write-security-test/SKILL.md +257 -0
  69. package/.qa/project.example.json +71 -0
  70. package/CHANGELOG.md +118 -0
  71. package/LICENSE +12 -0
  72. package/README.md +70 -2
  73. package/bin/vc-qa-agents.mjs +595 -0
  74. package/dist/auth/browser-sessions.d.ts +88 -0
  75. package/dist/auth/browser-sessions.js +126 -0
  76. package/dist/auth/browser-sessions.js.map +1 -0
  77. package/dist/auth/credentials.d.ts +10 -0
  78. package/dist/auth/credentials.js +2 -0
  79. package/dist/auth/credentials.js.map +1 -0
  80. package/dist/auth/index.d.ts +9 -0
  81. package/dist/auth/index.js +5 -0
  82. package/dist/auth/index.js.map +1 -0
  83. package/dist/auth/sign-in-lock.d.ts +14 -0
  84. package/dist/auth/sign-in-lock.js +70 -0
  85. package/dist/auth/sign-in-lock.js.map +1 -0
  86. package/dist/auth/sign-in-strategies.d.ts +67 -0
  87. package/dist/auth/sign-in-strategies.js +121 -0
  88. package/dist/auth/sign-in-strategies.js.map +1 -0
  89. package/dist/auth/storage-state.d.ts +3 -0
  90. package/dist/auth/storage-state.js +2 -0
  91. package/dist/auth/storage-state.js.map +1 -0
  92. package/dist/auth/token-client.d.ts +90 -0
  93. package/dist/auth/token-client.js +116 -0
  94. package/dist/auth/token-client.js.map +1 -0
  95. package/dist/auth/token-manager.d.ts +67 -0
  96. package/dist/auth/token-manager.js +138 -0
  97. package/dist/auth/token-manager.js.map +1 -0
  98. package/dist/core/default-reporters.d.ts +31 -0
  99. package/dist/core/default-reporters.js +36 -0
  100. package/dist/core/default-reporters.js.map +1 -0
  101. package/dist/core/default-use.d.ts +28 -0
  102. package/dist/core/default-use.js +25 -0
  103. package/dist/core/default-use.js.map +1 -0
  104. package/dist/core/env.d.ts +24 -0
  105. package/dist/core/env.js +33 -0
  106. package/dist/core/env.js.map +1 -0
  107. package/dist/core/error-message.d.ts +10 -0
  108. package/dist/core/error-message.js +13 -0
  109. package/dist/core/error-message.js.map +1 -0
  110. package/dist/core/index.d.ts +16 -0
  111. package/dist/core/index.js +11 -0
  112. package/dist/core/index.js.map +1 -0
  113. package/dist/core/is-ci.d.ts +14 -0
  114. package/dist/core/is-ci.js +18 -0
  115. package/dist/core/is-ci.js.map +1 -0
  116. package/dist/core/parse-env.d.ts +13 -0
  117. package/dist/core/parse-env.js +21 -0
  118. package/dist/core/parse-env.js.map +1 -0
  119. package/dist/core/projects.d.ts +24 -0
  120. package/dist/core/projects.js +33 -0
  121. package/dist/core/projects.js.map +1 -0
  122. package/dist/core/run-options.d.ts +31 -0
  123. package/dist/core/run-options.js +43 -0
  124. package/dist/core/run-options.js.map +1 -0
  125. package/dist/core/secret.d.ts +105 -0
  126. package/dist/core/secret.js +167 -0
  127. package/dist/core/secret.js.map +1 -0
  128. package/dist/core/string-schemas.d.ts +39 -0
  129. package/dist/core/string-schemas.js +56 -0
  130. package/dist/core/string-schemas.js.map +1 -0
  131. package/dist/core/url-path.d.ts +7 -0
  132. package/dist/core/url-path.js +2 -0
  133. package/dist/core/url-path.js.map +1 -0
  134. package/dist/dataset/collection.d.ts +44 -0
  135. package/dist/dataset/collection.js +76 -0
  136. package/dist/dataset/collection.js.map +1 -0
  137. package/dist/dataset/index.d.ts +11 -0
  138. package/dist/dataset/index.js +6 -0
  139. package/dist/dataset/index.js.map +1 -0
  140. package/dist/dataset/load-dataset.d.ts +39 -0
  141. package/dist/dataset/load-dataset.js +62 -0
  142. package/dist/dataset/load-dataset.js.map +1 -0
  143. package/dist/dataset/manifest.d.ts +77 -0
  144. package/dist/dataset/manifest.js +10 -0
  145. package/dist/dataset/manifest.js.map +1 -0
  146. package/dist/dataset/placeholders.d.ts +66 -0
  147. package/dist/dataset/placeholders.js +87 -0
  148. package/dist/dataset/placeholders.js.map +1 -0
  149. package/dist/dataset/seed-collection.d.ts +53 -0
  150. package/dist/dataset/seed-collection.js +115 -0
  151. package/dist/dataset/seed-collection.js.map +1 -0
  152. package/dist/dataset/seed-dataset.d.ts +70 -0
  153. package/dist/dataset/seed-dataset.js +138 -0
  154. package/dist/dataset/seed-dataset.js.map +1 -0
  155. package/dist/dataset/seed-events.d.ts +81 -0
  156. package/dist/dataset/seed-events.js +2 -0
  157. package/dist/dataset/seed-events.js.map +1 -0
  158. package/dist/dataset/seed-requests.d.ts +102 -0
  159. package/dist/dataset/seed-requests.js +160 -0
  160. package/dist/dataset/seed-requests.js.map +1 -0
  161. package/dist/dataset/seed-scope.d.ts +39 -0
  162. package/dist/dataset/seed-scope.js +67 -0
  163. package/dist/dataset/seed-scope.js.map +1 -0
  164. package/dist/fixtures/default-fixtures.d.ts +96 -0
  165. package/dist/fixtures/default-fixtures.js +109 -0
  166. package/dist/fixtures/default-fixtures.js.map +1 -0
  167. package/dist/fixtures/index.d.ts +2 -0
  168. package/dist/fixtures/index.js +2 -0
  169. package/dist/fixtures/index.js.map +1 -0
  170. package/dist/graphql/graphql-client.d.ts +78 -0
  171. package/dist/graphql/graphql-client.js +83 -0
  172. package/dist/graphql/graphql-client.js.map +1 -0
  173. package/dist/graphql/graphql-codegen.d.ts +56 -0
  174. package/dist/graphql/graphql-codegen.js +42 -0
  175. package/dist/graphql/graphql-codegen.js.map +1 -0
  176. package/dist/graphql/graphql-error.d.ts +54 -0
  177. package/dist/graphql/graphql-error.js +74 -0
  178. package/dist/graphql/graphql-error.js.map +1 -0
  179. package/dist/graphql/index.d.ts +6 -0
  180. package/dist/graphql/index.js +4 -0
  181. package/dist/graphql/index.js.map +1 -0
  182. package/dist/http/authentication.d.ts +16 -0
  183. package/dist/http/authentication.js +2 -0
  184. package/dist/http/authentication.js.map +1 -0
  185. package/dist/http/http-client.d.ts +110 -0
  186. package/dist/http/http-client.js +237 -0
  187. package/dist/http/http-client.js.map +1 -0
  188. package/dist/http/http-error.d.ts +26 -0
  189. package/dist/http/http-error.js +34 -0
  190. package/dist/http/http-error.js.map +1 -0
  191. package/dist/http/http-method.d.ts +2 -0
  192. package/dist/http/http-method.js +2 -0
  193. package/dist/http/http-method.js.map +1 -0
  194. package/dist/http/http-response.d.ts +137 -0
  195. package/dist/http/http-response.js +166 -0
  196. package/dist/http/http-response.js.map +1 -0
  197. package/dist/http/index.d.ts +7 -0
  198. package/dist/http/index.js +4 -0
  199. package/dist/http/index.js.map +1 -0
  200. package/dist/http/request-options.d.ts +62 -0
  201. package/dist/http/request-options.js +2 -0
  202. package/dist/http/request-options.js.map +1 -0
  203. package/dist/modules/index.d.ts +2 -0
  204. package/dist/modules/index.js +2 -0
  205. package/dist/modules/index.js.map +1 -0
  206. package/dist/modules/installed-modules.d.ts +86 -0
  207. package/dist/modules/installed-modules.js +135 -0
  208. package/dist/modules/installed-modules.js.map +1 -0
  209. package/docs/README.md +43 -0
  210. package/docs/concepts/areas.md +38 -0
  211. package/docs/concepts/auth.md +144 -0
  212. package/docs/concepts/config.md +103 -0
  213. package/docs/concepts/dataset.md +184 -0
  214. package/docs/concepts/environment.md +59 -0
  215. package/docs/concepts/fixtures.md +116 -0
  216. package/docs/concepts/graphql.md +76 -0
  217. package/docs/concepts/http.md +88 -0
  218. package/docs/concepts/modules.md +64 -0
  219. package/docs/concepts/secrets.md +50 -0
  220. package/docs/contributing/architecture.md +74 -0
  221. package/docs/contributing/conventions.md +39 -0
  222. package/docs/contributing/documentation.md +26 -0
  223. package/docs/contributing/releasing.md +90 -0
  224. package/docs/examples/auth.ts +20 -0
  225. package/docs/examples/config.ts +36 -0
  226. package/docs/examples/dataset.ts +70 -0
  227. package/docs/examples/environment.ts +8 -0
  228. package/docs/examples/fixtures.ts +41 -0
  229. package/docs/examples/getting-started.ts +22 -0
  230. package/docs/examples/graphql-codegen.ts +9 -0
  231. package/docs/examples/graphql.ts +32 -0
  232. package/docs/examples/http.ts +18 -0
  233. package/docs/examples/modules.ts +19 -0
  234. package/docs/examples/secrets.ts +11 -0
  235. package/docs/examples/sign-in-strategies.ts +22 -0
  236. package/docs/examples/tsconfig.json +10 -0
  237. package/docs/getting-started.md +167 -0
  238. package/docs/guides/generating-types.md +76 -0
  239. package/docs/guides/qa-agents.md +224 -0
  240. package/package.json +156 -4
  241. package/templates/suite/.mcp.json +16 -0
  242. package/templates/suite/.qa/project.json +70 -0
  243. package/templates/suite/CLAUDE.template.md +62 -0
  244. package/templates/suite/allurerc.mjs +13 -0
  245. package/templates/suite/arrange/context.ts +15 -0
  246. package/templates/suite/arrange/index.ts +69 -0
  247. package/templates/suite/arrange/security.ts +78 -0
  248. package/templates/suite/biome.template.json +12 -0
  249. package/templates/suite/builders/security.ts +46 -0
  250. package/templates/suite/codegen.ts +27 -0
  251. package/templates/suite/env.example +10 -0
  252. package/templates/suite/env.ts +25 -0
  253. package/templates/suite/fixtures/index.ts +96 -0
  254. package/templates/suite/gitignore +13 -0
  255. package/templates/suite/pages/README.md +10 -0
  256. package/templates/suite/playwright.config.ts +48 -0
  257. package/templates/suite/scripts/generate-rest-types.ts +16 -0
  258. package/templates/suite/support/require-fields.ts +53 -0
  259. package/templates/suite/support/shopper.ts +51 -0
  260. package/templates/suite/support/store.ts +33 -0
  261. package/templates/suite/support/unique-id.ts +11 -0
  262. package/templates/suite/support/users.ts +6 -0
  263. package/templates/suite/tests/restapi/security/sign-in.spec.ts +23 -0
  264. package/templates/suite/tsconfig.json +33 -0
@@ -0,0 +1,103 @@
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
+ | Fixture titles, such as signing in as the administrator | Steps |
96
+ | A test skipped for its required modules | A skipped test, with the reason |
97
+ | Errors, with secrets masked | The failure message |
98
+
99
+ Steps and attachments, such as a seed log, come from the test suite.
100
+
101
+ The report groups tests by project, file and `describe` block, so a test directory organized by area gives a
102
+ structured report without labels. For other metadata, use Playwright tags and annotations, which every reporter
103
+ understands, such as `test("…", { tag: "@smoke" })`.
@@ -0,0 +1,184 @@
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
+ The `skipped` events come before `started`. A `failed` event comes just before the error is thrown. For a collection,
103
+ it has the counts reached so far and the record or request that failed. The manifest is invalid when an entry breaks
104
+ the rules above, or when the installed version of a module cannot be compared with its range; the error names the
105
+ collection. The test suite decides how the events look, such as coloured counts on the console and plain text in a
106
+ log it attaches to the report.
107
+
108
+ An error thrown by `onEvent` stops the run, and names the event. When the listener fails while it reports a failure,
109
+ the run throws an `AggregateError` with the failure of the run first, so a bug in the listener does not hide why the
110
+ seed failed.
111
+
112
+ <!-- example: ../examples/dataset.ts -->
113
+ ```ts
114
+ import type { Manifest, SeedEvent, SeedSummary } from "@virtocommerce/test-automation-framework/dataset";
115
+ import type { HttpClient } from "@virtocommerce/test-automation-framework/http";
116
+
117
+ import { fileURLToPath } from "node:url";
118
+
119
+ import {
120
+ envPlaceholder,
121
+ loadDataset,
122
+ parseCollectionNames,
123
+ recordPlaceholder,
124
+ seedDataset,
125
+ } from "@virtocommerce/test-automation-framework/dataset";
126
+ import { InstalledModules } from "@virtocommerce/test-automation-framework/modules";
127
+
128
+ const CATALOG = { id: "VirtoCommerce.Catalog", minVersion: "3.1051.0" };
129
+ const SHIPPING = { id: "VirtoCommerce.Shipping", minVersion: "3.1010.0" };
130
+
131
+ export const MANIFEST = {
132
+ catalogs: { module: CATALOG, method: "POST", path: "/api/catalog/catalogs", send: "each" },
133
+ categories: {
134
+ module: CATALOG,
135
+ method: "POST",
136
+ path: "/api/catalog/categories",
137
+ send: "each",
138
+ key: "code",
139
+ parentField: "parentId",
140
+ },
141
+ shippingMethods: {
142
+ module: SHIPPING,
143
+ method: "PUT",
144
+ path: "/api/shipping",
145
+ send: "each",
146
+ key: "code",
147
+ storedIdFrom: {
148
+ searchPath: "/api/shipping/search",
149
+ criteria: { storeId: envPlaceholder("STORE_ID"), codes: [recordPlaceholder("code")] },
150
+ match: "code",
151
+ },
152
+ },
153
+ } as const satisfies Manifest;
154
+
155
+ type Catalog = { readonly id: string; readonly name: string };
156
+
157
+ const PLACEHOLDERS = { STORE_ID: "B2B-store" };
158
+
159
+ export const dataset = loadDataset<typeof MANIFEST, { readonly catalogs: Catalog }>({
160
+ manifest: MANIFEST,
161
+ dataDir: fileURLToPath(new URL("data", import.meta.url)),
162
+ placeholders: PLACEHOLDERS,
163
+ });
164
+
165
+ export function catalogName(id: string): string {
166
+ return dataset.catalogs.get(id).name;
167
+ }
168
+
169
+ export async function seed(
170
+ admin: HttpClient,
171
+ only: string | undefined,
172
+ onEvent: (event: SeedEvent) => void,
173
+ ): Promise<SeedSummary<typeof MANIFEST>> {
174
+ return seedDataset({
175
+ http: admin,
176
+ manifest: MANIFEST,
177
+ dataset,
178
+ installed: await InstalledModules.read(admin),
179
+ only: parseCollectionNames(MANIFEST, only),
180
+ placeholders: PLACEHOLDERS,
181
+ onEvent,
182
+ });
183
+ }
184
+ ```
@@ -0,0 +1,59 @@
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 certificates of the platform and the frontends |
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_TAG` (`@platform-defect`), see [run options](config.md#run-options) |
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
+ The administrator is required, because a test suite cannot run without it: the seed writes the dataset as the
26
+ administrator, the installed modules that gate collections and tests are read with its token, and `workerAdmin`
27
+ arranges the data that the tests of a file share.
28
+
29
+ ## Extending the variables
30
+
31
+ A test suite extends `envSchema` with its own variables and can redefine a variable to change its default:
32
+
33
+ <!-- example: ../examples/environment.ts -->
34
+ ```ts
35
+ import { absoluteUrl, envSchema, parseEnv, positiveInt } from "@virtocommerce/test-automation-framework/core";
36
+
37
+ export const suiteEnvSchema = envSchema.extend({
38
+ API_WORKERS: positiveInt.default(8),
39
+ MAILBOX_URL: absoluteUrl,
40
+ });
41
+
42
+ export const env = parseEnv(suiteEnvSchema);
43
+ ```
44
+
45
+ Use the schemas from `@virtocommerce/test-automation-framework/core` for the values: `nonBlankString`, `absoluteUrl`,
46
+ `originUrl`, `positiveInt`, `booleanString` and `secretString`.
47
+
48
+ Stores are not environment variables, because a solution can have several stores. A test suite describes its stores
49
+ in its own configuration.
50
+
51
+ ## Parsing
52
+
53
+ `parseEnv` parses the variables with a schema and returns them typed:
54
+
55
+ - An empty variable counts as unset, so its default applies. A line such as `API_WORKERS=` in a `.env` file does not
56
+ fail.
57
+ - When variables are invalid, it throws one error that lists each of them. The message does not contain the values,
58
+ so it is safe to print even for passwords.
59
+ - Variables that the schema does not name are left out.
@@ -0,0 +1,116 @@
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
+ A frontend that signs users in another way than the Virto Commerce frontend passes its sign-in strategy as the second
57
+ argument, `defaultFixtures(env, { frontendSignIn })`, and `frontendSessions` uses it. See
58
+ [Authentication](auth.md#sign-in-strategies).
59
+
60
+ ## Worker fixtures
61
+
62
+ A worker creates these once and shares them between its tests:
63
+
64
+ | Fixture | Is |
65
+ | ------------------ | -------------------------------------------------------------------------------- |
66
+ | `env` | The environment variables of the test suite |
67
+ | `workerHttp` | A client of the platform without authentication, for the work of the worker |
68
+ | `tokens` | The `TokenManager` of the worker. It signs users out when the worker ends |
69
+ | `workerAdmin` | A client signed in as the administrator, for data that the tests of a file share |
70
+ | `frontendSessions` | The `BrowserSessions` of the frontends, with the `frontendSignIn` strategy |
71
+ | `platformSessions` | The `BrowserSessions` of the platform's admin UI, with `platformAdminSignIn` |
72
+
73
+ Both sessions are signed out when the worker ends.
74
+
75
+ The other fixtures read the platform's address and the administrator from `env`. A test suite that overrides `env`
76
+ points them all elsewhere.
77
+
78
+ ## Test fixtures
79
+
80
+ | Fixture | Is |
81
+ | -------------- | --------------------------------------------------------------------------------------- |
82
+ | `apiContext` | The request context of the test, disposed of after it |
83
+ | `http` | A client of the platform without authentication |
84
+ | `signIn` | Returns a client signed in as a user. The token is kept for the worker |
85
+ | `graphql` | A GraphQL client of the platform without authentication |
86
+ | `modules` | The modules that the tests need, an option set with `test.use` |
87
+ | `checkModules` | Runs for every test and skips it when its `modules` do not qualify; tests do not use it |
88
+
89
+ Users sign in once for each worker. Each test has its own request context, so cookies of one test never reach another.
90
+
91
+ ## Required modules
92
+
93
+ A test whose `modules` are not installed, or not in their range of versions, is skipped, and the reason names each
94
+ module. A version that cannot be compared fails the test. The modules are read, as the administrator, only for a test
95
+ that names requirements, so a worker whose tests need none never signs the administrator in to check them.
96
+
97
+ `modules` is a record of `ModuleRequirement`s, so a test names the test suite's constants with shorthand properties,
98
+ such as `{ QUOTES, XPICKUP }`. The keys are only labels; the reason names the modules. These are the same
99
+ constants that the dataset manifest uses, so a collection that the seed skips and the tests that use its data skip for
100
+ the same reason.
101
+
102
+ An inner `test.use` replaces the requirements of the outer one. To keep them, spread them: `{ ...OUTER, QUOTES }`.
103
+
104
+ ## Browser sessions
105
+
106
+ Browser tests start signed in, so they skip the sign-in pages. The test suite overrides `context` and applies a storage
107
+ state of `frontendSessions` or `platformSessions`, as the example does. See
108
+ [Authentication](auth.md#browser-sessions) for how the sessions sign in and when they sign out.
109
+
110
+ A user that a test deletes must be signed out first: call `tokens.signOut`, `frontendSessions.signOut` and
111
+ `platformSessions.signOut`. Otherwise the worker fails to revoke a token of the deleted user when it ends.
112
+
113
+ ## Traces
114
+
115
+ Every request appears in the trace of the test that runs at the time. Requests of the worker, such as sign-ins and
116
+ reading the modules, appear in the trace of the test that first needs them.
@@ -0,0 +1,76 @@
1
+ # GraphQL
2
+
3
+ The `graphql` area runs typed GraphQL operations, such as the operations of the Virto Commerce API (xAPI).
4
+
5
+ ## Documents
6
+
7
+ The framework does not define operations. A test suite generates typed documents from its operations with GraphQL
8
+ Code Generator, in the string document mode, and passes them to the client. Each document carries the types of its
9
+ result and its variables, so the data and the variables are typed without a GraphQL package in the framework.
10
+
11
+ For the setup, see [Generating types](../guides/generating-types.md#graphql). `graphqlCodegenConfig` returns the
12
+ configuration that produces documents the client accepts.
13
+
14
+ ## The client
15
+
16
+ `GraphqlClient` sends operations through an `HttpClient`, usually a signed-in one, so sign-in, token renewal, the
17
+ single origin and test traces work as for any request. The endpoint is `/graphql` unless another path is given.
18
+
19
+ | Method | Returns | Throws a `GraphqlError` when |
20
+ | ------------ | ----------------------------------- | ----------------------------------------------------------- |
21
+ | `execute` | The data of the response | The response has errors, even with partial data, or no data |
22
+ | `executeRaw` | The data, the errors and the status | Never; use it in tests that check errors or partial data |
23
+
24
+ - Variables are optional only for an operation without required variables. Each string in them can be a `Secret`,
25
+ revealed only when the operation is sent.
26
+ - GraphQL errors are read from a response with any status, because a server can return them with a success status or,
27
+ for an invalid operation, with a 400 status.
28
+ - Both methods throw an `HttpError` for a failed status without GraphQL errors, and for a body that is not a GraphQL
29
+ response.
30
+
31
+ <!-- example: ../examples/graphql.ts -->
32
+ ```ts
33
+ import type { GraphqlDocument } from "@virtocommerce/test-automation-framework/graphql";
34
+ import type { HttpClient } from "@virtocommerce/test-automation-framework/http";
35
+
36
+ import { expect } from "@playwright/test";
37
+ import { GraphqlClient, GraphqlError } from "@virtocommerce/test-automation-framework/graphql";
38
+
39
+ type Cart = { readonly cart: { readonly id: string; readonly itemsCount: number } };
40
+ type CartVariables = { readonly storeId: string; readonly userId: string };
41
+
42
+ export async function countCartItems(
43
+ signedIn: HttpClient,
44
+ getCart: GraphqlDocument<Cart, CartVariables>,
45
+ variables: CartVariables,
46
+ ): Promise<number> {
47
+ const { cart } = await new GraphqlClient(signedIn).execute(getCart, variables);
48
+ return cart.itemsCount;
49
+ }
50
+
51
+ export async function expectRejectedWithCode(
52
+ signedIn: HttpClient,
53
+ getCart: GraphqlDocument<Cart, CartVariables>,
54
+ variables: CartVariables,
55
+ code: string,
56
+ ): Promise<void> {
57
+ const result = await new GraphqlClient(signedIn).executeRaw(getCart, variables);
58
+
59
+ expect(result.errors.map((entry) => entry.extensions?.["code"])).toContain(code);
60
+ }
61
+
62
+ export function isMissingObject(error: unknown): boolean {
63
+ return GraphqlError.hasCode(error, "NOT_FOUND", "OBJECT_NOT_FOUND");
64
+ }
65
+ ```
66
+
67
+ ## Errors
68
+
69
+ `GraphqlError` represents a response that has errors, or one that has no data.
70
+
71
+ - The message names the operation and the HTTP status, then lists each error with its code and path, such as
72
+ `- [VALIDATION_ERROR] Quantity must be positive (at addItem)`.
73
+ - `errors` holds the error entries of the response, including fields that the server adds, such as `locations`.
74
+ - Secrets are masked in the message and in the entries, because servers often quote variable values in their errors.
75
+ - `GraphqlError.hasCode(error, ...codes)` tells whether an unknown value is a `GraphqlError` with an entry whose
76
+ `extensions.code` is one of the codes.
@@ -0,0 +1,88 @@
1
+ # HTTP
2
+
3
+ `HttpClient` sends requests through a Playwright request context, so the requests appear in test traces. It returns
4
+ an `HttpResponse` whose body has already been read.
5
+
6
+ ## The client
7
+
8
+ A client sends requests to one origin, given when it is created. It is immutable: `withHeaders` and
9
+ `withAuthentication` return a new client and leave the original unchanged.
10
+
11
+ - **One origin.** A path that resolves to another origin is refused before anything is sent, and redirects are not
12
+ followed. Headers, including sign-in headers, never reach another host.
13
+ - **No exceptions for a status.** The client returns every response, whatever its status. The response methods check
14
+ the status, as described below.
15
+ - **No retries.** A request is sent once. When no response arrives, the client throws an error with secrets masked.
16
+ The only resend is after a 401 status on a client with authentication, once the sign-in has been renewed.
17
+ - **Secrets revealed only when sent.** The query, headers and body accept `Secret` values.
18
+
19
+ ### Headers
20
+
21
+ Headers are merged in this order, and a later header replaces an earlier one of the same name, whatever its case:
22
+
23
+ 1. Headers from `withHeaders`, in the order the calls were made.
24
+ 2. Sign-in headers from `withAuthentication`.
25
+ 3. The content type of a JSON body.
26
+ 4. Headers given with the request.
27
+
28
+ A header provider passed to `withHeaders` is called for each request, so values that change are picked up.
29
+
30
+ ### Bodies
31
+
32
+ A request has at most one body:
33
+
34
+ | Option | Sent as |
35
+ | ----------- | --------------------------------------------------------------------------------------- |
36
+ | `json` | JSON with the `application/json` content type, with each `Secret` at any depth revealed |
37
+ | `form` | URL-encoded form fields |
38
+ | `multipart` | Multipart form data with text fields and files |
39
+
40
+ For `form` and `multipart` bodies, a content type set with `withHeaders` is ignored, so the body is encoded correctly.
41
+
42
+ ## The response
43
+
44
+ | Member | Returns | Throws an `HttpError` when |
45
+ | ----------------------- | ---------------------------------------------------------------- | ----------------------------------------------------------- |
46
+ | `ok` | Whether the status is a success status (2xx) | Never |
47
+ | `expectOk()` | The response | The status is not a success status |
48
+ | `json<T>()` | The body parsed as JSON, not checked at run time | The status is not a success status, or the body is not JSON |
49
+ | `parse(schema)` | The body validated by a schema | As for `json`, or the body does not match the schema |
50
+ | `optionalJson<T>()` | As for `json`, or `undefined` for an empty or `null` body | As for `json` |
51
+ | `parseOptional(schema)` | As for `parse`, or `undefined` for an empty or `null` body | As for `parse` |
52
+ | `errorJson<T>()` | The body of an error response parsed as JSON, for negative tests | The status is a success status, or the body is not JSON |
53
+ | `toError(reason)` | An `HttpError` that describes the response, for other checks | Never; the caller throws it |
54
+
55
+ Because `json` and `parse` require a success status and `errorJson` requires an error status, a missed status check
56
+ cannot hide a failure.
57
+
58
+ A 404 status is an error for `optionalJson` and `parseOptional` too, because a server also returns it for an unknown
59
+ route. For an endpoint that answers a missing record with 404, pass `{ allow404: true }`, and the method returns
60
+ `undefined` for a 404 status as well.
61
+
62
+ <!-- example: ../examples/http.ts -->
63
+ ```ts
64
+ import type { HttpClient } from "@virtocommerce/test-automation-framework/http";
65
+
66
+ import { expect } from "@playwright/test";
67
+ import { object, string } from "zod";
68
+
69
+ const storeSchema = object({ id: string(), name: string() });
70
+
71
+ export async function readStore(client: HttpClient, id: string) {
72
+ const response = await client.get(`/api/stores/${encodeURIComponent(id)}`);
73
+ return response.parse(storeSchema);
74
+ }
75
+
76
+ export async function rejectionOf(client: HttpClient, path: string, body: unknown) {
77
+ const response = await client.post(path, { json: body });
78
+
79
+ expect(response.ok).toBe(false);
80
+ return response.errorJson();
81
+ }
82
+ ```
83
+
84
+ ## Errors
85
+
86
+ An `HttpError` names the request and the status, and quotes the body. The URL in the message has no query or
87
+ fragment, the body is shortened after 1000 characters, and secrets are masked in the message and in `error.body`.
88
+ `HttpError.hasStatus(error, 404, 409)` tells whether an unknown value is an `HttpError` with one of the statuses.