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,241 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Checks the step documentation and the features against the step
5
+ // definitions, without a browser:
6
+ //
7
+ // 1. every step definition in tests/step-definitions carries a JSDoc block
8
+ // with a description and at least five "Example #n:" blocks that use
9
+ // the step itself (CLAUDE.md §4.2),
10
+ // 2. every step line of every example resolves to exactly one definition
11
+ // (none undefined, none ambiguous),
12
+ // 3. at least one example of a definition resolves to that definition,
13
+ // 4. every step in tests/features resolves to exactly one definition.
14
+ //
15
+ // The matching is done by cucumber-js itself (`--dry-run`), so regular
16
+ // expressions and Cucumber expressions are read the way a real run reads
17
+ // them. An example may span several lines: the steps that set the scene, a
18
+ // data table or a doc string count as part of it.
19
+ //
20
+ // Usage: node tests/check-examples.js (npm run test:examples)
21
+
22
+ const fs = require('fs');
23
+ const os = require('os');
24
+ const path = require('path');
25
+ const { spawnSync } = require('child_process');
26
+
27
+ const ROOT = path.resolve(__dirname, '..');
28
+ const STEPS_DIR = path.join(ROOT, 'tests', 'step-definitions');
29
+ const KEYWORD = /^(Given|When|Then|And|But|\*)\s/;
30
+
31
+ /**
32
+ * Read every step definition of a step file with the JSDoc block above it.
33
+ *
34
+ * @param {string} file - File name inside tests/step-definitions.
35
+ * @returns {Array<Object>} One entry per definition.
36
+ */
37
+ function readDefinitions(file) {
38
+ const source = fs.readFileSync(path.join(STEPS_DIR, file), 'utf8');
39
+ const definitions = [];
40
+ // Some steps are registered through an alias (ThenF, WhenF): they count.
41
+ const re = /(?:^|\n)[ \t]*(Given|When|Then|defineStep)F?\(\s*(\/(?:\\\/|[^/\n])+\/[a-z]*|'(?:\\'|[^'\n])*'|"(?:\\"|[^"\n])*"|`[^`\n]*`)/g;
42
+ let m;
43
+ while ((m = re.exec(source))) {
44
+ const index = m.index + (m[0].startsWith('\n') ? 1 : 0);
45
+ const before = source.slice(0, index);
46
+ const line = before.split('\n').length;
47
+ let doc = null;
48
+ const docEnd = before.lastIndexOf('*/');
49
+ if (docEnd !== -1 && /^\s*$/.test(before.slice(docEnd + 2))) {
50
+ // The block opens on a line of its own; "/**" may also be part of a
51
+ // URL pattern inside an example.
52
+ let docStart = -1;
53
+ const open = /(^|\n)[ \t]*\/\*\*/g;
54
+ let o;
55
+ while ((o = open.exec(before.slice(0, docEnd)))) docStart = o.index + o[0].indexOf('/**');
56
+ if (docStart !== -1) doc = before.slice(docStart + 3, docEnd);
57
+ }
58
+ const examples = [];
59
+ const description = [];
60
+ if (doc !== null) {
61
+ let current = null;
62
+ for (const raw of doc.split('\n').map((l) => l.replace(/^\s*\*\s?/, ''))) {
63
+ const example = raw.match(/^\s*Example\s*#?\d*[^:]*:\s*(.*)$/);
64
+ if (example) {
65
+ current = [];
66
+ examples.push(current);
67
+ // Text after the colon is the first step, or a caption of the block.
68
+ if (KEYWORD.test(example[1].trim())) current.push(example[1].trim());
69
+ continue;
70
+ }
71
+ if (/^\s*@\w+/.test(raw)) { current = null; continue; }
72
+ if (current) { if (raw.trim()) current.push(raw.trim()); continue; }
73
+ if (!examples.length && raw.trim()) description.push(raw.trim());
74
+ }
75
+ }
76
+ definitions.push({ file, line, pattern: m[2], hasDoc: doc !== null, description: description.join(' '), examples, own: 0, ownExamples: new Set() });
77
+ }
78
+ return definitions;
79
+ }
80
+
81
+ /**
82
+ * Turn the examples of the definitions of one file into a feature: one
83
+ * scenario per example. Returns the feature text and, per feature line, the
84
+ * definition the step line belongs to.
85
+ */
86
+ function buildFeature(file, definitions) {
87
+ const lines = [`Feature: examples of ${file}`, ''];
88
+ const owners = {};
89
+ for (const definition of definitions) {
90
+ definition.examples.forEach((example, n) => {
91
+ const body = [];
92
+ let inDocString = false;
93
+ let steps = 0;
94
+ for (const raw of example) {
95
+ if (/^("""|```)/.test(raw)) { inDocString = !inDocString; if (steps) body.push({ text: ' ' + raw }); continue; }
96
+ if (inDocString) { if (steps) body.push({ text: ' ' + raw }); continue; }
97
+ if (/^\|.*\|\s*(#.*)?$/.test(raw)) { if (steps) body.push({ text: ' ' + raw.replace(/\|\s+#[^|]*$/, '|') }); continue; }
98
+ if (!KEYWORD.test(raw)) continue; // a caption or a comment
99
+ let step = raw.replace(/\s{2,}#\s.*$/, '').replace(/^(\S+)\s+/, '$1 ');
100
+ if (!steps) step = step.replace(/^(And|But|\*) /, 'Given ');
101
+ steps++;
102
+ body.push({ text: ' ' + step, step: raw });
103
+ }
104
+ if (!steps) return;
105
+ lines.push(` Scenario: ${file} line ${definition.line} example ${n + 1}`);
106
+ for (const item of body) {
107
+ lines.push(item.text);
108
+ if (item.step) owners[lines.length] = { definition, step: item.step, example: n };
109
+ }
110
+ lines.push('');
111
+ });
112
+ }
113
+ return { text: lines.join('\n'), owners };
114
+ }
115
+
116
+ /**
117
+ * Dry-run cucumber-js over some feature paths and return its JSON report and
118
+ * its usage report.
119
+ */
120
+ function dryRun(tmp, name, featurePaths) {
121
+ const usage = path.join(tmp, `${name}-usage.json`);
122
+ const report = path.join(tmp, `${name}-report.json`);
123
+ const config = path.join(tmp, `${name}-cucumber.js`);
124
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
125
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
126
+ requireModule: base.requireModule,
127
+ require: base.require,
128
+ paths: featurePaths,
129
+ format: [`usage-json:${usage}`, `json:${report}`],
130
+ worldParameters: base.worldParameters,
131
+ }) + ' };');
132
+ const bin = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber', 'bin', 'cucumber.js');
133
+ const run = spawnSync(process.execPath, [bin, '--config', path.relative(ROOT, config), '--dry-run'], {
134
+ cwd: ROOT,
135
+ encoding: 'utf8',
136
+ env: Object.assign({}, process.env, { WEBSHIP_REPORT_DISABLE: '1' }),
137
+ maxBuffer: 1 << 28,
138
+ });
139
+ if (!fs.existsSync(report) || !fs.existsSync(usage) || !fs.readFileSync(report, 'utf8').trim()) {
140
+ console.error((run.stdout || '') + (run.stderr || ''));
141
+ console.error(`cucumber-js --dry-run did not produce a report for the ${name}.`);
142
+ process.exit(2);
143
+ }
144
+ return {
145
+ report: JSON.parse(fs.readFileSync(report, 'utf8')),
146
+ usage: JSON.parse(fs.readFileSync(usage, 'utf8')),
147
+ };
148
+ }
149
+
150
+ const problems = [];
151
+ const files = fs.readdirSync(STEPS_DIR).filter((f) => f.endsWith('.steps.js')).sort();
152
+ const all = [];
153
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-examples-'));
154
+ const featureOwners = {};
155
+ const featurePaths = [];
156
+
157
+ for (const file of files) {
158
+ const definitions = readDefinitions(file);
159
+ all.push(...definitions);
160
+ for (const d of definitions) {
161
+ const where = `${d.file}:${d.line}`;
162
+ if (!d.hasDoc) problems.push(`${where} no JSDoc block above the definition ${d.pattern}`);
163
+ else if (!d.description) problems.push(`${where} the JSDoc block has no description`);
164
+ if (d.hasDoc && !d.examples.length) problems.push(`${where} no "Example #n:" line`);
165
+ }
166
+ const feature = buildFeature(file, definitions);
167
+ const featurePath = path.join(tmp, `${file}.feature`);
168
+ fs.writeFileSync(featurePath, feature.text);
169
+ featurePaths.push(path.relative(ROOT, featurePath));
170
+ featureOwners[`${file}.feature`] = feature.owners;
171
+ }
172
+
173
+ const byPlace = {};
174
+ for (const d of all) byPlace[`${d.file}:${d.line}`] = d;
175
+
176
+ // 1. The examples.
177
+ const examples = dryRun(tmp, 'examples', featurePaths);
178
+ const matched = {};
179
+ for (const entry of examples.usage) {
180
+ for (const match of entry.matches || []) {
181
+ matched[`${path.basename(match.uri)}:${match.line}`] = `${path.basename(entry.uri)}:${entry.line}`;
182
+ }
183
+ }
184
+ let exampleSteps = 0;
185
+ for (const feature of examples.report) {
186
+ const owners = featureOwners[path.basename(feature.uri)] || {};
187
+ for (const scenario of feature.elements || []) {
188
+ for (const step of scenario.steps || []) {
189
+ const owner = owners[step.line];
190
+ if (!owner) continue;
191
+ exampleSteps++;
192
+ const where = `${owner.definition.file}:${owner.definition.line}`;
193
+ const status = step.result && step.result.status;
194
+ if (status === 'undefined') problems.push(`${where} example step matches no definition: ${owner.step}`);
195
+ else if (status === 'ambiguous') problems.push(`${where} example step matches more than one definition: ${owner.step}`);
196
+ else if (matched[`${path.basename(feature.uri)}:${step.line}`] === where) {
197
+ owner.definition.own++;
198
+ owner.definition.ownExamples.add(owner.example);
199
+ }
200
+ }
201
+ }
202
+ }
203
+ const MIN_EXAMPLES = 5;
204
+ for (const d of all) {
205
+ if (d.examples.length && !d.own) problems.push(`${d.file}:${d.line} none of its examples uses the step itself: ${d.pattern}`);
206
+ else if (d.hasDoc && d.ownExamples.size < MIN_EXAMPLES) problems.push(`${d.file}:${d.line} ${d.ownExamples.size} of its examples use the step itself, fewer than ${MIN_EXAMPLES}: ${d.pattern}`);
207
+ }
208
+
209
+ // 2. The features of the suite.
210
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
211
+ const suite = dryRun(tmp, 'features', base.paths);
212
+ let featureSteps = 0;
213
+ for (const feature of suite.report) {
214
+ for (const scenario of feature.elements || []) {
215
+ for (const step of scenario.steps || []) {
216
+ if (step.hidden) continue;
217
+ featureSteps++;
218
+ const status = step.result && step.result.status;
219
+ if (status === 'undefined') problems.push(`${feature.uri}:${step.line} undefined step: ${step.keyword}${step.name}`);
220
+ if (status === 'ambiguous') problems.push(`${feature.uri}:${step.line} ambiguous step: ${step.keyword}${step.name}`);
221
+ }
222
+ }
223
+ }
224
+ // A definition cucumber-js loaded that the reader above did not see would
225
+ // escape every check: say so instead of passing.
226
+ for (const entry of suite.usage) {
227
+ if (!byPlace[`${path.basename(entry.uri)}:${entry.line}`]) {
228
+ problems.push(`${entry.uri}:${entry.line} definition not read by this check: ${entry.pattern}`);
229
+ }
230
+ }
231
+
232
+ fs.rmSync(tmp, { recursive: true, force: true });
233
+
234
+ const exampleCount = all.reduce((n, d) => n + d.examples.length, 0);
235
+ console.log(`${all.length} step definitions in ${files.length} files, ${exampleCount} examples (${exampleSteps} step lines), ${featureSteps} feature steps.`);
236
+ if (problems.length) {
237
+ console.error(`\n${problems.length} problem(s):`);
238
+ for (const p of problems) console.error(' ' + p);
239
+ process.exit(1);
240
+ }
241
+ console.log('Every definition is documented, every example step and every feature step resolves to exactly one definition.');
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Checks the HTML report that tests/step-definitions/webship.js builds when
5
+ // a run of cucumber-js ends, in three runs of a small project:
6
+ //
7
+ // 1. `--parallel 2`: the report is built once, by the process that runs
8
+ // cucumber-js, from the whole JSON report; no worker tries to read a
9
+ // JSON report that is still being written.
10
+ // 2. A JSON report written somewhere else than tests/reports/ (the `json:`
11
+ // formatter of the config file): the report is built from that file.
12
+ // 3. No JSON formatter at all: one line says that there is no report and
13
+ // why, with no stack trace.
14
+ //
15
+ // The scenarios never navigate, so no server is needed; each one opens a
16
+ // browser, as every scenario does.
17
+ //
18
+ // Usage: node tests/check-exit-report.js (npm run test:exit-report)
19
+
20
+ const fs = require('fs');
21
+ const os = require('os');
22
+ const path = require('path');
23
+ const { spawnSync } = require('child_process');
24
+
25
+ const ROOT = path.resolve(__dirname, '..');
26
+ const CUCUMBER = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
27
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-exit-report-'));
28
+ const problems = [];
29
+
30
+ // A project of its own, so that no tests/reports/ of this repository is read.
31
+ const project = path.join(tmp, 'project');
32
+ fs.mkdirSync(project, { recursive: true });
33
+ fs.writeFileSync(path.join(project, 'playwright.config.js'), 'module.exports = ' + JSON.stringify({
34
+ browser: 'chromium',
35
+ launchOptions: { headless: true },
36
+ contextOptions: { viewport: null },
37
+ }) + ';\n');
38
+ const steps = path.join(project, 'plain.steps.js');
39
+ fs.writeFileSync(steps, [
40
+ `const { Given } = require(${JSON.stringify(CUCUMBER)});`,
41
+ "Given('this step passes', function () {});",
42
+ '',
43
+ ].join('\n'));
44
+ const features = [];
45
+ for (const name of ['first', 'second']) {
46
+ const file = path.join(project, `${name}.feature`);
47
+ fs.writeFileSync(file, [
48
+ `Feature: The ${name} feature`,
49
+ '',
50
+ ` Scenario: The ${name} scenario`,
51
+ ' Given this step passes',
52
+ '',
53
+ ].join('\n'));
54
+ features.push(file);
55
+ }
56
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
57
+ const world = JSON.parse(JSON.stringify(base.worldParameters));
58
+
59
+ /**
60
+ * Run cucumber-js in the project with a config of its own and return what it
61
+ * printed.
62
+ *
63
+ * @param {string} name - Name of the run (and of its config file).
64
+ * @param {string[]} format - Formatters of the config file.
65
+ * @param {string[]} [args] - Extra arguments of cucumber-js.
66
+ * @param {Object} [vars] - Extra environment variables.
67
+ * @returns {{output: string, html: string, status: number}}
68
+ */
69
+ function run(name, format, args, vars) {
70
+ const html = path.join(tmp, `${name}.html`);
71
+ const config = path.join(project, `${name}.cucumber.js`);
72
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
73
+ require: [path.join(ROOT, 'tests', 'step-definitions', '**', '*.js'), steps],
74
+ paths: features,
75
+ format,
76
+ worldParameters: world,
77
+ }) + ' };');
78
+ const env = Object.assign({ SLOW_MO: '0' }, process.env, {
79
+ WEBSHIP_VIDEO: 'off',
80
+ WEBSHIP_JS_ERROR_MODE: 'off',
81
+ WEBSHIP_REPORT_OUT: html,
82
+ FORCE_COLOR: '0',
83
+ });
84
+ delete env.WEBSHIP_REPORT_DISABLE;
85
+ delete env.WEBSHIP_REPORT_JSON;
86
+ delete env.WEBSHIP_REPORT_ARGS;
87
+ Object.assign(env, vars || {});
88
+ const result = spawnSync(process.execPath, [path.join(CUCUMBER, 'bin', 'cucumber.js'), '--config', path.basename(config)].concat(args || []), {
89
+ cwd: project,
90
+ stdio: ['ignore', 'pipe', 'pipe'],
91
+ env,
92
+ encoding: 'utf8',
93
+ });
94
+ return { output: `${result.stdout}\n${result.stderr}`, html, status: result.status };
95
+ }
96
+
97
+ const count = (text, re) => (text.match(re) || []).length;
98
+ const shown = (text) => text.trim().split('\n').slice(0, 12).map((line) => ` ${line}`).join('\n');
99
+ const STACK = /^\s+at .+:\d+:\d+\)?$/m;
100
+
101
+ // 1. Two workers, the JSON report named by WEBSHIP_REPORT_JSON.
102
+ {
103
+ const json = path.join(tmp, 'parallel.json');
104
+ const { output, html, status } = run('parallel', ['progress', `json:${json}`], ['--parallel', '2'], { WEBSHIP_REPORT_JSON: json });
105
+ if (status !== 0) problems.push(`The --parallel run failed (exit ${status}):\n${shown(output)}`);
106
+ if (/Unable to parse|Unexpected end of JSON input/.test(output)) {
107
+ problems.push(`With --parallel 2, a process read the JSON report before it was complete:\n${shown(output)}`);
108
+ }
109
+ const built = count(output, /\[webship-js\] HTML report/g);
110
+ if (built !== 1) problems.push(`With --parallel 2, the HTML report was built ${built} times, not once.`);
111
+ if (!fs.existsSync(html)) problems.push('With --parallel 2, no HTML report was written.');
112
+ }
113
+
114
+ // 2. The JSON report written somewhere else, by the config file.
115
+ {
116
+ const json = path.join(tmp, 'elsewhere', 'run.json');
117
+ const { output, html } = run('elsewhere', ['progress', `json:${json}`]);
118
+ if (/ENOENT/.test(output) || STACK.test(output)) {
119
+ problems.push(`With the JSON report written elsewhere, the end of the run printed an error:\n${shown(output)}`);
120
+ }
121
+ if (!fs.existsSync(html)) problems.push(`With the JSON report written to ${path.relative(tmp, json)}, no HTML report was built from it.`);
122
+ }
123
+
124
+ // 3. No JSON formatter.
125
+ {
126
+ const { output, html } = run('none', ['progress']);
127
+ if (/ENOENT/.test(output) || STACK.test(output)) {
128
+ problems.push(`With no JSON report, the end of the run printed an error:\n${shown(output)}`);
129
+ }
130
+ if (count(output, /\[webship-js\] No HTML report/g) !== 1) {
131
+ problems.push(`With no JSON report, the end of the run did not say once that there is no HTML report:\n${shown(output)}`);
132
+ }
133
+ if (fs.existsSync(html)) problems.push('With no JSON report, an HTML report was written anyway.');
134
+ }
135
+
136
+ fs.rmSync(tmp, { recursive: true, force: true });
137
+ if (problems.length) {
138
+ console.error('HTML report at the end of a run:\n - ' + problems.join('\n - '));
139
+ process.exit(1);
140
+ }
141
+ console.log('HTML report at the end of a run: built once with --parallel, built from a JSON report written elsewhere, and one plain line when there is none.');
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Runs the JavaScript-error checks with console warnings captured
5
+ // (WEBSHIP_JS_ERROR_LEVELS=error,warning) and checks what each one does:
6
+ // "there should be no JavaScript errors" counts errors only (an uncaught
7
+ // error or console.error), "there should be no JavaScript warnings" counts
8
+ // warnings only, and what a check did not read is still reported at the end
9
+ // of the scenario: a warning after the errors check, an error after the
10
+ // warnings check.
11
+ //
12
+ // The page is the blank page of the browser: no server is needed.
13
+ //
14
+ // Usage: node tests/check-javascript-errors.js (npm run test:js-errors)
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-js-errors-'));
23
+ const report = path.join(tmp, 'js-errors.json');
24
+ const config = path.join(tmp, 'cucumber.js');
25
+ const steps = path.join(tmp, 'js-errors.steps.js');
26
+ const feature = path.join(tmp, 'js-errors.feature');
27
+
28
+ const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
29
+ fs.writeFileSync(steps, [
30
+ `const { Given } = require(${JSON.stringify(cucumber)});`,
31
+ "Given('the page logs a warning', async function () { await this.page.evaluate(() => console.warn('Check warning: this option is deprecated')); await this.page.waitForTimeout(100); });",
32
+ "Given('the page logs an error', async function () { await this.page.evaluate(() => console.error('Check error: the request was refused')); await this.page.waitForTimeout(100); });",
33
+ '',
34
+ ].join('\n'));
35
+
36
+ // name → [the status of its last step, the status of the scenario's After hooks, a text the run must print for it]
37
+ const scenarios = [
38
+ ['A warning is not an error', 'Given the page logs a warning\n Then there should be no JavaScript errors', 'passed', 'passed', 'Check warning'],
39
+ ['An error is an error', 'Given the page logs an error\n Then there should be no JavaScript errors', 'failed', 'passed', null],
40
+ ['A warning is a warning', 'Given the page logs a warning\n Then there should be no JavaScript warnings', 'failed', 'passed', null],
41
+ ['An error is not a warning', 'Given the page logs an error\n Then there should be no JavaScript warnings', 'passed', 'passed', 'Check error'],
42
+ ['@js-fail A warning still fails a scenario in fail mode', 'Given the page logs a warning\n Then there should be no JavaScript errors', 'passed', 'failed', null],
43
+ ['@js-fail An error still fails a scenario in fail mode', 'Given the page logs an error\n Then there should be no JavaScript warnings', 'passed', 'failed', null],
44
+ ];
45
+ fs.writeFileSync(feature, ['Feature: JavaScript errors and warnings', ''].concat(scenarios.map(([name, body]) => {
46
+ const tag = name.startsWith('@') ? name.split(' ')[0] : '';
47
+ const title = tag ? name.slice(tag.length + 1) : name;
48
+ return (tag ? ` ${tag}\n` : '') + ` Scenario: ${title}\n ${body}\n`;
49
+ })).join('\n'));
50
+
51
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
52
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
53
+ requireModule: base.requireModule,
54
+ require: base.require.concat([steps]),
55
+ paths: [feature],
56
+ format: [`json:${report}`],
57
+ worldParameters: base.worldParameters,
58
+ }) + ' };');
59
+
60
+ const run = spawnSync(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
61
+ cwd: ROOT,
62
+ encoding: 'utf8',
63
+ stdio: ['ignore', 'pipe', 'pipe'],
64
+ env: Object.assign({ SLOW_MO: '0' }, process.env, {
65
+ WEBSHIP_REPORT_DISABLE: '1',
66
+ WEBSHIP_VIDEO: 'off',
67
+ WEBSHIP_JS_ERROR_MODE: 'warn',
68
+ WEBSHIP_JS_ERROR_LEVELS: 'error,warning',
69
+ }),
70
+ });
71
+ const printed = `${run.stdout || ''}\n${run.stderr || ''}`;
72
+
73
+ const problems = [];
74
+ if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
75
+ problems.push(`The run wrote no report: cucumber-js did not start.\n${printed}`);
76
+ } else {
77
+ const found = {};
78
+ for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
79
+ for (const scenario of f.elements || []) found[scenario.name] = scenario;
80
+ }
81
+ for (const [name, , lastStatus, afterStatus, text] of scenarios) {
82
+ const title = name.startsWith('@') ? name.slice(name.indexOf(' ') + 1) : name;
83
+ const scenario = found[title];
84
+ if (!scenario) { problems.push(`"${title}" did not run.`); continue; }
85
+ const visible = (scenario.steps || []).filter((s) => !s.hidden);
86
+ const last = visible[visible.length - 1];
87
+ // cucumber-js writes the hooks into the steps of the JSON report, hidden.
88
+ const after = (scenario.steps || []).filter((s) => s.hidden && s.keyword === 'After').map((h) => h.result && h.result.status);
89
+ const afterOutcome = after.includes('failed') ? 'failed' : 'passed';
90
+ if (!last || last.result.status !== lastStatus) {
91
+ problems.push(`"${title}": its check ${last ? last.result.status : 'is missing'}, it must have ${lastStatus}${last && last.result.error_message ? `: ${last.result.error_message.split('\n')[0]}` : ''}.`);
92
+ }
93
+ if (afterOutcome !== afterStatus) problems.push(`"${title}": the end-of-scenario report ${afterOutcome}, it must have ${afterStatus}.`);
94
+ if (text && !new RegExp(`JavaScript errors during "${title}"[\\s\\S]*${text}`).test(printed)) {
95
+ problems.push(`"${title}": the end-of-scenario report did not print "${text}".`);
96
+ }
97
+ }
98
+ }
99
+
100
+ fs.rmSync(tmp, { recursive: true, force: true });
101
+ if (problems.length) {
102
+ console.error('JavaScript errors and warnings:\n - ' + problems.join('\n - '));
103
+ process.exit(1);
104
+ }
105
+ console.log('JavaScript errors and warnings: each check counts its own kind, and what it did not read is reported at the end of the scenario.');
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Runs the scenarios of tests/must-fail/ and checks that every one of them
5
+ // FAILS, at its last step, with the message its description announces
6
+ // ("Fails with: ..."), and that the message names the page (for an API step,
7
+ // the request the response answers) and carries a hint, with no Playwright
8
+ // call log and no stack trace.
9
+ //
10
+ // A step that cannot fail proves nothing, and a failure nobody can read
11
+ // costs a tester an hour. Each scenario here asserts something that is not
12
+ // true on the example pages; the steps before the last one must pass.
13
+ //
14
+ // Usage: node tests/check-must-fail.js (npm run test:must-fail)
15
+ // The examples/ pages must be served on the launch URL of cucumber.js
16
+ // (npm start; LAUNCH_URL to point elsewhere).
17
+
18
+ const fs = require('fs');
19
+ const os = require('os');
20
+ const path = require('path');
21
+ const { spawnSync } = require('child_process');
22
+
23
+ const ROOT = path.resolve(__dirname, '..');
24
+ const DIR = path.join(ROOT, 'tests', 'must-fail');
25
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-must-fail-'));
26
+ const report = path.join(tmp, 'must-fail.json');
27
+ const config = path.join(tmp, 'cucumber.js');
28
+
29
+ const base = require(path.join(ROOT, 'cucumber.js')).default;
30
+ const features = fs.readdirSync(DIR).filter((file) => file.endsWith('.feature')).sort().map((file) => `tests/must-fail/${file}`);
31
+ // The same step definitions and world as the suite; the screenshots of these
32
+ // deliberate failures go to the temporary folder, not to screenshots/.
33
+ const world = JSON.parse(JSON.stringify(base.worldParameters));
34
+ world.screenshot = Object.assign({}, world.screenshot, { dir: path.join(tmp, 'screenshots') });
35
+ fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
36
+ requireModule: base.requireModule,
37
+ require: base.require,
38
+ paths: features,
39
+ format: [`json:${report}`],
40
+ worldParameters: world,
41
+ }) + ' };');
42
+
43
+ spawnSync(process.execPath, [path.join(ROOT, 'node_modules', '@cucumber', 'cucumber', 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
44
+ cwd: ROOT,
45
+ stdio: ['ignore', 'ignore', 'inherit'],
46
+ env: Object.assign({ SLOW_MO: '0' }, process.env, { WEBSHIP_REPORT_DISABLE: '1', WEBSHIP_VIDEO: 'off', WEBSHIP_JS_ERROR_MODE: 'off' }),
47
+ });
48
+
49
+ const strip = (text) => String(text || '').replace(/\u001b\[[0-9;]*m/g, '');
50
+ const problems = [];
51
+ let count = 0;
52
+
53
+ if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
54
+ problems.push('The must-fail run wrote no report: cucumber-js did not start.');
55
+ } else {
56
+ for (const feature of JSON.parse(fs.readFileSync(report, 'utf8'))) {
57
+ for (const scenario of feature.elements || []) {
58
+ count += 1;
59
+ const where = `${feature.uri}:${scenario.line} "${scenario.name}"`;
60
+ const wanted = ((strip(scenario.description).match(/Fails with:\s*(.+)/) || [])[1] || '').trim();
61
+ const steps = (scenario.steps || []).filter((step) => !step.hidden);
62
+ const last = steps[steps.length - 1];
63
+ const earlier = steps.slice(0, -1).filter((step) => step.result.status !== 'passed');
64
+ if (!wanted) { problems.push(`${where}: no "Fails with:" line in its description.`); continue; }
65
+ if (earlier.length) { problems.push(`${where}: an earlier step did not pass (${earlier[0].keyword}${earlier[0].name}: ${earlier[0].result.status}) ${strip(earlier[0].result.error_message).split('\n')[0]}`); continue; }
66
+ if (!last || last.result.status !== 'failed') { problems.push(`${where}: its last step ${last ? last.result.status : 'is missing'}; it must fail.`); continue; }
67
+ const message = strip(last.result.error_message);
68
+ const shown = message.split('\n').slice(0, 4).join('\n ');
69
+ if (!message.includes(wanted)) { problems.push(`${where}: failed, but not with "${wanted}":\n ${shown}`); continue; }
70
+ if (!/^\s*Hint: \S/m.test(message)) { problems.push(`${where}: the failure carries no hint:\n ${shown}`); continue; }
71
+ if (!/^\s*(?:Page|Request): \S/m.test(message)) { problems.push(`${where}: the failure names neither the page nor the request:\n ${shown}`); continue; }
72
+ if (/Call log:|Timeout \d+ms exceeded|^\s+at .+:\d+:\d+\)?$/m.test(message)) { problems.push(`${where}: the failure shows a Playwright call log, a raw timeout or a stack trace:\n ${shown}`); continue; }
73
+ console.log(` fails as it must: ${scenario.name}\n ${message.split('\n')[0].trim()}`);
74
+ }
75
+ }
76
+ if (!count) problems.push('No must-fail scenario ran.');
77
+ }
78
+
79
+ fs.rmSync(tmp, { recursive: true, force: true });
80
+
81
+ if (problems.length) {
82
+ console.error(`\n${problems.length} problem(s) in ${count} must-fail scenario(s):\n ${problems.join('\n ')}`);
83
+ process.exit(1);
84
+ }
85
+ console.log(`\n${count} must-fail scenarios: each failed at its last step with the announced message, the page (or the request) and a hint.`);
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // Checks that a feature, a scenario (file:line) or several features named on
5
+ // the command line of cucumber-js run alone, and that a run that names none
6
+ // runs the whole of tests/features/ (cucumber.js, commandLinePaths). Dry runs
7
+ // only: no browser, no server.
8
+ //
9
+ // Usage: node tests/check-paths.js (npm run test:paths)
10
+
11
+ const fs = require('fs');
12
+ const os = require('os');
13
+ const path = require('path');
14
+ const { spawnSync } = require('child_process');
15
+
16
+ const ROOT = path.resolve(__dirname, '..');
17
+ const BIN = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber', 'bin', 'cucumber.js');
18
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-paths-'));
19
+ const problems = [];
20
+
21
+ // The scenarios a dry run selects, from a JSON report written to the temporary
22
+ // folder; the report and the formats of cucumber.js are left alone.
23
+ function scenarios(args) {
24
+ const report = path.join(tmp, `run-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);
25
+ const run = spawnSync(process.execPath, [BIN, '--config', 'cucumber.js', '--dry-run', ...args, '--format', `json:${report}`], {
26
+ cwd: ROOT,
27
+ encoding: 'utf8',
28
+ env: Object.assign({}, process.env, { WEBSHIP_REPORT_DISABLE: '1', FORCE_COLOR: '0' }),
29
+ });
30
+ if (!fs.existsSync(report)) throw new Error(`cucumber-js ${args.join(' ')} wrote no report:\n${run.stderr}`);
31
+ const found = [];
32
+ for (const feature of JSON.parse(fs.readFileSync(report, 'utf8'))) {
33
+ for (const scenario of feature.elements || []) found.push(`${feature.uri}:${scenario.line}`);
34
+ }
35
+ return { found, warned: /specified paths in both/.test(run.stderr || '') };
36
+ }
37
+
38
+ function featureFiles() {
39
+ return fs.readdirSync(path.join(ROOT, 'tests', 'features')).filter((f) => f.endsWith('.feature')).sort();
40
+ }
41
+
42
+ try {
43
+ const all = scenarios([]);
44
+ const files = featureFiles();
45
+ if (!all.found.length) problems.push('a run that names no feature selected no scenario');
46
+ const inAll = new Set(all.found.map((s) => s.split(':')[0]));
47
+ for (const f of files) {
48
+ if (!inAll.has(`tests/features/${f}`)) problems.push(`a run that names no feature left out tests/features/${f}`);
49
+ }
50
+
51
+ const [first, second] = files;
52
+ const one = scenarios([`tests/features/${first}`]);
53
+ const own = all.found.filter((s) => s.startsWith(`tests/features/${first}:`));
54
+ if (one.found.length !== own.length || one.found.some((s) => !s.startsWith(`tests/features/${first}:`))) {
55
+ problems.push(`naming tests/features/${first} selected ${one.found.length} scenario(s), not its own ${own.length}`);
56
+ }
57
+ if (one.warned) problems.push('naming a feature makes cucumber-js warn that the paths of the configuration and of the command line are merged');
58
+
59
+ const line = own[0].split(':')[1];
60
+ const byLine = scenarios([`tests/features/${first}:${line}`]);
61
+ if (byLine.found.length !== 1 || byLine.found[0] !== own[0]) {
62
+ problems.push(`naming the scenario tests/features/${first}:${line} selected ${byLine.found.length} scenario(s), not 1`);
63
+ }
64
+
65
+ const two = scenarios([`tests/features/${first}`, '--tags', 'not @no-such-tag', `tests/features/${second}`]);
66
+ const ownTwo = all.found.filter((s) => s.startsWith(`tests/features/${first}:`) || s.startsWith(`tests/features/${second}:`));
67
+ if (two.found.length !== ownTwo.length) {
68
+ problems.push(`naming two features around an option selected ${two.found.length} scenario(s), not their ${ownTwo.length}`);
69
+ }
70
+ if (!problems.length) {
71
+ console.log(` no feature named: ${all.found.length} scenarios; ${first}: ${one.found.length}; ${first}:${line}: 1; ${first} and ${second}: ${two.found.length}.`);
72
+ }
73
+ } finally {
74
+ fs.rmSync(tmp, { recursive: true, force: true });
75
+ }
76
+
77
+ if (problems.length) {
78
+ console.error(`\n${problems.length} problem(s) with the paths of the command line:`);
79
+ for (const p of problems) console.error(' ' + p);
80
+ process.exit(1);
81
+ }
82
+ console.log('A feature or a scenario named on the command line runs alone; naming none runs the whole suite.');