webship-js 2.0.11 → 2.0.13
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 +48 -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 +53 -10
- 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/check-switch.html +37 -0
- package/examples/choice-controls.html +29 -0
- package/examples/click-whitespace.html +37 -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/follow-hidden-first.html +29 -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 +17 -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-network-changed.js +137 -0
- package/tests/check-scaffold.js +54 -2
- 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/check-switch.feature +28 -0
- package/tests/features/choice-controls.feature +35 -0
- package/tests/features/click-whitespace.feature +29 -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/follow-hidden-first.feature +9 -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 +53 -20
- 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 +412 -96
- package/tests/step-definitions/form.steps.js +88 -37
- 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 +741 -145
- package/tests/step-definitions/xml.steps.js +49 -15
- package/tests/step-definitions/yaml.steps.js +45 -20
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Runs the steps that print what they found and checks that the text reaches
|
|
5
|
+
// the cucumber JSON report as well as the console: a step's attachment is
|
|
6
|
+
// what the HTML report and a CI artifact show under it.
|
|
7
|
+
//
|
|
8
|
+
// - `I print accessibility violations`
|
|
9
|
+
// - `I print the full accessibility check`
|
|
10
|
+
//
|
|
11
|
+
// The page is written by the check itself (an image without an alt
|
|
12
|
+
// attribute), so no server is needed.
|
|
13
|
+
//
|
|
14
|
+
// Usage: node tests/check-attachments.js (npm run test:attachments)
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const os = require('os');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const { spawnSync } = require('child_process');
|
|
20
|
+
|
|
21
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
22
|
+
const CUCUMBER = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
|
|
23
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-attachments-'));
|
|
24
|
+
const report = path.join(tmp, 'attachments.json');
|
|
25
|
+
const config = path.join(tmp, 'cucumber.js');
|
|
26
|
+
const steps = path.join(tmp, 'page.steps.js');
|
|
27
|
+
const feature = path.join(tmp, 'attachments.feature');
|
|
28
|
+
|
|
29
|
+
fs.writeFileSync(steps, [
|
|
30
|
+
`const { Given } = require(${JSON.stringify(CUCUMBER)});`,
|
|
31
|
+
"Given('a page with an image without an alt attribute', async function () {",
|
|
32
|
+
" await this.page.setContent('<!doctype html><html lang=\"en\"><head><title>Attachments</title></head>' +",
|
|
33
|
+
" '<body><main><h1>Attachments</h1><img src=\"data:image/gif;base64,R0lGODlhAQABAAAAACw=\" width=\"10\" height=\"10\"></main></body></html>');",
|
|
34
|
+
'});',
|
|
35
|
+
'',
|
|
36
|
+
].join('\n'));
|
|
37
|
+
fs.writeFileSync(feature, [
|
|
38
|
+
'Feature: Printed findings reach the report',
|
|
39
|
+
'',
|
|
40
|
+
' Scenario: The accessibility print steps',
|
|
41
|
+
' Given a page with an image without an alt attribute',
|
|
42
|
+
' Then I print accessibility violations',
|
|
43
|
+
' And I print the full accessibility check',
|
|
44
|
+
'',
|
|
45
|
+
].join('\n'));
|
|
46
|
+
const lines = { 'print accessibility violations': 5, 'print the full accessibility check': 6 };
|
|
47
|
+
|
|
48
|
+
const base = require(path.join(ROOT, 'cucumber.js')).default;
|
|
49
|
+
fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
|
|
50
|
+
requireModule: base.requireModule,
|
|
51
|
+
require: base.require.concat([steps]),
|
|
52
|
+
paths: [feature],
|
|
53
|
+
format: [`json:${report}`],
|
|
54
|
+
worldParameters: base.worldParameters,
|
|
55
|
+
}) + ' };');
|
|
56
|
+
|
|
57
|
+
const run = spawnSync(process.execPath, [path.join(CUCUMBER, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
|
|
58
|
+
cwd: ROOT,
|
|
59
|
+
encoding: 'utf8',
|
|
60
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
61
|
+
env: Object.assign({ SLOW_MO: '0' }, process.env, { WEBSHIP_REPORT_DISABLE: '1', WEBSHIP_VIDEO: 'off', WEBSHIP_JS_ERROR_MODE: 'off', FORCE_COLOR: '0' }),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The text of an embedding of the JSON report: cucumber-js writes the data
|
|
66
|
+
* of every attachment in base64.
|
|
67
|
+
*/
|
|
68
|
+
function embeddedText(embedding) {
|
|
69
|
+
const data = String(embedding.data || '');
|
|
70
|
+
const decoded = Buffer.from(data, 'base64').toString('utf8');
|
|
71
|
+
return /image-alt|accessibility/i.test(decoded) ? decoded : data;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const problems = [];
|
|
75
|
+
if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
|
|
76
|
+
problems.push(`The run wrote no report: cucumber-js did not start.\n${run.stdout}\n${run.stderr}`);
|
|
77
|
+
} else {
|
|
78
|
+
const byLine = {};
|
|
79
|
+
for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
|
|
80
|
+
for (const scenario of f.elements || []) {
|
|
81
|
+
for (const step of (scenario.steps || []).filter((s) => !s.hidden)) byLine[step.line] = step;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const [name, line] of Object.entries(lines)) {
|
|
85
|
+
const step = byLine[line];
|
|
86
|
+
if (!step || !step.result || step.result.status !== 'passed') {
|
|
87
|
+
problems.push(`"${name}" (line ${line}) did not pass: ${step && step.result ? step.result.status : 'missing'} ${(step && step.result && step.result.error_message) || ''}`);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const texts = (step.embeddings || []).filter((e) => /^text\//.test(e.mime_type)).map(embeddedText);
|
|
91
|
+
if (!texts.some((text) => /image-alt|image\(s\) without an alt attribute/i.test(text))) {
|
|
92
|
+
problems.push(`"${name}" (line ${line}) attached nothing about the image without alt to the JSON report (${texts.length} text attachment(s)).`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!/image-alt|without an alt attribute/i.test(run.stdout)) {
|
|
96
|
+
problems.push('The print steps no longer print their findings to the console.');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
101
|
+
if (problems.length) {
|
|
102
|
+
console.error('Printed findings in the report:\n - ' + problems.join('\n - '));
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
console.log('Printed findings in the report: both accessibility print steps attach what they print to their step, and still print it.');
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Runs scenarios with a cucumber.js that names its own breakpoints (one of
|
|
5
|
+
// them marked `default: true`, no `desktop`, no `mobile`) and with
|
|
6
|
+
// WEBSHIP_SELECTORS_BREAKPOINTS set, and checks the size each step and tag
|
|
7
|
+
// opens at: every one of them reads the same registry (the built-in names,
|
|
8
|
+
// then worldParameters.selectors.breakpoints, then the environment variable,
|
|
9
|
+
// then the names a scenario adds).
|
|
10
|
+
//
|
|
11
|
+
// The scenarios read the size of a blank page, so no server is needed.
|
|
12
|
+
//
|
|
13
|
+
// Usage: node tests/check-breakpoints.js (npm run test:breakpoints)
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const { spawnSync } = require('child_process');
|
|
19
|
+
|
|
20
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
21
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'webship-js-breakpoints-'));
|
|
22
|
+
const report = path.join(tmp, 'breakpoints.json');
|
|
23
|
+
const config = path.join(tmp, 'cucumber.js');
|
|
24
|
+
const steps = path.join(tmp, 'breakpoints.steps.js');
|
|
25
|
+
const feature = path.join(tmp, 'breakpoints.feature');
|
|
26
|
+
|
|
27
|
+
const cucumber = path.join(ROOT, 'node_modules', '@cucumber', 'cucumber');
|
|
28
|
+
fs.writeFileSync(steps, [
|
|
29
|
+
`const { Then } = require(${JSON.stringify(cucumber)});`,
|
|
30
|
+
"Then('the window should be {int} by {int}', async function (width, height) {",
|
|
31
|
+
' const size = await this.page.evaluate(() => `${window.innerWidth} by ${window.innerHeight}`);',
|
|
32
|
+
' if (size !== `${width} by ${height}`) throw new Error(`The window is ${size}.`);',
|
|
33
|
+
'});',
|
|
34
|
+
'',
|
|
35
|
+
].join('\n'));
|
|
36
|
+
fs.writeFileSync(feature, [
|
|
37
|
+
'Feature: Breakpoints from the configuration and the environment',
|
|
38
|
+
'',
|
|
39
|
+
' @mobile',
|
|
40
|
+
' Scenario: The @mobile tag reads WEBSHIP_SELECTORS_BREAKPOINTS',
|
|
41
|
+
' Then the window should be 360 by 640',
|
|
42
|
+
'',
|
|
43
|
+
' @desktop',
|
|
44
|
+
' Scenario: The @desktop tag opens at the breakpoint marked default',
|
|
45
|
+
' Then the window should be 992 by 768',
|
|
46
|
+
'',
|
|
47
|
+
' Scenario: The set-the-viewport step reads WEBSHIP_SELECTORS_BREAKPOINTS',
|
|
48
|
+
' When I set the viewport to the "tablet" breakpoint',
|
|
49
|
+
' Then the window should be 800 by 600',
|
|
50
|
+
'',
|
|
51
|
+
' Scenario: The viewing-the-site step keeps the configured names beside the environment ones',
|
|
52
|
+
' When I am viewing the site on a "wide" screen',
|
|
53
|
+
' Then the window should be 1300 by 800',
|
|
54
|
+
'',
|
|
55
|
+
" Scenario: A scenario's own breakpoints keep the configured ones",
|
|
56
|
+
' Given the following responsive breakpoints:',
|
|
57
|
+
' | pocket | 320 | 480 |',
|
|
58
|
+
' When I set the viewport to the "wide" breakpoint',
|
|
59
|
+
' Then the window should be 1300 by 800',
|
|
60
|
+
' When I am viewing the site on a "pocket" device',
|
|
61
|
+
' Then the window should be 320 by 480',
|
|
62
|
+
'',
|
|
63
|
+
].join('\n'));
|
|
64
|
+
|
|
65
|
+
const base = require(path.join(ROOT, 'cucumber.js')).default;
|
|
66
|
+
const world = JSON.parse(JSON.stringify(base.worldParameters));
|
|
67
|
+
world.selectors = Object.assign({}, world.selectors, {
|
|
68
|
+
breakpoints: {
|
|
69
|
+
lg: { width: 992, height: 768, default: true },
|
|
70
|
+
wide: { width: 1300, height: 800 },
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
fs.writeFileSync(config, 'module.exports = { default: ' + JSON.stringify({
|
|
74
|
+
requireModule: base.requireModule,
|
|
75
|
+
require: base.require.concat([steps]),
|
|
76
|
+
paths: [feature],
|
|
77
|
+
format: [`json:${report}`],
|
|
78
|
+
worldParameters: world,
|
|
79
|
+
}) + ' };');
|
|
80
|
+
|
|
81
|
+
spawnSync(process.execPath, [path.join(cucumber, 'bin', 'cucumber.js'), '--config', path.relative(ROOT, config)], {
|
|
82
|
+
cwd: ROOT,
|
|
83
|
+
stdio: ['ignore', 'ignore', 'inherit'],
|
|
84
|
+
timeout: 180000,
|
|
85
|
+
env: Object.assign({ SLOW_MO: '0' }, process.env, {
|
|
86
|
+
WEBSHIP_REPORT_DISABLE: '1',
|
|
87
|
+
WEBSHIP_VIDEO: 'off',
|
|
88
|
+
WEBSHIP_JS_ERROR_MODE: 'off',
|
|
89
|
+
WEBSHIP_SCREENSHOT_ON_FAILED: 'false',
|
|
90
|
+
WEBSHIP_SELECTORS_BREAKPOINTS: JSON.stringify({ mobile: { width: 360, height: 640 }, tablet: { width: 800, height: 600 } }),
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const strip = (text) => String(text || '').replace(/\u001b\[[0-9;]*m/g, '');
|
|
95
|
+
const problems = [];
|
|
96
|
+
let count = 0;
|
|
97
|
+
if (!fs.existsSync(report) || !fs.readFileSync(report, 'utf8').trim()) {
|
|
98
|
+
problems.push('The run wrote no report: cucumber-js did not start.');
|
|
99
|
+
} else {
|
|
100
|
+
for (const f of JSON.parse(fs.readFileSync(report, 'utf8'))) {
|
|
101
|
+
for (const scenario of f.elements || []) {
|
|
102
|
+
count += 1;
|
|
103
|
+
const failed = (scenario.steps || []).find((step) => step.result && step.result.status !== 'passed');
|
|
104
|
+
if (failed) {
|
|
105
|
+
problems.push(`"${scenario.name}": ${failed.hidden ? 'a hook' : `"${failed.keyword}${failed.name}"`} ${failed.result.status}: ${strip(failed.result.error_message).split('\n')[0]}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (count !== 5) problems.push(`${count} scenarios ran, not 5.`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
113
|
+
if (problems.length) {
|
|
114
|
+
console.error('Breakpoints:\n - ' + problems.join('\n - '));
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
console.log('Breakpoints: the @mobile and @desktop tags, the set-the-viewport step and the viewing-the-site step read one registry.');
|
|
@@ -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
|
+
}
|