webship-js 2.0.11 → 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.
- package/.circleci/config.yml +10 -1
- package/.drone.yml +7 -7
- package/.github/workflows/github-actions.yml +45 -0
- package/.gitlab-ci.yml +9 -4
- package/.harness/webship-js-pipeline.yml +5 -6
- package/.semaphore/semaphore.yml +6 -9
- package/.teamcity/settings.kts +7 -6
- package/.travis.yml +6 -1
- package/AGENTS.md +1 -1
- package/CLAUDE.md +65 -23
- package/Jenkinsfile +5 -3
- package/azure-pipelines.yml +17 -8
- package/bamboo-specs/bamboo.yml +9 -15
- package/bin/init-webship.js +44 -8
- package/bitbucket-pipelines.yml +5 -1
- package/buildspec.yml +6 -7
- package/cloudbuild.yaml +28 -12
- package/codefresh.yml +6 -6
- package/cucumber.js +17 -10
- package/docs/00-quick-start.md +8 -0
- package/docs/02-bbr-smart-waits.md +15 -10
- package/docs/03-selector-registry.md +24 -0
- package/docs/04-step-reference.md +51 -25
- package/docs/05-web-first-assertions.md +6 -0
- package/docs/07-auth-state.md +1 -1
- package/docs/08-clock-mocking.md +21 -2
- package/docs/09-api-testing.md +40 -2
- package/docs/10-accessibility.md +2 -0
- package/docs/11-debugging.md +3 -1
- package/docs/12-ai-agent-guide.md +5 -0
- package/docs/13-faq.md +72 -1
- package/docs/14-recipes-cookbook.md +2 -0
- package/docs/15-tag-conventions.md +2 -1
- package/docs/16-ci-cd.md +140 -119
- package/docs/README.md +5 -5
- package/docs/advanced-screenshots.md +3 -1
- package/docs/api-step-definitions.md +16 -2
- package/docs/global-settings.md +69 -17
- package/docs/install-webship-js.md +2 -0
- package/docs/step-definitions/then-i-should-see.md +14 -1
- package/docs/step-definitions/then-item-checkbox.md +2 -0
- package/docs/step-definitions/when-i-fill.md +4 -0
- package/docs/step-definitions/when-i-select-option-select-list.md +2 -0
- package/examples/choice-controls.html +29 -0
- package/examples/datetime-fields.html +52 -0
- package/examples/element-selector-hint.html +16 -0
- package/examples/field-states.html +27 -0
- package/examples/fill-in-empty.html +26 -0
- package/examples/fill-unreachable.html +27 -0
- package/examples/iframe-inner.html +20 -0
- package/examples/iframe-nested.html +16 -0
- package/examples/iframe-outer.html +15 -0
- package/examples/multi-value-fields.html +54 -0
- package/examples/registered-names.html +15 -0
- package/examples/select-by-label.html +33 -0
- package/examples/settle-budget.html +21 -0
- package/examples/sorted-tables.html +38 -0
- package/examples/text-matching.html +48 -0
- package/examples/text-order.html +25 -0
- package/examples/touch.html +22 -0
- package/examples/viewport-top.html +36 -0
- package/package.json +16 -1
- package/playwright.config.ts +3 -1
- package/tests/check-api-launch-url.js +106 -0
- package/tests/check-assets.js +103 -0
- package/tests/check-attachments.js +105 -0
- package/tests/check-breakpoints.js +117 -0
- package/tests/check-clock.js +143 -0
- package/tests/check-config.js +90 -0
- package/tests/check-context.js +215 -0
- package/tests/check-dry-run.js +104 -0
- package/tests/check-examples.js +10 -4
- package/tests/check-exit-report.js +141 -0
- package/tests/check-javascript-errors.js +105 -0
- package/tests/check-must-fail.js +5 -4
- package/tests/check-scaffold.js +36 -1
- package/tests/check-screenshots.js +117 -0
- package/tests/check-settle-verbs.js +137 -0
- package/tests/check-time-limit.js +104 -0
- package/tests/check-video.js +156 -0
- package/tests/check-world.js +167 -0
- package/tests/features/api-base-url.feature +25 -0
- package/tests/features/api-form-data.feature +18 -0
- package/tests/features/api-json-paths.feature +24 -0
- package/tests/features/api-response-contains.feature +21 -0
- package/tests/features/api-response-header-presence.feature +17 -0
- package/tests/features/api-response-header.feature +17 -0
- package/tests/features/api-saved-placeholders.feature +37 -0
- package/tests/features/api-step-definitions-individual.feature +1 -1
- package/tests/features/api-tables.feature +40 -0
- package/tests/features/breakpoints.feature +25 -0
- package/tests/features/choice-controls.feature +35 -0
- package/tests/features/complete-api-testing-examples.feature +1 -1
- package/tests/features/datetime-field-lookup.feature +29 -0
- package/tests/features/element-selector-hint.feature +14 -0
- package/tests/features/field-state.feature +21 -0
- package/tests/features/fill-in-empty-value.feature +41 -0
- package/tests/features/fill-reachable.feature +13 -0
- package/tests/features/iframe-nested.feature +43 -0
- package/tests/features/javascript-tolerated-errors.feature +20 -0
- package/tests/features/modal-open.feature +13 -0
- package/tests/features/multi-value-field-lookup.feature +30 -0
- package/tests/features/registered-names.feature +14 -0
- package/tests/features/select-by-label.feature +31 -0
- package/tests/features/selector-files.feature +14 -0
- package/tests/features/selectors-table-header.feature +35 -0
- package/tests/features/settle-budget.feature +11 -0
- package/tests/features/sorted-tables.feature +19 -0
- package/tests/features/storage-quoted-values.feature +26 -0
- package/tests/features/text-matching.feature +38 -0
- package/tests/features/text-order.feature +14 -0
- package/tests/features/touch.feature +21 -0
- package/tests/features/viewport-top.feature +13 -0
- package/tests/features/xml-namespaces.feature +34 -0
- package/tests/must-fail/api-json-paths.feature +21 -0
- package/tests/must-fail/api-response-contains.feature +23 -0
- package/tests/must-fail/api-response-header-presence.feature +17 -0
- package/tests/must-fail/api-response-header.feature +21 -0
- package/tests/must-fail/api-without-base-url.feature +11 -0
- package/tests/must-fail/breakpoints.feature +15 -0
- package/tests/must-fail/choice-controls.feature +25 -0
- package/tests/must-fail/clock.feature +11 -0
- package/tests/must-fail/datetime-field.feature +10 -0
- package/tests/must-fail/element-selector-hint.feature +17 -0
- package/tests/must-fail/field-state.feature +20 -0
- package/tests/must-fail/fill-field.feature +30 -0
- package/tests/must-fail/iframe-text.feature +17 -0
- package/tests/must-fail/modal-open.feature +26 -0
- package/tests/must-fail/multi-value-field.feature +18 -0
- package/tests/must-fail/registered-names.feature +25 -0
- package/tests/must-fail/select-list.feature +15 -0
- package/tests/must-fail/selector-files.feature +10 -0
- package/tests/must-fail/sorted-tables.feature +20 -0
- package/tests/must-fail/storage-before-a-page.feature +13 -0
- package/tests/must-fail/text-matching.feature +16 -0
- package/tests/must-fail/text-order.feature +15 -0
- package/tests/must-fail/viewport-top.feature +20 -0
- package/tests/must-fail/yaml-numbers.feature +48 -0
- package/tests/step-definitions/a11y.steps.js +24 -15
- package/tests/step-definitions/action.steps.js +22 -8
- package/tests/step-definitions/api.steps.js +349 -67
- package/tests/step-definitions/assertion.steps.js +100 -10
- package/tests/step-definitions/auth.steps.js +15 -18
- package/tests/step-definitions/clock.steps.js +22 -0
- package/tests/step-definitions/debug.steps.js +8 -0
- package/tests/step-definitions/dialog.steps.js +7 -0
- package/tests/step-definitions/element.steps.js +132 -17
- package/tests/step-definitions/field.steps.js +409 -96
- package/tests/step-definitions/form.steps.js +76 -29
- package/tests/step-definitions/iframe.steps.js +89 -29
- package/tests/step-definitions/input.steps.js +26 -7
- package/tests/step-definitions/javascript.steps.js +64 -22
- package/tests/step-definitions/modal.steps.js +79 -13
- package/tests/step-definitions/navigation.steps.js +14 -0
- package/tests/step-definitions/network.steps.js +15 -5
- package/tests/step-definitions/response.steps.js +6 -4
- package/tests/step-definitions/responsive.steps.js +26 -33
- package/tests/step-definitions/screenshot.steps.js +25 -8
- package/tests/step-definitions/scroll.steps.js +20 -0
- package/tests/step-definitions/selectors.steps.js +95 -48
- package/tests/step-definitions/storage.steps.js +38 -13
- package/tests/step-definitions/table.steps.js +81 -6
- package/tests/step-definitions/video.steps.js +52 -55
- package/tests/step-definitions/wait.steps.js +88 -23
- package/tests/step-definitions/web-first.steps.js +69 -35
- package/tests/step-definitions/webship.js +681 -143
- package/tests/step-definitions/xml.steps.js +49 -15
- package/tests/step-definitions/yaml.steps.js +45 -20
package/tests/check-examples.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
// definitions, without a browser:
|
|
6
6
|
//
|
|
7
7
|
// 1. every step definition in tests/step-definitions carries a JSDoc block
|
|
8
|
-
// with a description and at least
|
|
8
|
+
// with a description and at least five "Example #n:" blocks that use
|
|
9
|
+
// the step itself (CLAUDE.md §4.2),
|
|
9
10
|
// 2. every step line of every example resolves to exactly one definition
|
|
10
11
|
// (none undefined, none ambiguous),
|
|
11
12
|
// 3. at least one example of a definition resolves to that definition,
|
|
@@ -72,7 +73,7 @@ function readDefinitions(file) {
|
|
|
72
73
|
if (!examples.length && raw.trim()) description.push(raw.trim());
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
|
-
definitions.push({ file, line, pattern: m[2], hasDoc: doc !== null, description: description.join(' '), examples, own: 0 });
|
|
76
|
+
definitions.push({ file, line, pattern: m[2], hasDoc: doc !== null, description: description.join(' '), examples, own: 0, ownExamples: new Set() });
|
|
76
77
|
}
|
|
77
78
|
return definitions;
|
|
78
79
|
}
|
|
@@ -104,7 +105,7 @@ function buildFeature(file, definitions) {
|
|
|
104
105
|
lines.push(` Scenario: ${file} line ${definition.line} example ${n + 1}`);
|
|
105
106
|
for (const item of body) {
|
|
106
107
|
lines.push(item.text);
|
|
107
|
-
if (item.step) owners[lines.length] = { definition, step: item.step };
|
|
108
|
+
if (item.step) owners[lines.length] = { definition, step: item.step, example: n };
|
|
108
109
|
}
|
|
109
110
|
lines.push('');
|
|
110
111
|
});
|
|
@@ -192,12 +193,17 @@ for (const feature of examples.report) {
|
|
|
192
193
|
const status = step.result && step.result.status;
|
|
193
194
|
if (status === 'undefined') problems.push(`${where} example step matches no definition: ${owner.step}`);
|
|
194
195
|
else if (status === 'ambiguous') problems.push(`${where} example step matches more than one definition: ${owner.step}`);
|
|
195
|
-
else if (matched[`${path.basename(feature.uri)}:${step.line}`] === where)
|
|
196
|
+
else if (matched[`${path.basename(feature.uri)}:${step.line}`] === where) {
|
|
197
|
+
owner.definition.own++;
|
|
198
|
+
owner.definition.ownExamples.add(owner.example);
|
|
199
|
+
}
|
|
196
200
|
}
|
|
197
201
|
}
|
|
198
202
|
}
|
|
203
|
+
const MIN_EXAMPLES = 5;
|
|
199
204
|
for (const d of all) {
|
|
200
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}`);
|
|
201
207
|
}
|
|
202
208
|
|
|
203
209
|
// 2. The features of the suite.
|
|
@@ -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.');
|
package/tests/check-must-fail.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
// Runs the scenarios of tests/must-fail/ and checks that every one of them
|
|
5
5
|
// FAILS, at its last step, with the message its description announces
|
|
6
|
-
// ("Fails with: ..."), and that the message names the page
|
|
7
|
-
//
|
|
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.
|
|
8
9
|
//
|
|
9
10
|
// A step that cannot fail proves nothing, and a failure nobody can read
|
|
10
11
|
// costs a tester an hour. Each scenario here asserts something that is not
|
|
@@ -67,7 +68,7 @@ if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
|
|
|
67
68
|
const shown = message.split('\n').slice(0, 4).join('\n ');
|
|
68
69
|
if (!message.includes(wanted)) { problems.push(`${where}: failed, but not with "${wanted}":\n ${shown}`); continue; }
|
|
69
70
|
if (!/^\s*Hint: \S/m.test(message)) { problems.push(`${where}: the failure carries no hint:\n ${shown}`); continue; }
|
|
70
|
-
if (!/^\s*Page: \S/m.test(message)) { problems.push(`${where}: the failure
|
|
71
|
+
if (!/^\s*(?:Page|Request): \S/m.test(message)) { problems.push(`${where}: the failure names neither the page nor the request:\n ${shown}`); continue; }
|
|
71
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; }
|
|
72
73
|
console.log(` fails as it must: ${scenario.name}\n ${message.split('\n')[0].trim()}`);
|
|
73
74
|
}
|
|
@@ -81,4 +82,4 @@ if (problems.length) {
|
|
|
81
82
|
console.error(`\n${problems.length} problem(s) in ${count} must-fail scenario(s):\n ${problems.join('\n ')}`);
|
|
82
83
|
process.exit(1);
|
|
83
84
|
}
|
|
84
|
-
console.log(`\n${count} must-fail scenarios: each failed at its last step with the announced message, the page and a hint.`);
|
|
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.`);
|
package/tests/check-scaffold.js
CHANGED
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
// pages of this repository, served on a free port),
|
|
12
12
|
// 3. a feature named on the command line runs alone,
|
|
13
13
|
// 4. a second scaffold run changes nothing, and a `test` script the project
|
|
14
|
-
// chose itself is kept
|
|
14
|
+
// chose itself is kept,
|
|
15
|
+
// 5. a `test` script that runs Nightwatch (a project from webship-js 1.x)
|
|
16
|
+
// is replaced by the suite and kept as `test:nightwatch`,
|
|
17
|
+
// 6. `--force` rewrites the scaffold's files but keeps the project's own
|
|
18
|
+
// steps in tests/step-definitions/custom.js.
|
|
15
19
|
//
|
|
16
20
|
// The browser install is skipped (--skip-browsers): Chromium must be in the
|
|
17
21
|
// Playwright cache already, as it is after `npx playwright install chromium`.
|
|
@@ -184,6 +188,37 @@ async function main() {
|
|
|
184
188
|
if (ownPkg.scripts.test !== 'node my-own-tests.js') problems.push(`the scaffold replaced a test script of the project: ${ownPkg.scripts.test}`);
|
|
185
189
|
if (!ownPkg.scripts['test:chromium']) problems.push('the scaffold did not add test:chromium beside an existing test script');
|
|
186
190
|
|
|
191
|
+
// A project from webship-js 1.x: its test script runs Nightwatch.
|
|
192
|
+
const legacy = path.join(tmp, 'from-1x');
|
|
193
|
+
fs.mkdirSync(legacy);
|
|
194
|
+
const nightwatch = 'nightwatch --format @cucumber/pretty-formatter --format json:./tests/reports/cucumber-report.json';
|
|
195
|
+
fs.writeFileSync(path.join(legacy, 'package.json'), JSON.stringify({ name: 'from-1x', version: '1.0.0', scripts: { test: nightwatch } }, null, 2));
|
|
196
|
+
const legacyRun = scaffold(legacy);
|
|
197
|
+
const legacyPkg = JSON.parse(fs.readFileSync(path.join(legacy, 'package.json'), 'utf8'));
|
|
198
|
+
if (legacyPkg.scripts.test !== 'cucumber-js --config cucumber.js') {
|
|
199
|
+
problems.push(`the scaffold kept a Nightwatch test script from 1.x: "npm test" is still ${legacyPkg.scripts.test}`);
|
|
200
|
+
}
|
|
201
|
+
if (legacyPkg.scripts['test:nightwatch'] !== nightwatch) {
|
|
202
|
+
problems.push(`the scaffold did not keep the old Nightwatch command as test:nightwatch: ${legacyPkg.scripts['test:nightwatch']}`);
|
|
203
|
+
}
|
|
204
|
+
if (legacyPkg.scripts.test !== nightwatch && !/nightwatch/i.test(legacyRun.stdout || '')) {
|
|
205
|
+
problems.push('the scaffold replaced the Nightwatch test script without saying so');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// --force keeps the project's own steps.
|
|
209
|
+
const customFile = path.join(project, 'tests', 'step-definitions', 'custom.js');
|
|
210
|
+
const ownSteps = fs.readFileSync(customFile, 'utf8') + "\nGiven('a step of the project', function () {});\n";
|
|
211
|
+
fs.writeFileSync(customFile, ownSteps);
|
|
212
|
+
fs.writeFileSync(path.join(project, 'playwright.config.ts'), '// changed by the project\n');
|
|
213
|
+
const forced = spawnSync(process.execPath, [INIT, '--cwd', project, '--skip-browsers', '--force'], { encoding: 'utf8' });
|
|
214
|
+
if (forced.status !== 0) problems.push(`the scaffold with --force exited with ${forced.status}`);
|
|
215
|
+
if (fs.readFileSync(customFile, 'utf8') !== ownSteps) {
|
|
216
|
+
problems.push('the scaffold with --force overwrote tests/step-definitions/custom.js, the steps of the project');
|
|
217
|
+
}
|
|
218
|
+
if (fs.readFileSync(path.join(project, 'playwright.config.ts'), 'utf8') === '// changed by the project\n') {
|
|
219
|
+
problems.push('the scaffold with --force did not rewrite playwright.config.ts');
|
|
220
|
+
}
|
|
221
|
+
|
|
187
222
|
// No package.json at all: the scaffold writes one.
|
|
188
223
|
const bare = path.join(tmp, 'no-package-json');
|
|
189
224
|
fs.mkdirSync(bare);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Runs three scenarios with the failure screenshots on and checks which of
|
|
5
|
+
// them leave a "failed_" screenshot: the one whose step fails does; the one
|
|
6
|
+
// that a step skips on purpose (the step returns 'skipped', the way a suite
|
|
7
|
+
// leaves out a scenario that does not apply to the site) and the one that
|
|
8
|
+
// stops at a pending step do not. The failure screenshot is also attached to
|
|
9
|
+
// the failed step in the JSON report (an image/png embedding), so the HTML
|
|
10
|
+
// report shows it; the other two steps carry none.
|
|
11
|
+
//
|
|
12
|
+
// The scenarios never navigate, so no server is needed.
|
|
13
|
+
//
|
|
14
|
+
// Usage: node tests/check-screenshots.js (npm run test:screenshots)
|
|
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-screenshots-'));
|
|
23
|
+
const shots = path.join(tmp, 'screenshots');
|
|
24
|
+
const report = path.join(tmp, 'outcomes.json');
|
|
25
|
+
const config = path.join(tmp, 'cucumber.js');
|
|
26
|
+
const steps = path.join(tmp, 'outcomes.steps.js');
|
|
27
|
+
const feature = path.join(tmp, 'outcomes.feature');
|
|
28
|
+
|
|
29
|
+
const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
|
|
30
|
+
fs.writeFileSync(steps, [
|
|
31
|
+
`const { Given, Then } = require(${JSON.stringify(cucumber)});`,
|
|
32
|
+
"Given('this scenario does not apply here', function () { return 'skipped'; });",
|
|
33
|
+
"Given('this step is not written yet', function () { return 'pending'; });",
|
|
34
|
+
"Then('this step fails on purpose', function () { throw new Error('Failing on purpose.'); });",
|
|
35
|
+
'',
|
|
36
|
+
].join('\n'));
|
|
37
|
+
fs.writeFileSync(feature, [
|
|
38
|
+
'Feature: Outcomes and failure screenshots',
|
|
39
|
+
'',
|
|
40
|
+
' Scenario: A step skips the scenario on purpose',
|
|
41
|
+
' Given this scenario does not apply here',
|
|
42
|
+
'',
|
|
43
|
+
' Scenario: A step is pending',
|
|
44
|
+
' Given this step is not written yet',
|
|
45
|
+
'',
|
|
46
|
+
' Scenario: A step fails',
|
|
47
|
+
' Then this step fails on purpose',
|
|
48
|
+
'',
|
|
49
|
+
' Scenario: Named screenshots',
|
|
50
|
+
' Then I save screenshot with name "homepage.png"',
|
|
51
|
+
' And I save fullscreen screenshot with name "full-page.JPG"',
|
|
52
|
+
' And I save screenshot with name "plain-name"',
|
|
53
|
+
'',
|
|
54
|
+
].join('\n'));
|
|
55
|
+
const lines = { skipped: 4, pending: 7, failed: 10 };
|
|
56
|
+
|
|
57
|
+
const base = require(path.join(ROOT, 'cucumber.js')).default;
|
|
58
|
+
const world = JSON.parse(JSON.stringify(base.worldParameters));
|
|
59
|
+
world.screenshot = Object.assign({}, world.screenshot, { dir: shots, onFailed: true, onEveryStep: false, purge: false });
|
|
60
|
+
fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
|
|
61
|
+
requireModule: base.requireModule,
|
|
62
|
+
require: base.require.concat([steps]),
|
|
63
|
+
paths: [feature],
|
|
64
|
+
format: [`json:${report}`],
|
|
65
|
+
worldParameters: world,
|
|
66
|
+
}) + ' };');
|
|
67
|
+
|
|
68
|
+
spawnSync(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
|
|
69
|
+
cwd: ROOT,
|
|
70
|
+
stdio: ['ignore', 'ignore', 'inherit'],
|
|
71
|
+
env: Object.assign({ SLOW_MO: '0' }, process.env, { WEBSHIP_REPORT_DISABLE: '1', WEBSHIP_VIDEO: 'off', WEBSHIP_JS_ERROR_MODE: 'off' }),
|
|
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.');
|
|
77
|
+
} else {
|
|
78
|
+
const statuses = {};
|
|
79
|
+
const images = {};
|
|
80
|
+
for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
|
|
81
|
+
for (const scenario of f.elements || []) {
|
|
82
|
+
for (const step of (scenario.steps || []).filter((s) => !s.hidden)) {
|
|
83
|
+
statuses[step.line] = step.result && step.result.status;
|
|
84
|
+
images[step.line] = (step.embeddings || []).filter((e) => e.mime_type === 'image/png' && e.data).length;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const [outcome, line] of Object.entries(lines)) {
|
|
89
|
+
if (statuses[line] !== outcome) problems.push(`The step on line ${line} ended "${statuses[line]}", not "${outcome}": the check itself is broken.`);
|
|
90
|
+
}
|
|
91
|
+
const files = fs.existsSync(shots) ? fs.readdirSync(shots).filter((name) => name.startsWith('failed_')) : [];
|
|
92
|
+
const forLine = (line) => files.filter((name) => new RegExp(`\\.feature_${line}\\.(png|html)$`).test(name));
|
|
93
|
+
if (!forLine(lines.failed).some((name) => name.endsWith('.png'))) {
|
|
94
|
+
problems.push(`The failed step (line ${lines.failed}) left no failure screenshot; files: ${files.join(', ') || 'none'}.`);
|
|
95
|
+
}
|
|
96
|
+
for (const outcome of ['skipped', 'pending']) {
|
|
97
|
+
const found = forLine(lines[outcome]);
|
|
98
|
+
if (found.length) problems.push(`The ${outcome} step (line ${lines[outcome]}) left failure screenshots: ${found.join(', ')}.`);
|
|
99
|
+
if (images[lines[outcome]]) problems.push(`The ${outcome} step (line ${lines[outcome]}) carries ${images[lines[outcome]]} screenshot(s) in the JSON report.`);
|
|
100
|
+
}
|
|
101
|
+
// A name that ends with the extension of a file the step writes keeps
|
|
102
|
+
// that one extension: "homepage.png" is homepage.png, not homepage.png.png.
|
|
103
|
+
const saved = fs.existsSync(shots) ? fs.readdirSync(shots) : [];
|
|
104
|
+
for (const name of ['homepage.png', 'homepage.html', 'full-page.png', 'full-page.html', 'plain-name.png', 'plain-name.html']) {
|
|
105
|
+
if (!saved.includes(name)) problems.push(`The named screenshot ${name} was not written; files: ${saved.filter((f) => !f.startsWith('failed_')).join(', ') || 'none'}.`);
|
|
106
|
+
}
|
|
107
|
+
if (images[lines.failed] !== 1) {
|
|
108
|
+
problems.push(`The failed step (line ${lines.failed}) carries ${images[lines.failed] || 0} screenshot(s) in the JSON report, not 1: no report can show it.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
113
|
+
if (problems.length) {
|
|
114
|
+
console.error('Failure screenshots:\n - ' + problems.join('\n - '));
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
console.log('Failure screenshots: the failed step left one, attached to it in the JSON report; the skipped and the pending step left none. Named screenshots keep the one extension their name gives.');
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Runs a project's own steps (written here, the way a project writes them)
|
|
5
|
+
// whose words carry a page-changing verb — add, log out, enter, open,
|
|
6
|
+
// delete, save — and checks that the settle after the step waited for the
|
|
7
|
+
// page: the next step reads the element once and finds the change that
|
|
8
|
+
// arrives 600 ms after the action. A built-in assertion whose quoted text
|
|
9
|
+
// holds such a word ("Then I should see "Delete"") gets no settle.
|
|
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-settle-verbs.js (npm run test:settle-verbs)
|
|
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-settle-verbs-'));
|
|
24
|
+
const report = path.join(tmp, 'settle.json');
|
|
25
|
+
const config = path.join(tmp, 'cucumber.js');
|
|
26
|
+
const steps = path.join(tmp, 'project.steps.js');
|
|
27
|
+
const feature = path.join(tmp, 'settle.feature');
|
|
28
|
+
const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
|
|
29
|
+
|
|
30
|
+
const PAGE = `<!doctype html><html><head><title>Shop</title></head><body>
|
|
31
|
+
<h1>Shop</h1>
|
|
32
|
+
<button id="act" type="button">Act</button>
|
|
33
|
+
<p id="status">Nothing yet</p>
|
|
34
|
+
<p>Delete</p>
|
|
35
|
+
<script>
|
|
36
|
+
document.getElementById('act').addEventListener('click', function () {
|
|
37
|
+
setTimeout(function () { document.getElementById('status').textContent = 'Done'; }, 600);
|
|
38
|
+
});
|
|
39
|
+
</script></body></html>`;
|
|
40
|
+
|
|
41
|
+
// A project's own steps: each one clicks the button the way a custom step
|
|
42
|
+
// would, without waiting for anything.
|
|
43
|
+
const phrases = [
|
|
44
|
+
'I add "Laptop" to the cart',
|
|
45
|
+
'I log out of the shop',
|
|
46
|
+
'I enter the 2FA code "123456"',
|
|
47
|
+
'I open the account menu',
|
|
48
|
+
'I delete the draft',
|
|
49
|
+
'I save the order',
|
|
50
|
+
];
|
|
51
|
+
fs.writeFileSync(steps, [
|
|
52
|
+
`const { When } = require(${JSON.stringify(cucumber)});`,
|
|
53
|
+
...phrases.map((p) => {
|
|
54
|
+
const args = (p.match(/"[^"]*"/g) || []).map((_, i) => `value${i}`).join(', ');
|
|
55
|
+
return `When(${JSON.stringify(p.replace(/"[^"]*"/g, '{string}'))}, async function (${args}) { await this.page.click('#act'); });`;
|
|
56
|
+
}),
|
|
57
|
+
'',
|
|
58
|
+
].join('\n'));
|
|
59
|
+
fs.writeFileSync(feature, [
|
|
60
|
+
'Feature: A project step that changes the page is followed by the settle',
|
|
61
|
+
'',
|
|
62
|
+
...phrases.flatMap((p) => [
|
|
63
|
+
` Scenario: ${p}`,
|
|
64
|
+
' Given I am on "/"',
|
|
65
|
+
` When ${p}`,
|
|
66
|
+
' Then I should see "Done" in the "#status" element',
|
|
67
|
+
'',
|
|
68
|
+
]),
|
|
69
|
+
' Scenario: A wait for AJAX in lower case',
|
|
70
|
+
' Given I am on "/"',
|
|
71
|
+
' When I wait for ajax to finish',
|
|
72
|
+
' Then I should see "Shop"',
|
|
73
|
+
'',
|
|
74
|
+
].join('\n'));
|
|
75
|
+
|
|
76
|
+
const server = http.createServer((req, res) => {
|
|
77
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
78
|
+
res.end(PAGE);
|
|
79
|
+
});
|
|
80
|
+
server.listen(0, '127.0.0.1', () => {
|
|
81
|
+
const base = `http://127.0.0.1:${server.address().port}`;
|
|
82
|
+
const defaults = require(path.join(ROOT, 'cucumber.js')).default;
|
|
83
|
+
const world = JSON.parse(JSON.stringify(defaults.worldParameters));
|
|
84
|
+
world.launchUrl = base;
|
|
85
|
+
fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
|
|
86
|
+
requireModule: defaults.requireModule,
|
|
87
|
+
require: defaults.require.concat([steps]),
|
|
88
|
+
paths: [feature],
|
|
89
|
+
format: [`json:${report}`],
|
|
90
|
+
worldParameters: world,
|
|
91
|
+
}) + ' };');
|
|
92
|
+
const env = Object.assign({ SLOW_MO: '0' }, process.env, {
|
|
93
|
+
LAUNCH_URL: base,
|
|
94
|
+
WEBSHIP_REPORT_DISABLE: '1',
|
|
95
|
+
WEBSHIP_VIDEO: 'off',
|
|
96
|
+
WEBSHIP_JS_ERROR_MODE: 'off',
|
|
97
|
+
WEBSHIP_SCREENSHOT_ON_FAILED: 'false',
|
|
98
|
+
});
|
|
99
|
+
delete env.WEBSHIP_AUTO_SETTLE;
|
|
100
|
+
const run = spawn(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
|
|
101
|
+
cwd: ROOT,
|
|
102
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
103
|
+
env,
|
|
104
|
+
});
|
|
105
|
+
let errors = '';
|
|
106
|
+
run.stderr.on('data', (chunk) => { errors += chunk; });
|
|
107
|
+
const timer = setTimeout(() => run.kill('SIGKILL'), 180000);
|
|
108
|
+
run.on('exit', () => {
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
server.close();
|
|
111
|
+
finish(errors);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
function finish(errors) {
|
|
116
|
+
const strip = (text) => String(text || '').replace(/\u001b\[[0-9;]*m/g, '');
|
|
117
|
+
const problems = [];
|
|
118
|
+
let count = 0;
|
|
119
|
+
if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
|
|
120
|
+
problems.push(`The run wrote no report.\n${strip(errors).slice(-1500)}`);
|
|
121
|
+
} else {
|
|
122
|
+
for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
|
|
123
|
+
for (const scenario of f.elements || []) {
|
|
124
|
+
count += 1;
|
|
125
|
+
const failed = (scenario.steps || []).find((step) => step.result && step.result.status !== 'passed');
|
|
126
|
+
if (failed) problems.push(`"${scenario.name}": ${failed.hidden ? 'a hook' : `"${failed.keyword}${failed.name}"`} ${failed.result.status}: ${strip(failed.result.error_message).split('\n')[0]}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (count !== phrases.length + 1) problems.push(`${count} scenarios ran, not ${phrases.length + 1}.`);
|
|
130
|
+
}
|
|
131
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
132
|
+
if (problems.length) {
|
|
133
|
+
console.error('The settle after a project step:\n - ' + problems.join('\n - '));
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
console.log('The settle after a project step: every page-changing verb waits for the page; the AJAX wait reads in lower case.');
|
|
137
|
+
}
|