webship-js 2.0.10 → 2.0.12

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 (248) hide show
  1. package/.circleci/config.yml +10 -1
  2. package/.drone.yml +7 -7
  3. package/.github/ISSUE_TEMPLATE/issue.md +37 -0
  4. package/.github/PULL_REQUEST_TEMPLATE.md +24 -0
  5. package/.github/workflows/github-actions.yml +101 -4
  6. package/.gitlab-ci.yml +9 -4
  7. package/.harness/webship-js-pipeline.yml +5 -6
  8. package/.semaphore/semaphore.yml +6 -9
  9. package/.teamcity/settings.kts +7 -6
  10. package/.travis.yml +6 -1
  11. package/AGENTS.md +1 -1
  12. package/CLAUDE.md +69 -24
  13. package/Jenkinsfile +5 -3
  14. package/README.md +13 -1
  15. package/azure-pipelines.yml +17 -8
  16. package/bamboo-specs/bamboo.yml +9 -15
  17. package/bin/generate-reports.js +51 -7
  18. package/bin/init-webship.js +127 -23
  19. package/bitbucket-pipelines.yml +5 -1
  20. package/buildspec.yml +6 -7
  21. package/cloudbuild.yaml +28 -12
  22. package/codefresh.yml +6 -6
  23. package/cucumber.js +46 -11
  24. package/docs/00-quick-start.md +38 -7
  25. package/docs/02-bbr-smart-waits.md +21 -10
  26. package/docs/03-selector-registry.md +24 -0
  27. package/docs/04-step-reference.md +53 -27
  28. package/docs/05-web-first-assertions.md +6 -0
  29. package/docs/07-auth-state.md +1 -1
  30. package/docs/08-clock-mocking.md +21 -2
  31. package/docs/09-api-testing.md +40 -2
  32. package/docs/10-accessibility.md +2 -0
  33. package/docs/11-debugging.md +24 -1
  34. package/docs/12-ai-agent-guide.md +8 -1
  35. package/docs/13-faq.md +75 -1
  36. package/docs/14-recipes-cookbook.md +2 -0
  37. package/docs/15-tag-conventions.md +5 -1
  38. package/docs/16-ci-cd.md +161 -124
  39. package/docs/README.md +5 -5
  40. package/docs/advanced-screenshots.md +3 -1
  41. package/docs/api-step-definitions.md +16 -2
  42. package/docs/global-settings.md +70 -18
  43. package/docs/install-webship-js/ddev-webship-js.md +3 -0
  44. package/docs/install-webship-js.md +16 -2
  45. package/docs/step-definitions/then-i-should-see.md +14 -1
  46. package/docs/step-definitions/then-item-checkbox.md +2 -0
  47. package/docs/step-definitions/when-i-fill.md +4 -0
  48. package/docs/step-definitions/when-i-select-option-select-list.md +2 -0
  49. package/examples/a11y-legacy-widget.html +34 -0
  50. package/examples/auth-state.html +42 -0
  51. package/examples/choice-controls.html +29 -0
  52. package/examples/clock.html +33 -0
  53. package/examples/datetime-fields.html +52 -0
  54. package/examples/downloads/webship-archive.zip +0 -0
  55. package/examples/downloads/webship-notes.txt +4 -0
  56. package/examples/downloads/webship-report.csv +4 -0
  57. package/examples/downloads.html +16 -0
  58. package/examples/element-selector-hint.html +16 -0
  59. package/examples/element-viewport.html +42 -0
  60. package/examples/field-states.html +27 -0
  61. package/examples/field-types.html +98 -0
  62. package/examples/fill-in-empty.html +26 -0
  63. package/examples/fill-unreachable.html +27 -0
  64. package/examples/iframe-inner.html +20 -0
  65. package/examples/iframe-nested.html +16 -0
  66. package/examples/iframe-newsletter.html +29 -0
  67. package/examples/iframe-order.html +26 -0
  68. package/examples/iframe-outer.html +15 -0
  69. package/examples/iframe.html +21 -0
  70. package/examples/javascript-errors.html +35 -0
  71. package/examples/links.html +1 -0
  72. package/examples/metatags.html +18 -0
  73. package/examples/mouse-and-pointer.html +83 -0
  74. package/examples/multi-value-fields.html +54 -0
  75. package/examples/native-dialogs.html +8 -0
  76. package/examples/network.html +83 -0
  77. package/examples/registered-names.html +15 -0
  78. package/examples/scroll-horizontal.html +50 -0
  79. package/examples/select-by-label.html +33 -0
  80. package/examples/selectors-position.html +29 -0
  81. package/examples/settle-budget.html +21 -0
  82. package/examples/sorted-tables.html +38 -0
  83. package/examples/storage.html +57 -0
  84. package/examples/text-matching.html +48 -0
  85. package/examples/text-order.html +25 -0
  86. package/examples/touch.html +22 -0
  87. package/examples/viewport-size.html +24 -0
  88. package/examples/viewport-top.html +36 -0
  89. package/examples/wait-conditions.html +69 -0
  90. package/examples/web-first.html +99 -0
  91. package/package.json +24 -2
  92. package/playwright.config.ts +3 -1
  93. package/tests/assets/catalog.xml +19 -0
  94. package/tests/assets/feed-namespaced.xml +13 -0
  95. package/tests/assets/sitemap.xml +14 -0
  96. package/tests/assets/webship-site-expected.yaml +21 -0
  97. package/tests/assets/webship-site.schema.json +46 -0
  98. package/tests/assets/webship-site.yaml +21 -0
  99. package/tests/check-api-launch-url.js +106 -0
  100. package/tests/check-assets.js +103 -0
  101. package/tests/check-attachments.js +105 -0
  102. package/tests/check-breakpoints.js +117 -0
  103. package/tests/check-clock.js +143 -0
  104. package/tests/check-config.js +90 -0
  105. package/tests/check-context.js +215 -0
  106. package/tests/check-dry-run.js +104 -0
  107. package/tests/check-examples.js +241 -0
  108. package/tests/check-exit-report.js +141 -0
  109. package/tests/check-javascript-errors.js +105 -0
  110. package/tests/check-must-fail.js +85 -0
  111. package/tests/check-paths.js +82 -0
  112. package/tests/check-report.js +119 -0
  113. package/tests/check-scaffold.js +246 -0
  114. package/tests/check-screenshots.js +117 -0
  115. package/tests/check-settle-verbs.js +137 -0
  116. package/tests/check-time-limit.js +104 -0
  117. package/tests/check-video.js +156 -0
  118. package/tests/check-world.js +167 -0
  119. package/tests/features/a11y.feature +18 -0
  120. package/tests/features/api-base-url.feature +25 -0
  121. package/tests/features/api-form-data.feature +18 -0
  122. package/tests/features/api-json-paths.feature +24 -0
  123. package/tests/features/api-response-contains.feature +21 -0
  124. package/tests/features/api-response-header-presence.feature +17 -0
  125. package/tests/features/api-response-header.feature +17 -0
  126. package/tests/features/api-saved-placeholders.feature +37 -0
  127. package/tests/features/api-step-definitions-individual.feature +1 -1
  128. package/tests/features/api-tables.feature +40 -0
  129. package/tests/features/auth-state.feature +32 -0
  130. package/tests/features/breakpoints.feature +25 -0
  131. package/tests/features/choice-controls.feature +35 -0
  132. package/tests/features/clock.feature +27 -0
  133. package/tests/features/complete-api-testing-examples.feature +1 -1
  134. package/tests/features/cookie.feature +9 -0
  135. package/tests/features/datetime-field-lookup.feature +29 -0
  136. package/tests/features/dialog.feature +27 -0
  137. package/tests/features/element-selector-hint.feature +14 -0
  138. package/tests/features/element.feature +47 -0
  139. package/tests/features/field-state.feature +21 -0
  140. package/tests/features/field.feature +104 -0
  141. package/tests/features/file-download.feature +64 -0
  142. package/tests/features/fill-in-empty-value.feature +41 -0
  143. package/tests/features/fill-reachable.feature +13 -0
  144. package/tests/features/iframe-nested.feature +43 -0
  145. package/tests/features/iframe.feature +83 -0
  146. package/tests/features/javascript-tolerated-errors.feature +20 -0
  147. package/tests/features/javascript.feature +47 -0
  148. package/tests/features/link.feature +11 -0
  149. package/tests/features/metatag.feature +38 -0
  150. package/tests/features/modal-open.feature +13 -0
  151. package/tests/features/mouse-and-pointer.feature +86 -0
  152. package/tests/features/multi-value-field-lookup.feature +30 -0
  153. package/tests/features/network-mocking.feature +80 -0
  154. package/tests/features/registered-names.feature +14 -0
  155. package/tests/features/responsive.feature +27 -0
  156. package/tests/features/scroll-horizontal.feature +55 -0
  157. package/tests/features/select-by-label.feature +31 -0
  158. package/tests/features/selector-files.feature +14 -0
  159. package/tests/features/selectors-position.feature +41 -0
  160. package/tests/features/selectors-table-header.feature +35 -0
  161. package/tests/features/settle-budget.feature +11 -0
  162. package/tests/features/sorted-tables.feature +19 -0
  163. package/tests/features/storage-quoted-values.feature +26 -0
  164. package/tests/features/storage.feature +98 -0
  165. package/tests/features/test--then--i-see-locator.feature +13 -0
  166. package/tests/features/test--then--i-should--see-text-in-element.feature +9 -1
  167. package/tests/features/test--then--the-field-should-contain-value.feature +8 -0
  168. package/tests/features/text-matching.feature +38 -0
  169. package/tests/features/text-order.feature +14 -0
  170. package/tests/features/touch.feature +21 -0
  171. package/tests/features/video.feature +1 -0
  172. package/tests/features/viewport-top.feature +13 -0
  173. package/tests/features/wait.feature +89 -0
  174. package/tests/features/web-first.feature +100 -0
  175. package/tests/features/xml-namespaces.feature +34 -0
  176. package/tests/features/xml.feature +96 -0
  177. package/tests/features/yaml.feature +75 -0
  178. package/tests/must-fail/api-json-paths.feature +21 -0
  179. package/tests/must-fail/api-response-contains.feature +23 -0
  180. package/tests/must-fail/api-response-header-presence.feature +17 -0
  181. package/tests/must-fail/api-response-header.feature +21 -0
  182. package/tests/must-fail/api-without-base-url.feature +11 -0
  183. package/tests/must-fail/assertions.feature +96 -0
  184. package/tests/must-fail/breakpoints.feature +15 -0
  185. package/tests/must-fail/choice-controls.feature +25 -0
  186. package/tests/must-fail/clock.feature +11 -0
  187. package/tests/must-fail/datetime-field.feature +10 -0
  188. package/tests/must-fail/element-selector-hint.feature +17 -0
  189. package/tests/must-fail/field-state.feature +20 -0
  190. package/tests/must-fail/fill-field.feature +30 -0
  191. package/tests/must-fail/iframe-text.feature +17 -0
  192. package/tests/must-fail/modal-open.feature +26 -0
  193. package/tests/must-fail/multi-value-field.feature +18 -0
  194. package/tests/must-fail/registered-names.feature +25 -0
  195. package/tests/must-fail/select-list.feature +15 -0
  196. package/tests/must-fail/selector-files.feature +10 -0
  197. package/tests/must-fail/sorted-tables.feature +20 -0
  198. package/tests/must-fail/storage-before-a-page.feature +13 -0
  199. package/tests/must-fail/text-matching.feature +16 -0
  200. package/tests/must-fail/text-order.feature +15 -0
  201. package/tests/must-fail/viewport-top.feature +20 -0
  202. package/tests/must-fail/waits.feature +51 -0
  203. package/tests/must-fail/yaml-numbers.feature +48 -0
  204. package/tests/reports/README.md +2 -2
  205. package/tests/step-definitions/a11y.steps.js +36 -23
  206. package/tests/step-definitions/action.steps.js +22 -8
  207. package/tests/step-definitions/api.steps.js +349 -67
  208. package/tests/step-definitions/assertion.steps.js +327 -63
  209. package/tests/step-definitions/auth.steps.js +15 -18
  210. package/tests/step-definitions/clock.steps.js +22 -0
  211. package/tests/step-definitions/debug.steps.js +8 -0
  212. package/tests/step-definitions/dialog.steps.js +9 -2
  213. package/tests/step-definitions/element.steps.js +135 -18
  214. package/tests/step-definitions/field.steps.js +523 -80
  215. package/tests/step-definitions/file-download.steps.js +74 -10
  216. package/tests/step-definitions/form.steps.js +76 -29
  217. package/tests/step-definitions/iframe.steps.js +89 -29
  218. package/tests/step-definitions/input.steps.js +26 -7
  219. package/tests/step-definitions/javascript.steps.js +64 -22
  220. package/tests/step-definitions/modal.steps.js +79 -13
  221. package/tests/step-definitions/navigation.steps.js +14 -0
  222. package/tests/step-definitions/network.steps.js +15 -5
  223. package/tests/step-definitions/response.steps.js +6 -4
  224. package/tests/step-definitions/responsive.steps.js +26 -33
  225. package/tests/step-definitions/screenshot.steps.js +26 -9
  226. package/tests/step-definitions/scroll.steps.js +20 -0
  227. package/tests/step-definitions/selectors.steps.js +104 -51
  228. package/tests/step-definitions/storage.steps.js +41 -16
  229. package/tests/step-definitions/table.steps.js +81 -6
  230. package/tests/step-definitions/video.steps.js +52 -55
  231. package/tests/step-definitions/wait.steps.js +209 -54
  232. package/tests/step-definitions/web-first.steps.js +69 -35
  233. package/tests/step-definitions/webship.js +807 -128
  234. package/tests/step-definitions/xml.steps.js +124 -28
  235. package/tests/step-definitions/yaml.steps.js +90 -46
  236. package/.scratch/commit.txt +0 -14
  237. package/.scratch/docs.py +0 -42
  238. package/.scratch/echo-server.js +0 -8
  239. package/.scratch/echo.js +0 -35
  240. package/.scratch/echo.pid +0 -1
  241. package/.scratch/features/cookies.feature +0 -22
  242. package/.scratch/http.pid +0 -1
  243. package/.scratch/https.pid +0 -1
  244. package/.scratch/issue.md +0 -49
  245. package/.scratch/one.js +0 -2
  246. package/.scratch/one.json +0 -280
  247. package/.scratch/patch.py +0 -163
  248. package/.scratch/pr.md +0 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webship-js",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "Webship JS automated functional testing.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -19,9 +19,29 @@
19
19
  "test:chromium": "BROWSER=chromium cucumber-js --config cucumber.js",
20
20
  "test:firefox": "BROWSER=firefox cucumber-js --config cucumber.js",
21
21
  "test:webkit": "BROWSER=webkit cucumber-js --config cucumber.js",
22
+ "test:report": "node tests/check-report.js",
23
+ "test:attachments": "node tests/check-attachments.js",
22
24
  "test:headed": "HEADLESS=false cucumber-js --config cucumber.js",
25
+ "test:dry-run": "node tests/check-dry-run.js",
26
+ "test:api-launch-url": "node tests/check-api-launch-url.js",
27
+ "test:must-fail": "node tests/check-must-fail.js",
28
+ "test:js-errors": "node tests/check-javascript-errors.js",
29
+ "test:screenshots": "node tests/check-screenshots.js",
30
+ "test:config": "node tests/check-config.js",
31
+ "test:exit-report": "node tests/check-exit-report.js",
32
+ "test:breakpoints": "node tests/check-breakpoints.js",
33
+ "test:context": "node tests/check-context.js",
34
+ "test:video": "node tests/check-video.js",
35
+ "test:world": "node tests/check-world.js",
36
+ "test:clock": "node tests/check-clock.js",
37
+ "test:settle-verbs": "node tests/check-settle-verbs.js",
23
38
  "test:fast": "SLOW_MO=0 cucumber-js --config cucumber.js",
39
+ "test:assets": "node tests/check-assets.js",
40
+ "test:examples": "node tests/check-examples.js",
41
+ "test:paths": "node tests/check-paths.js",
42
+ "test:time-limit": "node tests/check-time-limit.js",
24
43
  "generate-reports": "node ./bin/generate-reports.js",
44
+ "test:scaffold": "node tests/check-scaffold.js",
25
45
  "start": "http-server examples -p 8080 -s"
26
46
  },
27
47
  "repository": {
@@ -39,6 +59,7 @@
39
59
  "@cucumber/cucumber": "^12",
40
60
  "@cucumber/pretty-formatter": "~1",
41
61
  "@types/node": "~20",
62
+ "@xmldom/xmldom": "^0.9.8",
42
63
  "ajv": "^8.20.0",
43
64
  "ajv-formats": "^3.0.1",
44
65
  "axe-core": "^4.11.4",
@@ -48,6 +69,7 @@
48
69
  "js-yaml": "^4.1.1",
49
70
  "playwright": "^1.58.2",
50
71
  "tsx": "^4.19.2",
51
- "typescript": "~5"
72
+ "typescript": "~5",
73
+ "xpath": "~0.0.34"
52
74
  }
53
75
  }
@@ -26,7 +26,9 @@ const config: PlaywrightConfig = {
26
26
  browser,
27
27
  launchOptions: {
28
28
  headless: process.env.HEADLESS !== 'false',
29
- // SLOW_MO env var: 0 in CI for speed, 800ms when watching headed runs.
29
+ // Pause before every browser action, in ms: 300 by default, 800 with
30
+ // HEADLESS=false so a headed run can be watched. SLOW_MO wins over both:
31
+ // SLOW_MO=0 for full speed (npm run test:fast), in CI too.
30
32
  slowMo: parseInt(process.env.SLOW_MO || (process.env.HEADLESS === 'false' ? '800' : '300'), 10),
31
33
  args: browser === 'chromium' ? chromiumArgs : [],
32
34
  },
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <catalog version="2.0" updated="2026-01-15">
3
+ <book id="bk101" lang="en">
4
+ <title>Testing with Webship-js</title>
5
+ <author>Webship</author>
6
+ <price currency="USD">29.90</price>
7
+ </book>
8
+ <book id="bk102" lang="en">
9
+ <title>Behaviour-driven development by example</title>
10
+ <author>Webship</author>
11
+ <price currency="EUR">24.50</price>
12
+ </book>
13
+ <book id="bk103" lang="fr">
14
+ <title>Les tests automatiques</title>
15
+ <author>Webship</author>
16
+ <price currency="EUR">19.00</price>
17
+ </book>
18
+ <status>published</status>
19
+ </catalog>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <feed xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
3
+ <title>Webship-js releases</title>
4
+ <atom:link href="https://example.com/feed.xml" rel="self"/>
5
+ <entry>
6
+ <title>First release</title>
7
+ <dc:creator>Webship</dc:creator>
8
+ </entry>
9
+ <entry>
10
+ <title>Second release</title>
11
+ <dc:creator>Webship</dc:creator>
12
+ </entry>
13
+ </feed>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
3
+ <url>
4
+ <loc>https://example.com/</loc>
5
+ <lastmod>2026-11-16</lastmod>
6
+ <image:image>
7
+ <image:loc>https://example.com/logo.png</image:loc>
8
+ </image:image>
9
+ </url>
10
+ <url>
11
+ <loc>https://example.com/about-us</loc>
12
+ <lastmod>2026-11-10</lastmod>
13
+ </url>
14
+ </urlset>
@@ -0,0 +1,21 @@
1
+ # What the site description should be; the status block changes on every save.
2
+ name: webship-site
3
+ namespace: production
4
+ version: 2
5
+ owner:
6
+ team: platform
7
+ contact: team@example.com
8
+ settings:
9
+ cache: true
10
+ languages:
11
+ - en
12
+ - fr
13
+ homepage: /welcome
14
+ pages:
15
+ - title: Home
16
+ path: /
17
+ - title: About us
18
+ path: /about-us
19
+ status:
20
+ updated: "2025-06-01T08:30:00Z"
21
+ revision: 7
@@ -0,0 +1,46 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Site description",
4
+ "type": "object",
5
+ "required": ["name", "namespace", "version", "owner", "pages"],
6
+ "properties": {
7
+ "name": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
8
+ "namespace": { "type": "string", "enum": ["production", "staging", "development"] },
9
+ "version": { "type": "integer", "minimum": 1 },
10
+ "owner": {
11
+ "type": "object",
12
+ "required": ["team", "contact"],
13
+ "properties": {
14
+ "team": { "type": "string" },
15
+ "contact": { "type": "string", "format": "email" }
16
+ }
17
+ },
18
+ "settings": {
19
+ "type": "object",
20
+ "properties": {
21
+ "cache": { "type": "boolean" },
22
+ "languages": { "type": "array", "items": { "type": "string", "minLength": 2, "maxLength": 2 } },
23
+ "homepage": { "type": "string" }
24
+ }
25
+ },
26
+ "pages": {
27
+ "type": "array",
28
+ "minItems": 1,
29
+ "items": {
30
+ "type": "object",
31
+ "required": ["title", "path"],
32
+ "properties": {
33
+ "title": { "type": "string" },
34
+ "path": { "type": "string", "pattern": "^/" }
35
+ }
36
+ }
37
+ },
38
+ "status": {
39
+ "type": "object",
40
+ "properties": {
41
+ "updated": { "type": "string", "format": "date-time" },
42
+ "revision": { "type": "integer" }
43
+ }
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,21 @@
1
+ # A small site description for the YAML steps.
2
+ name: webship-site
3
+ namespace: production
4
+ version: 2
5
+ owner:
6
+ team: platform
7
+ contact: team@example.com
8
+ settings:
9
+ cache: true
10
+ languages:
11
+ - en
12
+ - fr
13
+ homepage: /welcome
14
+ pages:
15
+ - title: Home
16
+ path: /
17
+ - title: About us
18
+ path: /about-us
19
+ status:
20
+ updated: "2026-01-15T10:00:00Z"
21
+ revision: 41
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Checks that the relative API base URL (`Given the API base URL is "/"`)
5
+ // is joined to the launch URL of the run, `worldParameters.launchUrl`, the
6
+ // one every other step uses, and not to the LAUNCH_URL variable alone: the
7
+ // run below sets its launch URL in its config only, serves a folder of its
8
+ // own on a free port, and asks for a file that only that folder holds.
9
+ //
10
+ // Usage: node tests/check-api-launch-url.js (npm run test:api-launch-url)
11
+
12
+ const fs = require('fs');
13
+ const net = require('net');
14
+ const os = require('os');
15
+ const path = require('path');
16
+ const { spawn, spawnSync } = require('child_process');
17
+
18
+ const ROOT = path.resolve(__dirname, '..');
19
+ const CUCUMBER = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
20
+
21
+ function freePort() {
22
+ return new Promise((resolve, reject) => {
23
+ const server = net.createServer();
24
+ server.on('error', reject);
25
+ server.listen(0, '127.0.0.1', () => {
26
+ const { port } = server.address();
27
+ server.close(() => resolve(port));
28
+ });
29
+ });
30
+ }
31
+
32
+ function waitForPort(port, ms) {
33
+ const deadline = Date.now() + ms;
34
+ return new Promise((resolve) => {
35
+ const attempt = () => {
36
+ const socket = net.connect(port, '127.0.0.1');
37
+ socket.on('connect', () => { socket.destroy(); resolve(true); });
38
+ socket.on('error', () => {
39
+ socket.destroy();
40
+ if (Date.now() > deadline) resolve(false);
41
+ else setTimeout(attempt, 200);
42
+ });
43
+ };
44
+ attempt();
45
+ });
46
+ }
47
+
48
+ async function main() {
49
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-api-launch-url-'));
50
+ const report = path.join(tmp, 'api.json');
51
+ const config = path.join(tmp, 'cucumber.js');
52
+ const feature = path.join(tmp, 'api.feature');
53
+ const site = path.join(tmp, 'site');
54
+ fs.mkdirSync(site);
55
+ fs.writeFileSync(path.join(site, 'launch-url-check.json'), JSON.stringify({ served: 'by the launch URL of the config' }));
56
+ const port = await freePort();
57
+ const server = spawn(process.execPath, [path.join(ROOT, 'node_modules', 'http-server', 'bin', 'http-server'), site, '-p', String(port), '-a', '127.0.0.1', '-s'], { stdio: 'ignore' });
58
+ const problems = [];
59
+ try {
60
+ if (!await waitForPort(port, 15000)) throw new Error(`the examples server did not start on port ${port}`);
61
+ fs.writeFileSync(feature, [
62
+ 'Feature: The API base URL and the launch URL',
63
+ '',
64
+ ' Scenario: A relative base URL is joined to the launch URL of the config',
65
+ ' Given the API base URL is "/"',
66
+ ' When I send a GET request to "/launch-url-check.json"',
67
+ ' Then the API response code should be 200',
68
+ ' And the JSON response should have "served" equal to "by the launch URL of the config"',
69
+ '',
70
+ ].join('\n'));
71
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
72
+ const world = JSON.parse(JSON.stringify(base.worldParameters));
73
+ world.launchUrl = `http://127.0.0.1:${port}`;
74
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
75
+ requireModule: base.requireModule,
76
+ require: base.require,
77
+ paths: [feature],
78
+ format: [`json:${report}`],
79
+ worldParameters: world,
80
+ }) + ' };');
81
+ const env = Object.assign({ SLOW_MO: '0' }, process.env, { WEBSHIP_REPORT_DISABLE: '1', WEBSHIP_VIDEO: 'off', WEBSHIP_JS_ERROR_MODE: 'off', FORCE_COLOR: '0' });
82
+ delete env.LAUNCH_URL;
83
+ const run = spawnSync(process.execPath, [path.join(CUCUMBER, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
84
+ cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], env,
85
+ });
86
+ const steps = fs.existsSync(report)
87
+ ? JSON.parse(fs.readFileSync(report, 'utf8')).flatMap((f) => (f.elements || []).flatMap((s) => s.steps || [])).filter((s) => !s.hidden)
88
+ : [];
89
+ const failed = steps.find((s) => s.result.status !== 'passed');
90
+ if (!steps.length) problems.push(`the run wrote no report:\n${run.stdout}\n${run.stderr}`);
91
+ else if (failed) problems.push(`"${failed.name}" ${failed.result.status}: ${String(failed.result.error_message || '').split('\n').slice(0, 3).join(' ')}`);
92
+ } finally {
93
+ server.kill();
94
+ fs.rmSync(tmp, { recursive: true, force: true });
95
+ }
96
+ if (problems.length) {
97
+ console.error('The relative API base URL does not follow the launch URL of the config:\n - ' + problems.join('\n - '));
98
+ process.exit(1);
99
+ }
100
+ console.log('The relative API base URL follows the launch URL of the config (worldParameters.launchUrl).');
101
+ }
102
+
103
+ main().catch((error) => {
104
+ console.error(error.stack || String(error));
105
+ process.exit(1);
106
+ });
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Runs the steps that read a file by its name — the XML and YAML file steps
5
+ // and the attach step — in a project of their own, the way a project that
6
+ // installed webship-js runs them: its own tests/assets/, its own cucumber.js
7
+ // and playwright.config, the webship-js step definitions from elsewhere. A
8
+ // name is found in the project's tests/assets/, a path from the project root
9
+ // as written, and a file that is not there fails with a plain message.
10
+ //
11
+ // The pages are files of the project (file: URLs): no server is needed.
12
+ //
13
+ // Usage: node tests/check-assets.js (npm run test:assets)
14
+
15
+ const fs = require('fs');
16
+ const os = require('os');
17
+ const path = require('path');
18
+ const { spawnSync } = require('child_process');
19
+
20
+ const ROOT = path.resolve(__dirname, '..');
21
+ const project = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-assets-'));
22
+ const report = path.join(project, 'report.json');
23
+ const write = (file, content) => {
24
+ fs.mkdirSync(path.dirname(path.join(project, file)), { recursive: true });
25
+ fs.writeFileSync(path.join(project, file), content);
26
+ };
27
+
28
+ write('playwright.config.js', "module.exports = { browser: 'chromium', launchOptions: { headless: true }, contextOptions: {} };\n");
29
+ write('tests/assets/project-feed.xml', '<feed><title>Project feed</title></feed>\n');
30
+ write('tests/assets/project-config.yaml', 'name: project\nreplicas: 3\n');
31
+ write('tests/assets/project-upload.txt', 'A file of the project.\n');
32
+ write('fixtures/root-feed.xml', '<feed><title>Root feed</title></feed>\n');
33
+ write('upload.html', '<input type="file" id="file"><p id="picked">nothing</p><script>document.getElementById("file").addEventListener("change", function (e) { document.getElementById("picked").textContent = e.target.files[0].name; });</script>\n');
34
+ write('tests/features/assets.feature', [
35
+ 'Feature: Files of the project',
36
+ '',
37
+ ' Scenario: An XML file of the project\'s assets',
38
+ ' Given the response content from the file "project-feed.xml"',
39
+ ' Then the XML element "/feed/title" should be equal to "Project feed"',
40
+ '',
41
+ ' Scenario: A YAML file of the project\'s assets',
42
+ ' Given the YAML response content from the file "project-config.yaml"',
43
+ ' Then the YAML element "/name" should be equal to "project"',
44
+ '',
45
+ ' Scenario: An XML file named from the project root',
46
+ ' Given the response content from the file "fixtures/root-feed.xml"',
47
+ ' Then the XML element "/feed/title" should be equal to "Root feed"',
48
+ '',
49
+ ' Scenario: A file of the project\'s assets attached to a file field',
50
+ ' Given I am on "upload.html"',
51
+ ' When I attach the file "project-upload.txt" to "#file"',
52
+ ' Then "#picked" should have text "project-upload.txt"',
53
+ '',
54
+ ' Scenario: A file that is not there',
55
+ ' Given the response content from the file "no-such-feed.xml"',
56
+ '',
57
+ ].join('\n'));
58
+ write('cucumber.js', 'module.exports = { default: ' + JSON.stringify({
59
+ require: [path.join(ROOT, 'tests', 'step-definitions', '**', '*.js')],
60
+ paths: ['tests/features/assets.feature'],
61
+ format: [`json:${report}`],
62
+ worldParameters: { launchUrl: 'file://' + project + '/' },
63
+ }) + ' };\n');
64
+
65
+ spawnSync(process.execPath, [path.join(ROOT, 'node_modules', '@cucumber', 'cucumber', 'bin', 'cucumber.js')], {
66
+ cwd: project,
67
+ stdio: ['ignore', 'ignore', 'inherit'],
68
+ env: Object.assign({ SLOW_MO: '0' }, process.env, { WEBSHIP_REPORT_DISABLE: '1', WEBSHIP_VIDEO: 'off', WEBSHIP_JS_ERROR_MODE: 'off' }),
69
+ });
70
+
71
+ const problems = [];
72
+ if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
73
+ problems.push('The run wrote no report: cucumber-js did not start.');
74
+ } else {
75
+ const found = {};
76
+ for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
77
+ for (const scenario of f.elements || []) found[scenario.name] = scenario;
78
+ }
79
+ const failure = (scenario) => {
80
+ const step = (scenario.steps || []).filter((s) => !s.hidden).find((s) => s.result.status !== 'passed');
81
+ return step ? `${step.keyword}${step.name}: ${String(step.result.error_message || step.result.status).split('\n')[0]}` : '';
82
+ };
83
+ for (const name of ['An XML file of the project\'s assets', 'A YAML file of the project\'s assets', 'An XML file named from the project root', 'A file of the project\'s assets attached to a file field']) {
84
+ const scenario = found[name];
85
+ if (!scenario) { problems.push(`"${name}" did not run.`); continue; }
86
+ const why = failure(scenario);
87
+ if (why) problems.push(`"${name}" failed: ${why}`);
88
+ }
89
+ const missing = found['A file that is not there'];
90
+ const step = missing && (missing.steps || []).filter((s) => !s.hidden)[0];
91
+ const message = String((step && step.result.error_message) || '');
92
+ if (!step || step.result.status !== 'failed') problems.push('A missing file did not fail its step.');
93
+ else if (!message.includes('The file "no-such-feed.xml" was not found.')) problems.push(`A missing file failed with: ${message.split('\n')[0]}`);
94
+ else if (!/^\s*Hint: \S/m.test(message)) problems.push('The failure of a missing file carries no hint.');
95
+ else if (/ENOENT|^\s+at .+:\d+:\d+\)?$/m.test(message)) problems.push('The failure of a missing file shows ENOENT or a stack trace.');
96
+ }
97
+
98
+ fs.rmSync(project, { recursive: true, force: true });
99
+ if (problems.length) {
100
+ console.error('Files of a project:\n - ' + problems.join('\n - '));
101
+ process.exit(1);
102
+ }
103
+ console.log('Files of a project: read from its tests/assets/ and from its root, and a missing file fails plainly.');
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Runs the steps that print what they found and checks that the text reaches
5
+ // the cucumber JSON report as well as the console: a step's attachment is
6
+ // what the HTML report and a CI artifact show under it.
7
+ //
8
+ // - `I print accessibility violations`
9
+ // - `I print the full accessibility check`
10
+ //
11
+ // The page is written by the check itself (an image without an alt
12
+ // attribute), so no server is needed.
13
+ //
14
+ // Usage: node tests/check-attachments.js (npm run test:attachments)
15
+
16
+ const fs = require('fs');
17
+ const os = require('os');
18
+ const path = require('path');
19
+ const { spawnSync } = require('child_process');
20
+
21
+ const ROOT = path.resolve(__dirname, '..');
22
+ const CUCUMBER = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
23
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-attachments-'));
24
+ const report = path.join(tmp, 'attachments.json');
25
+ const config = path.join(tmp, 'cucumber.js');
26
+ const steps = path.join(tmp, 'page.steps.js');
27
+ const feature = path.join(tmp, 'attachments.feature');
28
+
29
+ fs.writeFileSync(steps, [
30
+ `const { Given } = require(${JSON.stringify(CUCUMBER)});`,
31
+ "Given('a page with an image without an alt attribute', async function () {",
32
+ " await this.page.setContent('<!doctype html><html lang=\"en\"><head><title>Attachments</title></head>' +",
33
+ " '<body><main><h1>Attachments</h1><img src=\"data:image/gif;base64,R0lGODlhAQABAAAAACw=\" width=\"10\" height=\"10\"></main></body></html>');",
34
+ '});',
35
+ '',
36
+ ].join('\n'));
37
+ fs.writeFileSync(feature, [
38
+ 'Feature: Printed findings reach the report',
39
+ '',
40
+ ' Scenario: The accessibility print steps',
41
+ ' Given a page with an image without an alt attribute',
42
+ ' Then I print accessibility violations',
43
+ ' And I print the full accessibility check',
44
+ '',
45
+ ].join('\n'));
46
+ const lines = { 'print accessibility violations': 5, 'print the full accessibility check': 6 };
47
+
48
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
49
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
50
+ requireModule: base.requireModule,
51
+ require: base.require.concat([steps]),
52
+ paths: [feature],
53
+ format: [`json:${report}`],
54
+ worldParameters: base.worldParameters,
55
+ }) + ' };');
56
+
57
+ const run = spawnSync(process.execPath, [path.join(CUCUMBER, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
58
+ cwd: ROOT,
59
+ encoding: 'utf8',
60
+ stdio: ['ignore', 'pipe', 'pipe'],
61
+ env: Object.assign({ SLOW_MO: '0' }, process.env, { WEBSHIP_REPORT_DISABLE: '1', WEBSHIP_VIDEO: 'off', WEBSHIP_JS_ERROR_MODE: 'off', FORCE_COLOR: '0' }),
62
+ });
63
+
64
+ /**
65
+ * The text of an embedding of the JSON report: cucumber-js writes the data
66
+ * of every attachment in base64.
67
+ */
68
+ function embeddedText(embedding) {
69
+ const data = String(embedding.data || '');
70
+ const decoded = Buffer.from(data, 'base64').toString('utf8');
71
+ return /image-alt|accessibility/i.test(decoded) ? decoded : data;
72
+ }
73
+
74
+ const problems = [];
75
+ if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
76
+ problems.push(`The run wrote no report: cucumber-js did not start.\n${run.stdout}\n${run.stderr}`);
77
+ } else {
78
+ const byLine = {};
79
+ for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
80
+ for (const scenario of f.elements || []) {
81
+ for (const step of (scenario.steps || []).filter((s) => !s.hidden)) byLine[step.line] = step;
82
+ }
83
+ }
84
+ for (const [name, line] of Object.entries(lines)) {
85
+ const step = byLine[line];
86
+ if (!step || !step.result || step.result.status !== 'passed') {
87
+ problems.push(`"${name}" (line ${line}) did not pass: ${step && step.result ? step.result.status : 'missing'} ${(step && step.result && step.result.error_message) || ''}`);
88
+ continue;
89
+ }
90
+ const texts = (step.embeddings || []).filter((e) => /^text\//.test(e.mime_type)).map(embeddedText);
91
+ if (!texts.some((text) => /image-alt|image\(s\) without an alt attribute/i.test(text))) {
92
+ problems.push(`"${name}" (line ${line}) attached nothing about the image without alt to the JSON report (${texts.length} text attachment(s)).`);
93
+ }
94
+ }
95
+ if (!/image-alt|without an alt attribute/i.test(run.stdout)) {
96
+ problems.push('The print steps no longer print their findings to the console.');
97
+ }
98
+ }
99
+
100
+ fs.rmSync(tmp, { recursive: true, force: true });
101
+ if (problems.length) {
102
+ console.error('Printed findings in the report:\n - ' + problems.join('\n - '));
103
+ process.exit(1);
104
+ }
105
+ console.log('Printed findings in the report: both accessibility print steps attach what they print to their step, and still print it.');
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Runs scenarios with a cucumber.js that names its own breakpoints (one of
5
+ // them marked `default: true`, no `desktop`, no `mobile`) and with
6
+ // WEBSHIP_SELECTORS_BREAKPOINTS set, and checks the size each step and tag
7
+ // opens at: every one of them reads the same registry (the built-in names,
8
+ // then worldParameters.selectors.breakpoints, then the environment variable,
9
+ // then the names a scenario adds).
10
+ //
11
+ // The scenarios read the size of a blank page, so no server is needed.
12
+ //
13
+ // Usage: node tests/check-breakpoints.js (npm run test:breakpoints)
14
+
15
+ const fs = require('fs');
16
+ const os = require('os');
17
+ const path = require('path');
18
+ const { spawnSync } = require('child_process');
19
+
20
+ const ROOT = path.resolve(__dirname, '..');
21
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-breakpoints-'));
22
+ const report = path.join(tmp, 'breakpoints.json');
23
+ const config = path.join(tmp, 'cucumber.js');
24
+ const steps = path.join(tmp, 'breakpoints.steps.js');
25
+ const feature = path.join(tmp, 'breakpoints.feature');
26
+
27
+ const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
28
+ fs.writeFileSync(steps, [
29
+ `const { Then } = require(${JSON.stringify(cucumber)});`,
30
+ "Then('the window should be {int} by {int}', async function (width, height) {",
31
+ ' const size = await this.page.evaluate(() => `${window.innerWidth} by ${window.innerHeight}`);',
32
+ ' if (size !== `${width} by ${height}`) throw new Error(`The window is ${size}.`);',
33
+ '});',
34
+ '',
35
+ ].join('\n'));
36
+ fs.writeFileSync(feature, [
37
+ 'Feature: Breakpoints from the configuration and the environment',
38
+ '',
39
+ ' @mobile',
40
+ ' Scenario: The @mobile tag reads WEBSHIP_SELECTORS_BREAKPOINTS',
41
+ ' Then the window should be 360 by 640',
42
+ '',
43
+ ' @desktop',
44
+ ' Scenario: The @desktop tag opens at the breakpoint marked default',
45
+ ' Then the window should be 992 by 768',
46
+ '',
47
+ ' Scenario: The set-the-viewport step reads WEBSHIP_SELECTORS_BREAKPOINTS',
48
+ ' When I set the viewport to the "tablet" breakpoint',
49
+ ' Then the window should be 800 by 600',
50
+ '',
51
+ ' Scenario: The viewing-the-site step keeps the configured names beside the environment ones',
52
+ ' When I am viewing the site on a "wide" screen',
53
+ ' Then the window should be 1300 by 800',
54
+ '',
55
+ " Scenario: A scenario's own breakpoints keep the configured ones",
56
+ ' Given the following responsive breakpoints:',
57
+ ' | pocket | 320 | 480 |',
58
+ ' When I set the viewport to the "wide" breakpoint',
59
+ ' Then the window should be 1300 by 800',
60
+ ' When I am viewing the site on a "pocket" device',
61
+ ' Then the window should be 320 by 480',
62
+ '',
63
+ ].join('\n'));
64
+
65
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
66
+ const world = JSON.parse(JSON.stringify(base.worldParameters));
67
+ world.selectors = Object.assign({}, world.selectors, {
68
+ breakpoints: {
69
+ lg: { width: 992, height: 768, default: true },
70
+ wide: { width: 1300, height: 800 },
71
+ },
72
+ });
73
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
74
+ requireModule: base.requireModule,
75
+ require: base.require.concat([steps]),
76
+ paths: [feature],
77
+ format: [`json:${report}`],
78
+ worldParameters: world,
79
+ }) + ' };');
80
+
81
+ spawnSync(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
82
+ cwd: ROOT,
83
+ stdio: ['ignore', 'ignore', 'inherit'],
84
+ timeout: 180000,
85
+ env: Object.assign({ SLOW_MO: '0' }, process.env, {
86
+ WEBSHIP_REPORT_DISABLE: '1',
87
+ WEBSHIP_VIDEO: 'off',
88
+ WEBSHIP_JS_ERROR_MODE: 'off',
89
+ WEBSHIP_SCREENSHOT_ON_FAILED: 'false',
90
+ WEBSHIP_SELECTORS_BREAKPOINTS: JSON.stringify({ mobile: { width: 360, height: 640 }, tablet: { width: 800, height: 600 } }),
91
+ }),
92
+ });
93
+
94
+ const strip = (text) => String(text || '').replace(/\u001b\[[0-9;]*m/g, '');
95
+ const problems = [];
96
+ let count = 0;
97
+ if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
98
+ problems.push('The run wrote no report: cucumber-js did not start.');
99
+ } else {
100
+ for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
101
+ for (const scenario of f.elements || []) {
102
+ count += 1;
103
+ const failed = (scenario.steps || []).find((step) => step.result && step.result.status !== 'passed');
104
+ if (failed) {
105
+ problems.push(`"${scenario.name}": ${failed.hidden ? 'a hook' : `"${failed.keyword}${failed.name}"`} ${failed.result.status}: ${strip(failed.result.error_message).split('\n')[0]}`);
106
+ }
107
+ }
108
+ }
109
+ if (count !== 5) problems.push(`${count} scenarios ran, not 5.`);
110
+ }
111
+
112
+ fs.rmSync(tmp, { recursive: true, force: true });
113
+ if (problems.length) {
114
+ console.error('Breakpoints:\n - ' + problems.join('\n - '));
115
+ process.exit(1);
116
+ }
117
+ console.log('Breakpoints: the @mobile and @desktop tags, the set-the-viewport step and the viewing-the-site step read one registry.');