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
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Runs scenarios with a fake clock (Playwright's page.clock) and checks that
5
+ // the smart waits still read the page: a navigation and a press settle in
6
+ // about the time the page needs, not their whole budget, because the
7
+ // settle no longer counts the clock's own timers nor reads the faked
8
+ // Date.now(). It also checks that advancing a clock nobody installed says
9
+ // so: Playwright installs one there and then, and the timers the page set
10
+ // before it run on real time.
11
+ //
12
+ // The check serves its own page on a free local port, so no other server is
13
+ // needed.
14
+ //
15
+ // Usage: node tests/check-clock.js (npm run test:clock)
16
+
17
+ const fs = require('fs');
18
+ const os = require('os');
19
+ const path = require('path');
20
+ const http = require('http');
21
+ const { spawn } = require('child_process');
22
+
23
+ const ROOT = path.resolve(__dirname, '..');
24
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-clock-'));
25
+ const report = path.join(tmp, 'clock.json');
26
+ const config = path.join(tmp, 'cucumber.js');
27
+ const feature = path.join(tmp, 'clock.feature');
28
+ const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
29
+
30
+ const PAGE = `<!doctype html><html><head><title>Clock</title></head><body>
31
+ <h1>A quiet page</h1>
32
+ <button id="go" type="button">Go</button>
33
+ <p id="status">Ready</p>
34
+ <script>
35
+ document.getElementById('go').addEventListener('click', function () {
36
+ document.getElementById('status').textContent = 'Pressed';
37
+ });
38
+ </script></body></html>`;
39
+
40
+ // [scenario, its steps, the step to time (by its text), its limit in ms]
41
+ const scenarios = [
42
+ ['A navigation with a fake clock settles when the page is quiet', [
43
+ 'Given I am on "/"',
44
+ 'And the system time is "2026-05-08T10:00:00Z"',
45
+ 'When I am on "/"',
46
+ 'Then I should see "A quiet page"',
47
+ ], 'I am on "/"', 2000],
48
+ ['A press with a fake clock settles when the page is quiet', [
49
+ 'Given I am on "/"',
50
+ 'And the system time is "2026-05-08T10:00:00Z"',
51
+ 'When I press "Go"',
52
+ 'Then I should see "Pressed"',
53
+ ], 'I press "Go"', 1000],
54
+ ['Advancing a clock nobody installed', [
55
+ 'Given I am on "/"',
56
+ 'When I advance the clock by 2 seconds',
57
+ 'Then I should see "A quiet page"',
58
+ ], null, null],
59
+ ];
60
+
61
+ fs.writeFileSync(feature, [
62
+ 'Feature: Smart waits with a fake clock',
63
+ '',
64
+ ...scenarios.flatMap(([name, steps]) => [` Scenario: ${name}`, ...steps.map((s) => ` ${s}`), '']),
65
+ ].join('\n'));
66
+
67
+ const server = http.createServer((req, res) => {
68
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
69
+ res.end(PAGE);
70
+ });
71
+
72
+ server.listen(0, '127.0.0.1', () => {
73
+ const base = `http://127.0.0.1:${server.address().port}`;
74
+ const defaults = require(path.join(ROOT, 'cucumber.js')).default;
75
+ const world = JSON.parse(JSON.stringify(defaults.worldParameters));
76
+ world.launchUrl = base;
77
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
78
+ requireModule: defaults.requireModule,
79
+ require: defaults.require,
80
+ paths: [feature],
81
+ format: [`json:${report}`],
82
+ worldParameters: world,
83
+ }) + ' };');
84
+ const env = Object.assign({ SLOW_MO: '0' }, process.env, {
85
+ LAUNCH_URL: base,
86
+ WEBSHIP_REPORT_DISABLE: '1',
87
+ WEBSHIP_VIDEO: 'off',
88
+ WEBSHIP_JS_ERROR_MODE: 'off',
89
+ WEBSHIP_SCREENSHOT_ON_FAILED: 'false',
90
+ });
91
+ delete env.WEBSHIP_AUTO_SETTLE;
92
+ const run = spawn(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
93
+ cwd: ROOT,
94
+ stdio: ['ignore', 'pipe', 'pipe'],
95
+ env,
96
+ });
97
+ let output = '';
98
+ run.stdout.on('data', (chunk) => { output += chunk; });
99
+ run.stderr.on('data', (chunk) => { output += chunk; });
100
+ const timer = setTimeout(() => run.kill('SIGKILL'), 180000);
101
+ run.on('exit', () => {
102
+ clearTimeout(timer);
103
+ server.close();
104
+ finish(output);
105
+ });
106
+ });
107
+
108
+ function finish(output) {
109
+ const strip = (text) => String(text || '').replace(/\u001b\[[0-9;]*m/g, '');
110
+ const problems = [];
111
+ let count = 0;
112
+ if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
113
+ problems.push(`The run wrote no report.\n${strip(output).slice(-1500)}`);
114
+ } else {
115
+ for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
116
+ for (const scenario of f.elements || []) {
117
+ count += 1;
118
+ const failed = (scenario.steps || []).find((step) => step.result && step.result.status !== 'passed');
119
+ if (failed) {
120
+ problems.push(`"${scenario.name}": ${failed.hidden ? 'a hook' : `"${failed.keyword}${failed.name}"`} ${failed.result.status}: ${strip(failed.result.error_message).split('\n')[0]}`);
121
+ continue;
122
+ }
123
+ const entry = scenarios.find(([name]) => name === scenario.name);
124
+ if (!entry || !entry[2]) continue;
125
+ const [, , text, limit] = entry;
126
+ const timed = (scenario.steps || []).filter((step) => !step.hidden && step.name === text);
127
+ const last = timed[timed.length - 1];
128
+ const ms = last ? Math.round(last.result.duration / 1e6) : NaN;
129
+ if (!(ms <= limit)) problems.push(`"${scenario.name}": "${text}" took ${ms} ms with the fake clock, more than ${limit} ms: the settle ran to its budget.`);
130
+ }
131
+ }
132
+ if (count !== scenarios.length) problems.push(`${count} scenarios ran, not ${scenarios.length}.`);
133
+ }
134
+ if (!/The clock was not installed/.test(strip(output))) {
135
+ problems.push('Advancing a clock nobody installed printed no note that a fake clock was installed only then.');
136
+ }
137
+ fs.rmSync(tmp, { recursive: true, force: true });
138
+ if (problems.length) {
139
+ console.error('Smart waits with a fake clock:\n - ' + problems.join('\n - '));
140
+ process.exit(1);
141
+ }
142
+ console.log('Smart waits with a fake clock: a navigation and a press settle when the page is quiet; advancing a clock nobody installed says so.');
143
+ }
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Runs a scenario with a cucumber.js whose worldParameters carry nothing but
5
+ // the launch URL, and checks that it passes and that the run ends by itself.
6
+ // Every other block of worldParameters (minWaitTime, selectors, screenshot,
7
+ // video, javascript) is optional: a project may leave any of them out.
8
+ //
9
+ // The scenario writes its own page, so no server is needed.
10
+ //
11
+ // Usage: node tests/check-config.js (npm run test:config)
12
+
13
+ const fs = require('fs');
14
+ const os = require('os');
15
+ const path = require('path');
16
+ const { spawnSync } = require('child_process');
17
+
18
+ const ROOT = path.resolve(__dirname, '..');
19
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-config-'));
20
+ const report = path.join(tmp, 'minimal.json');
21
+ const config = path.join(tmp, 'cucumber.js');
22
+ const steps = path.join(tmp, 'minimal.steps.js');
23
+ const feature = path.join(tmp, 'minimal.feature');
24
+ const LIMIT = 120000;
25
+
26
+ const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
27
+ fs.writeFileSync(steps, [
28
+ `const { Given } = require(${JSON.stringify(cucumber)});`,
29
+ "Given('a page that reads {string}', async function (text) {",
30
+ " await this.page.setContent(`<main><h1>${text}</h1><button>Go</button></main>`);",
31
+ '});',
32
+ '',
33
+ ].join('\n'));
34
+ fs.writeFileSync(feature, [
35
+ 'Feature: A configuration with only the launch URL',
36
+ '',
37
+ ' Scenario: The built-in steps and hooks run without the optional settings',
38
+ ' Given a page that reads "Hello"',
39
+ ' When I press "Go"',
40
+ ' Then I should see "Hello"',
41
+ '',
42
+ ].join('\n'));
43
+
44
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
45
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
46
+ requireModule: base.requireModule,
47
+ require: base.require.concat([steps]),
48
+ paths: [feature],
49
+ format: [`json:${report}`],
50
+ worldParameters: { launchUrl: 'http://localhost:8080' },
51
+ }) + ' };');
52
+
53
+ const started = Date.now();
54
+ const run = spawnSync(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
55
+ cwd: ROOT,
56
+ stdio: ['ignore', 'pipe', 'pipe'],
57
+ encoding: 'utf8',
58
+ timeout: LIMIT,
59
+ killSignal: 'SIGKILL',
60
+ env: Object.assign({ SLOW_MO: '0' }, process.env, { WEBSHIP_REPORT_DISABLE: '1', WEBSHIP_VIDEO: 'off', WEBSHIP_JS_ERROR_MODE: 'off' }),
61
+ });
62
+
63
+ const problems = [];
64
+ const output = `${run.stdout || ''}${run.stderr || ''}`.replace(/\u001b\[[0-9;]*m/g, '');
65
+ if (run.error && run.error.code === 'ETIMEDOUT') {
66
+ problems.push(`The run did not end by itself within ${LIMIT / 1000} seconds: it was stopped.`);
67
+ }
68
+ if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
69
+ problems.push('The run wrote no report.');
70
+ } else {
71
+ for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
72
+ for (const scenario of f.elements || []) {
73
+ for (const step of scenario.steps || []) {
74
+ const status = step.result && step.result.status;
75
+ if (status !== 'passed' && !(step.hidden && status === 'skipped')) {
76
+ const what = step.hidden ? `the ${step.keyword.trim()} hook` : `"${step.keyword}${step.name}"`;
77
+ problems.push(`${what} ended "${status}": ${String((step.result && step.result.error_message) || '').split('\n')[0]}`);
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
83
+ if (run.status !== 0 && !problems.length) problems.push(`cucumber-js exited with ${run.status}:\n${output.slice(-1500)}`);
84
+
85
+ fs.rmSync(tmp, { recursive: true, force: true });
86
+ if (problems.length) {
87
+ console.error('A configuration with only the launch URL:\n - ' + problems.join('\n - '));
88
+ process.exit(1);
89
+ }
90
+ console.log(`A configuration with only the launch URL: the scenario passed and the run ended in ${Math.round((Date.now() - started) / 1000)} s.`);
@@ -0,0 +1,215 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Runs scenarios in which a step replaces the browser context — restoring an
5
+ // auth state, starting and stopping a video recording — and checks that the
6
+ // new page keeps what the scenario had set up: the viewport of the @mobile
7
+ // tag, the smart-wait probes of the init script (a pending timer is counted),
8
+ // JavaScript-error capture, a running request log, the cookies, and video
9
+ // recording while it is on.
10
+ //
11
+ // The check serves its own page on a free local port, so no other server is
12
+ // needed.
13
+ //
14
+ // Usage: node tests/check-context.js (npm run test:context)
15
+
16
+ const fs = require('fs');
17
+ const os = require('os');
18
+ const path = require('path');
19
+ const http = require('http');
20
+ const { spawn } = require('child_process');
21
+
22
+ const ROOT = path.resolve(__dirname, '..');
23
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-context-'));
24
+ const report = path.join(tmp, 'context.json');
25
+ const config = path.join(tmp, 'cucumber.js');
26
+ const steps = path.join(tmp, 'context.steps.js');
27
+ const feature = path.join(tmp, 'context.feature');
28
+ const state = path.join(tmp, 'auth', 'state.json');
29
+ const videos = path.join(tmp, 'videos');
30
+ const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
31
+
32
+ const PAGE = `<!doctype html><html><head><title>Context</title></head><body>
33
+ <h1>A page in a new browser context</h1>
34
+ <button id="boom" type="button">Boom</button>
35
+ <script>
36
+ document.getElementById('boom').addEventListener('click', function () {
37
+ throw new Error('Boom in the new browser context');
38
+ });
39
+ </script></body></html>`;
40
+
41
+ fs.writeFileSync(steps, [
42
+ `const { Given, When, Then } = require(${JSON.stringify(cucumber)});`,
43
+ "Given('the cookie {string} is {string}', async function (name, value) {",
44
+ ' await this.context.addCookies([{ name, value, url: this.launchUrl }]);',
45
+ '});',
46
+ "When('the page fetches {string}', async function (url) {",
47
+ ' await this.page.evaluate((u) => fetch(u).then((r) => r.text()), url);',
48
+ '});',
49
+ "Then('the window should be {int} by {int}', async function (width, height) {",
50
+ ' const size = await this.page.evaluate(() => `${window.innerWidth} by ${window.innerHeight}`);',
51
+ ' if (size !== `${width} by ${height}`) throw new Error(`The window is ${size}.`);',
52
+ '});',
53
+ "Then('the smart waits should count a pending timer', async function () {",
54
+ ' const pending = await this.page.evaluate(() => { setTimeout(() => {}, 3000); return window.__webshipPendingTimers; });',
55
+ ' if (!(pending >= 1)) throw new Error(`The pending-timer counter reads ${pending}: the init script of the smart waits is not on this page.`);',
56
+ '});',
57
+ "Then('{int} JavaScript error(s) should have been captured', function (count) {",
58
+ ' const found = (this._jsErrors || []).length;',
59
+ ' if (found !== count) throw new Error(`${found} JavaScript error(s) were captured, not ${count}.`);',
60
+ '});',
61
+ "Then('the cookie {string} should still be {string}', async function (name, value) {",
62
+ ' const cookie = (await this.context.cookies()).find((c) => c.name === name);',
63
+ ' if (!cookie || cookie.value !== value) throw new Error(`The cookie "${name}" is ${cookie ? `"${cookie.value}"` : "gone"}.`);',
64
+ '});',
65
+ "Then('the page should be recording a video', function () {",
66
+ " if (!this.page.video()) throw new Error('The page records no video.');",
67
+ '});',
68
+ "Then('the page should not be recording a video', function () {",
69
+ " if (this.page.video()) throw new Error('The page still records a video.');",
70
+ '});',
71
+ '',
72
+ ].join('\n'));
73
+
74
+ const restore = [
75
+ ' Given I am on "/"',
76
+ ' And the cookie "session" is "kept"',
77
+ ` And I save the auth state to "${state}"`,
78
+ ' And I start recording network requests',
79
+ ` When I restore the auth state from "${state}"`,
80
+ ' And I am on "/"',
81
+ ];
82
+ const start = [
83
+ ' Given I am on "/"',
84
+ ' And the cookie "session" is "kept"',
85
+ ' And I start recording network requests',
86
+ ' When I start video recording',
87
+ ' And I am on "/"',
88
+ ];
89
+ const scenarios = [
90
+ ['@mobile', 'Restoring an auth state keeps the viewport of the tag', restore, [
91
+ ' Then the window should be 375 by 667',
92
+ ]],
93
+ ['', 'Restoring an auth state keeps the smart waits', restore, [
94
+ ' Then the smart waits should count a pending timer',
95
+ ]],
96
+ ['', 'Restoring an auth state keeps JavaScript-error capture', restore, [
97
+ ' When I press "Boom"',
98
+ ' Then 1 JavaScript error should have been captured',
99
+ ]],
100
+ ['', 'Restoring an auth state keeps the request log', restore, [
101
+ ' When the page fetches "/api"',
102
+ ' Then a GET request to "*/api" should have been made',
103
+ ]],
104
+ ['@mobile', 'Starting a video recording keeps the viewport of the tag', start, [
105
+ ' Then the page should be recording a video',
106
+ ' And the window should be 375 by 667',
107
+ ]],
108
+ ['', 'Starting a video recording keeps the cookies and JavaScript-error capture', start, [
109
+ ' Then the cookie "session" should still be "kept"',
110
+ ' When I press "Boom"',
111
+ ' Then 1 JavaScript error should have been captured',
112
+ ]],
113
+ ['@mobile', 'Stopping a video recording keeps the viewport, the cookies, the request log and JavaScript-error capture', start, [
114
+ ' When I stop video recording',
115
+ ' And I am on "/"',
116
+ ' Then the page should not be recording a video',
117
+ ' And the window should be 375 by 667',
118
+ ' And the smart waits should count a pending timer',
119
+ ' And the cookie "session" should still be "kept"',
120
+ ' When the page fetches "/api"',
121
+ ' Then a GET request to "*/api" should have been made',
122
+ ' When I press "Boom"',
123
+ ' Then 1 JavaScript error should have been captured',
124
+ ]],
125
+ ];
126
+ fs.writeFileSync(feature, [
127
+ 'Feature: A step that replaces the browser context keeps what the scenario set up',
128
+ '',
129
+ ...scenarios.flatMap(([tag, name, given, then]) => [
130
+ ...(tag ? [` ${tag}`] : []),
131
+ ` Scenario: ${name}`,
132
+ ...given,
133
+ ...then,
134
+ '',
135
+ ]),
136
+ ].join('\n'));
137
+
138
+ const server = http.createServer((req, res) => {
139
+ if (req.url === '/api') {
140
+ res.writeHead(200, { 'Content-Type': 'application/json' });
141
+ res.end('{"ok":true}');
142
+ return;
143
+ }
144
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
145
+ res.end(PAGE);
146
+ });
147
+
148
+ server.listen(0, '127.0.0.1', () => {
149
+ const base = `http://127.0.0.1:${server.address().port}`;
150
+ const defaults = require(path.join(ROOT, 'cucumber.js')).default;
151
+ const world = JSON.parse(JSON.stringify(defaults.worldParameters));
152
+ world.launchUrl = base;
153
+ world.video = Object.assign({}, world.video, { mode: 'off', dir: videos });
154
+ world.javascript = Object.assign({}, world.javascript, { mode: 'warn', levels: ['error'] });
155
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
156
+ requireModule: defaults.requireModule,
157
+ require: defaults.require.concat([steps]),
158
+ paths: [feature],
159
+ format: [`json:${report}`],
160
+ worldParameters: world,
161
+ }) + ' };');
162
+
163
+ const env = Object.assign({ SLOW_MO: '0' }, process.env, {
164
+ LAUNCH_URL: base,
165
+ WEBSHIP_REPORT_DISABLE: '1',
166
+ WEBSHIP_SCREENSHOT_ON_FAILED: 'false',
167
+ });
168
+ delete env.WEBSHIP_VIDEO;
169
+ delete env.WEBSHIP_VIDEO_DIR;
170
+ delete env.WEBSHIP_JS_ERROR_MODE;
171
+ const run = spawn(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
172
+ cwd: ROOT,
173
+ stdio: ['ignore', 'ignore', 'pipe'],
174
+ env,
175
+ });
176
+ let errors = '';
177
+ run.stderr.on('data', (chunk) => { errors += chunk; });
178
+ const timer = setTimeout(() => run.kill('SIGKILL'), 180000);
179
+ run.on('exit', () => {
180
+ clearTimeout(timer);
181
+ server.close();
182
+ finish(errors);
183
+ });
184
+ });
185
+
186
+ function finish(errors) {
187
+ const strip = (text) => String(text || '').replace(/\u001b\[[0-9;]*m/g, '');
188
+ const problems = [];
189
+ let count = 0;
190
+ if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
191
+ problems.push('The run wrote no report: cucumber-js did not start or was stopped.');
192
+ } else {
193
+ for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
194
+ for (const scenario of f.elements || []) {
195
+ count += 1;
196
+ const failed = (scenario.steps || []).find((step) => step.result && step.result.status !== 'passed');
197
+ if (failed) {
198
+ problems.push(`"${scenario.name}": ${failed.hidden ? 'a hook' : `"${failed.keyword}${failed.name}"`} ${failed.result.status}: ${strip(failed.result.error_message).split('\n')[0]}`);
199
+ }
200
+ }
201
+ }
202
+ if (count !== scenarios.length) problems.push(`${count} scenarios ran, not ${scenarios.length}.`);
203
+ }
204
+ const leftovers = fs.existsSync(videos) ? fs.readdirSync(videos) : [];
205
+ const orphans = leftovers.filter((name) => /^page@/.test(name));
206
+ if (orphans.length) problems.push(`Video files left without their final name: ${orphans.join(', ')}.`);
207
+
208
+ fs.rmSync(tmp, { recursive: true, force: true });
209
+ if (problems.length) {
210
+ if (!count) process.stderr.write(errors);
211
+ console.error('A replaced browser context:\n - ' + problems.join('\n - '));
212
+ process.exit(1);
213
+ }
214
+ console.log('A replaced browser context keeps the viewport, the smart waits, the cookies, JavaScript-error capture, the request log and video recording.');
215
+ }
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Runs a dry run with the pretty formatter, as the scaffold's cucumber.js
5
+ // does, and checks what it prints: the steps, the "? undefined" line of a
6
+ // step no definition matches and the summary, and no "- skipped" line — in a
7
+ // dry run every hook and every step is skipped, and a line for each of them
8
+ // buries the ones the dry run is for. Then a real run, whose step after a
9
+ // failing one must still be shown as skipped.
10
+ //
11
+ // No page is opened by the dry run; the real run never navigates. No server
12
+ // is needed.
13
+ //
14
+ // Usage: node tests/check-dry-run.js (npm run test:dry-run)
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 tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-dry-run-'));
23
+ const config = path.join(tmp, 'cucumber.js');
24
+ const steps = path.join(tmp, 'dry-run.steps.js');
25
+ const dryFeature = path.join(tmp, 'dry-run.feature');
26
+ const realFeature = path.join(tmp, 'real-run.feature');
27
+
28
+ const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
29
+ fs.writeFileSync(steps, [
30
+ `const { Then } = require(${JSON.stringify(cucumber)});`,
31
+ "Then('this step fails on purpose', function () { throw new Error('Failing on purpose.'); });",
32
+ "Then('this step comes after the failure', function () {});",
33
+ '',
34
+ ].join('\n'));
35
+ fs.writeFileSync(dryFeature, [
36
+ 'Feature: A dry run',
37
+ '',
38
+ ' Scenario: Steps that are defined',
39
+ ' Given I am on "/about-us.html"',
40
+ ' When I press "Submit"',
41
+ ' Then I should see "About Us"',
42
+ '',
43
+ ' Scenario: A step that no definition matches',
44
+ ' Given I am on "/about-us.html"',
45
+ ' Then this step is not defined anywhere',
46
+ '',
47
+ ].join('\n'));
48
+ fs.writeFileSync(realFeature, [
49
+ 'Feature: A real run',
50
+ '',
51
+ ' Scenario: A step after a failing step is skipped',
52
+ ' Then this step fails on purpose',
53
+ ' And this step comes after the failure',
54
+ '',
55
+ ].join('\n'));
56
+
57
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
58
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
59
+ requireModule: base.requireModule,
60
+ require: base.require.concat([steps]),
61
+ format: ['@cucumber/pretty-formatter'],
62
+ worldParameters: base.worldParameters,
63
+ }) + ' };');
64
+
65
+ const env = Object.assign({ SLOW_MO: '0' }, process.env, { WEBSHIP_REPORT_DISABLE: '1', WEBSHIP_VIDEO: 'off', WEBSHIP_JS_ERROR_MODE: 'off', FORCE_COLOR: '0' });
66
+ const plain = (text) => String(text || '').replace(/\u001b\[[0-9;]*m/g, '');
67
+ const run = (args) => {
68
+ const r = spawnSync(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)].concat(args), {
69
+ cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], env,
70
+ });
71
+ return plain(`${r.stdout || ''}${r.stderr || ''}`);
72
+ };
73
+
74
+ const problems = [];
75
+ const skipped = /^\s*-\s+skipped\s*$/;
76
+
77
+ const dry = run(['--dry-run', path.relative(ROOT, dryFeature)]).split('\n');
78
+ const dryText = dry.join('\n');
79
+ const skippedLines = dry.filter((line) => skipped.test(line)).length;
80
+ if (skippedLines) problems.push(`The dry run printed ${skippedLines} "- skipped" line(s).`);
81
+ for (const step of ['Given I am on "/about-us.html"', 'When I press "Submit"', 'Then I should see "About Us"', 'Then this step is not defined anywhere']) {
82
+ if (!dry.some((line) => line.trim() === step)) problems.push(`The dry run did not print the step: ${step}`);
83
+ }
84
+ if (!dry.some((line) => /^\s*\?\s+undefined\s*$/.test(line))) problems.push('The dry run did not print the "? undefined" line of the undefined step.');
85
+ if (!/2 scenarios \(1 undefined, 1 skipped\)/.test(dryText)) problems.push('The dry run did not print its summary "2 scenarios (1 undefined, 1 skipped)".');
86
+ // The steps of a scenario follow one another: no empty line left where a
87
+ // "- skipped" line was taken out.
88
+ const first = dry.findIndex((line) => line.trim() === 'Given I am on "/about-us.html"');
89
+ if (first >= 0 && (dry[first + 1] || '').trim() !== 'When I press "Submit"') {
90
+ problems.push(`The dry run left a line between two steps: "${dry[first + 1]}".`);
91
+ }
92
+
93
+ const real = run([path.relative(ROOT, realFeature)]).split('\n');
94
+ const after = real.findIndex((line) => line.trim() === 'And this step comes after the failure');
95
+ if (after < 0 || !skipped.test(real[after + 1] || '')) {
96
+ problems.push('A real run no longer shows the step after a failing step as "- skipped".');
97
+ }
98
+
99
+ fs.rmSync(tmp, { recursive: true, force: true });
100
+ if (problems.length) {
101
+ console.error('Dry run output:\n - ' + problems.join('\n - '));
102
+ process.exit(1);
103
+ }
104
+ console.log('Dry run output: the steps, the undefined step and the summary, with no "- skipped" line; a real run still shows its skipped steps.');