@gnuechtel/nx-cucumber 2.0.0-13867546447.beta.4 → 2.0.0-beta.2
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/README.md +2 -73
- package/package.json +3 -6
- package/src/core/web-server.d.ts +7 -10
- package/src/core/web-server.js +15 -63
- package/src/core/web-server.js.map +1 -1
- package/src/generators/project/files/all/cucumber.js.template +7 -0
- package/src/generators/project/project.js +5 -55
- package/src/generators/project/project.js.map +1 -1
- package/src/index.d.ts +0 -1
- package/src/index.js +1 -3
- package/src/index.js.map +1 -1
- package/src/playwright/playwright-hooks.js +11 -47
- package/src/playwright/playwright-hooks.js.map +1 -1
- package/migrations.json +0 -10
- package/src/migrations/update-2-0-0/migrate-cucumber-api-to-inferred-tasks.d.ts +0 -20
- package/src/migrations/update-2-0-0/migrate-cucumber-api-to-inferred-tasks.js +0 -205
- package/src/migrations/update-2-0-0/migrate-cucumber-api-to-inferred-tasks.js.map +0 -1
package/README.md
CHANGED
|
@@ -151,13 +151,7 @@ The generator creates:
|
|
|
151
151
|
- A minimal `project.json` with lint target and implicit dependencies
|
|
152
152
|
- Feature files, step definitions, and TypeScript configuration
|
|
153
153
|
|
|
154
|
-
The `e2e` target
|
|
155
|
-
|
|
156
|
-
- **Core runner:** no explicit `e2e` target is generated. The `e2e` task is inferred by the plugin from `cucumber.js`.
|
|
157
|
-
- **Playwright runner:** explicit command targets are generated:
|
|
158
|
-
- `e2e-prepare` installs Playwright Chromium (Linux uses `--with-deps`).
|
|
159
|
-
- `e2e` runs `start-server-and-test` with `kill-port` before Cucumber execution.
|
|
160
|
-
- `e2e-ci` runs `e2e-prepare` and then `e2e`.
|
|
154
|
+
The `e2e` target is **not** defined in `project.json`. It is inferred by the plugin from the `cucumber.js` config file.
|
|
161
155
|
|
|
162
156
|
### Additional project generator options
|
|
163
157
|
|
|
@@ -167,18 +161,12 @@ All possible project generator options may be passed as command-line parameters
|
|
|
167
161
|
|
|
168
162
|
### Inferred tasks
|
|
169
163
|
|
|
170
|
-
In 2.x,
|
|
164
|
+
In 2.x, the `e2e` target is automatically inferred when the plugin detects a `cucumber.js` config file in a project directory. No executor configuration is needed:
|
|
171
165
|
|
|
172
166
|
```bash
|
|
173
167
|
npx nx e2e my-project-e2e
|
|
174
168
|
```
|
|
175
169
|
|
|
176
|
-
For Playwright projects generated by this plugin, explicit command targets are created:
|
|
177
|
-
|
|
178
|
-
- `e2e-prepare`: browser setup
|
|
179
|
-
- `e2e`: test execution with managed web-server lifecycle
|
|
180
|
-
- `e2e-ci`: `e2e-prepare` + `e2e`
|
|
181
|
-
|
|
182
170
|
### Plugin registration
|
|
183
171
|
|
|
184
172
|
To enable inferred tasks, register the plugin in `nx.json`:
|
|
@@ -546,32 +534,6 @@ Since 2.x uses framework-native execution via `npx cucumber-js`, all Cucumber CL
|
|
|
546
534
|
|
|
547
535
|
If a feature is missing, please open an issue with a minimal reproducible setup.
|
|
548
536
|
|
|
549
|
-
### Windows Playwright jobs hang or time out unexpectedly
|
|
550
|
-
|
|
551
|
-
If Windows jobs appear to hang after scenarios finish, or fail intermittently before the first browser step, use the generated Playwright `e2e` command pattern:
|
|
552
|
-
|
|
553
|
-
```bash
|
|
554
|
-
npx kill-port 4200 && start-server-and-test "npx nx run <app>:serve --port=4200 --strictPort" http://localhost:4200 "npx cucumber-js --config <e2e-project>/cucumber.js"
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
For CI, prefer the generated `e2e-ci` target to include browser preparation:
|
|
558
|
-
|
|
559
|
-
```bash
|
|
560
|
-
npx nx run <e2e-project>:e2e-ci
|
|
561
|
-
```
|
|
562
|
-
|
|
563
|
-
Why this is more stable:
|
|
564
|
-
|
|
565
|
-
- `kill-port` removes stale listeners before readiness checks.
|
|
566
|
-
- `start-server-and-test` owns start/wait/test/stop lifecycle in one process chain.
|
|
567
|
-
- `--strictPort` prevents fallback port switches by Vite that can break URL expectations.
|
|
568
|
-
|
|
569
|
-
For this repository, use the dedicated regression command:
|
|
570
|
-
|
|
571
|
-
```bash
|
|
572
|
-
npm run e2e:port-regression:react-example
|
|
573
|
-
```
|
|
574
|
-
|
|
575
537
|
## Migration from 1.x
|
|
576
538
|
|
|
577
539
|
### Prerequisites
|
|
@@ -579,27 +541,6 @@ npm run e2e:port-regression:react-example
|
|
|
579
541
|
- Upgrade to Nx `>=22`
|
|
580
542
|
- Install `@gnuechtel/nx-cucumber@2`
|
|
581
543
|
|
|
582
|
-
### Automated migration via nx migrate
|
|
583
|
-
|
|
584
|
-
You can run the legacy executor migration as part of the standard Nx migration flow:
|
|
585
|
-
|
|
586
|
-
```bash
|
|
587
|
-
npx nx migrate @gnuechtel/nx-cucumber@2
|
|
588
|
-
npx nx migrate --run-migrations
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
What this migration does:
|
|
592
|
-
|
|
593
|
-
- Detects projects using `@gnuechtel/nx-cucumber:cucumber-api`.
|
|
594
|
-
- Adds `@gnuechtel/nx-cucumber` to `nx.json` plugins (if missing).
|
|
595
|
-
- Removes legacy executor targets (`e2e-cucumber`, and legacy `e2e` wrappers pointing to `e2e-cucumber`).
|
|
596
|
-
- Creates a `cucumber.js` file when missing, based on detected legacy options.
|
|
597
|
-
- Writes a migration report to `tmp/nx-cucumber-migration-report.json`.
|
|
598
|
-
|
|
599
|
-
Dry-run mode:
|
|
600
|
-
|
|
601
|
-
- Set `NX_CUCUMBER_MIGRATION_DRY_RUN=true` before running migrations to print planned changes without modifying files.
|
|
602
|
-
|
|
603
544
|
### Step 1: Register the plugin
|
|
604
545
|
|
|
605
546
|
Add the plugin to `nx.json`:
|
|
@@ -666,15 +607,3 @@ npx nx e2e my-project-e2e
|
|
|
666
607
|
```
|
|
667
608
|
|
|
668
609
|
The inferred target runs `npx cucumber-js` with the configuration from `cucumber.js`.
|
|
669
|
-
|
|
670
|
-
### Rollback strategy
|
|
671
|
-
|
|
672
|
-
- Revert the migration commit in git if validation fails.
|
|
673
|
-
- Remove `@gnuechtel/nx-cucumber` from `nx.json` plugins if rollback to 1.x is required.
|
|
674
|
-
- Restore previous `project.json` executor targets and `cucumber.js` from version control.
|
|
675
|
-
|
|
676
|
-
### Known limitations
|
|
677
|
-
|
|
678
|
-
- Existing `cucumber.js` files are not overwritten automatically.
|
|
679
|
-
- Custom legacy watch flows (for example `e2e-watch` commands using watch-message) are reported for manual review.
|
|
680
|
-
- Highly customized run-command wrappers may require manual cleanup after migration.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gnuechtel/nx-cucumber",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "Plugin to use Cucumber within Nx workspaces",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"@nx/devkit": ">=22 <23",
|
|
13
13
|
"minimatch": "^10.0.0",
|
|
14
14
|
"tslib": "^2.3.0",
|
|
15
|
-
"@gnuechtel/shared-coverage": "2.0.0-
|
|
16
|
-
"@gnuechtel/shared-util": "2.0.0-
|
|
15
|
+
"@gnuechtel/shared-coverage": "2.0.0-beta.2",
|
|
16
|
+
"@gnuechtel/shared-util": "2.0.0-beta.2"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"@cucumber/cucumber": ">=9 <13",
|
|
@@ -33,9 +33,6 @@
|
|
|
33
33
|
"type": "commonjs",
|
|
34
34
|
"main": "./src/index.js",
|
|
35
35
|
"generators": "./generators.json",
|
|
36
|
-
"nx-migrations": {
|
|
37
|
-
"migrations": "./migrations.json"
|
|
38
|
-
},
|
|
39
36
|
"executors": "./executors.json",
|
|
40
37
|
"typings": "./src/index.d.ts",
|
|
41
38
|
"types": "./src/index.d.ts"
|
package/src/core/web-server.d.ts
CHANGED
|
@@ -8,22 +8,19 @@ export interface WebServerConfig {
|
|
|
8
8
|
/** Environment variables for the server process. Defaults to the current process environment. */
|
|
9
9
|
env?: NodeJS.ProcessEnv;
|
|
10
10
|
/**
|
|
11
|
-
* stdio mode for the server process.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* synchronous context. waitForUrl uses Atomics.wait which blocks the entire Node.js event
|
|
15
|
-
* loop - stdout data handlers cannot fire, so the pipe buffer fills up. On Windows the
|
|
16
|
-
* pipe buffer is only 4 KB: Vite fills it during startup output, blocks on write, and
|
|
17
|
-
* never starts the HTTP server, causing an indefinite hang.
|
|
18
|
-
*
|
|
19
|
-
* Use 'pipe' only when the event loop is free to process I/O during the wait (e.g. when
|
|
20
|
-
* called from an async BeforeAll hook without Atomics.wait).
|
|
11
|
+
* stdio mode for the server process.
|
|
12
|
+
* Use 'pipe' (default) to forward server output prefixed with '[serve]'.
|
|
13
|
+
* Use 'ignore' when starting the server inside a spawnSync context to avoid pipe-buffer deadlocks.
|
|
21
14
|
*/
|
|
22
15
|
stdio?: 'pipe' | 'ignore';
|
|
23
16
|
}
|
|
24
17
|
/**
|
|
25
18
|
* Starts a web server before Cucumber runs and stops it when the process exits.
|
|
26
19
|
* Mirrors Playwright's webServer config pattern.
|
|
20
|
+
*
|
|
21
|
+
* Note: when running inside a parent `spawnSync` context (e.g., nyc coverage wrapper),
|
|
22
|
+
* set stdio to 'ignore' to avoid pipe-buffer deadlocks, or start the server externally
|
|
23
|
+
* before invoking cucumber and rely on `reuseExistingServer`.
|
|
27
24
|
*/
|
|
28
25
|
export declare function startWebServer(config: WebServerConfig): void;
|
|
29
26
|
export declare function stopWebServer(): void;
|
package/src/core/web-server.js
CHANGED
|
@@ -5,18 +5,20 @@ exports.stopWebServer = stopWebServer;
|
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
6
|
const shared_util_1 = require("@gnuechtel/shared-util");
|
|
7
7
|
let serverProcess;
|
|
8
|
-
let serverPort;
|
|
9
8
|
/**
|
|
10
9
|
* Starts a web server before Cucumber runs and stops it when the process exits.
|
|
11
10
|
* Mirrors Playwright's webServer config pattern.
|
|
11
|
+
*
|
|
12
|
+
* Note: when running inside a parent `spawnSync` context (e.g., nyc coverage wrapper),
|
|
13
|
+
* set stdio to 'ignore' to avoid pipe-buffer deadlocks, or start the server externally
|
|
14
|
+
* before invoking cucumber and rely on `reuseExistingServer`.
|
|
12
15
|
*/
|
|
13
16
|
function startWebServer(config) {
|
|
14
|
-
const { command, url, reuseExistingServer = true, timeout = 60000, cwd, env, stdio = '
|
|
17
|
+
const { command, url, reuseExistingServer = true, timeout = 60000, cwd, env, stdio = 'pipe' } = config;
|
|
15
18
|
if (reuseExistingServer && isUrlReachable(url)) {
|
|
16
19
|
console.log(`Reusing existing server at ${url}`);
|
|
17
20
|
return;
|
|
18
21
|
}
|
|
19
|
-
serverPort = extractPort(url);
|
|
20
22
|
console.log(`Starting web server: ${command}`);
|
|
21
23
|
serverProcess = (0, child_process_1.spawn)(command, {
|
|
22
24
|
shell: true,
|
|
@@ -34,13 +36,16 @@ function startWebServer(config) {
|
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
serverProcess.unref();
|
|
37
|
-
process.on('exit',
|
|
39
|
+
process.on('exit', stopWebServer);
|
|
38
40
|
process.on('SIGINT', stopWebServer);
|
|
39
41
|
process.on('SIGTERM', stopWebServer);
|
|
40
42
|
console.log(`Waiting for ${url}...`);
|
|
41
43
|
waitForUrl(url, timeout);
|
|
42
44
|
console.log(`Server ready at ${url}`);
|
|
43
45
|
if (stdio === 'pipe') {
|
|
46
|
+
// Unref the stdio streams so they don't prevent the parent process from exiting
|
|
47
|
+
// once the tests complete. The streams are still active and will forward output,
|
|
48
|
+
// but the event loop won't be kept alive waiting for them.
|
|
44
49
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
50
|
serverProcess.stdout?.unref?.();
|
|
46
51
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -51,31 +56,9 @@ function stopWebServer() {
|
|
|
51
56
|
if (!serverProcess || serverProcess.killed)
|
|
52
57
|
return;
|
|
53
58
|
const pid = serverProcess.pid;
|
|
54
|
-
const port = serverPort;
|
|
55
59
|
serverProcess = undefined;
|
|
56
|
-
serverPort = undefined;
|
|
57
60
|
if (pid)
|
|
58
61
|
(0, shared_util_1.killProcessTree)(pid);
|
|
59
|
-
if (process.platform === 'win32' && port) {
|
|
60
|
-
killProcessOnPort(port);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
function stopWebServerOnProcessExit() {
|
|
64
|
-
if (!serverProcess || serverProcess.killed)
|
|
65
|
-
return;
|
|
66
|
-
const pid = serverProcess.pid;
|
|
67
|
-
serverProcess = undefined;
|
|
68
|
-
serverPort = undefined;
|
|
69
|
-
if (!pid)
|
|
70
|
-
return;
|
|
71
|
-
try {
|
|
72
|
-
// Avoid synchronous process-tree cleanup on process exit to prevent rare
|
|
73
|
-
// Windows deadlocks while the Node.js process is shutting down.
|
|
74
|
-
process.kill(pid, 'SIGTERM');
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
// ignore - process may have already exited
|
|
78
|
-
}
|
|
79
62
|
}
|
|
80
63
|
function waitForUrl(url, timeout) {
|
|
81
64
|
const interval = 1000;
|
|
@@ -94,46 +77,15 @@ function sleepSync(ms) {
|
|
|
94
77
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
95
78
|
}
|
|
96
79
|
function isUrlReachable(url) {
|
|
97
|
-
if (process.platform === 'win32') {
|
|
98
|
-
return isUrlReachableOnWindows(url);
|
|
99
|
-
}
|
|
100
|
-
// Let the child process exit itself after 2s instead of relying on spawnSync timeout.
|
|
101
|
-
// On Windows this path is avoided because GitLab Windows runners showed rare hangs with
|
|
102
|
-
// node+fetch probes. The PowerShell probe below has a parent timeout as a hard guard.
|
|
103
|
-
const result = (0, child_process_1.spawnSync)('node', [
|
|
104
|
-
'-e',
|
|
105
|
-
`setTimeout(()=>process.exit(1),2000);fetch('${url}').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))`,
|
|
106
|
-
], { stdio: 'ignore' });
|
|
107
|
-
return result.status === 0;
|
|
108
|
-
}
|
|
109
|
-
function isUrlReachableOnWindows(url) {
|
|
110
|
-
const escapedUrl = url.replace(/'/g, "''");
|
|
111
|
-
const result = (0, child_process_1.spawnSync)('powershell', [
|
|
112
|
-
'-NoProfile',
|
|
113
|
-
'-NonInteractive',
|
|
114
|
-
'-Command',
|
|
115
|
-
`$ProgressPreference='SilentlyContinue'; try { $r = Invoke-WebRequest -UseBasicParsing -Uri '${escapedUrl}' -TimeoutSec 2; if ($r.StatusCode -ge 200 -and $r.StatusCode -lt 400) { exit 0 } else { exit 1 } } catch { exit 1 }`,
|
|
116
|
-
], { stdio: 'ignore', timeout: 10000 });
|
|
117
|
-
return result.status === 0;
|
|
118
|
-
}
|
|
119
|
-
function extractPort(url) {
|
|
120
80
|
try {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return
|
|
81
|
+
(0, child_process_1.execSync)(`node -e "fetch('${url}').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"`, {
|
|
82
|
+
stdio: 'ignore',
|
|
83
|
+
timeout: 3000,
|
|
84
|
+
});
|
|
85
|
+
return true;
|
|
126
86
|
}
|
|
127
87
|
catch {
|
|
128
|
-
return
|
|
88
|
+
return false;
|
|
129
89
|
}
|
|
130
90
|
}
|
|
131
|
-
function killProcessOnPort(port) {
|
|
132
|
-
(0, child_process_1.spawnSync)('powershell', [
|
|
133
|
-
'-NoProfile',
|
|
134
|
-
'-NonInteractive',
|
|
135
|
-
'-Command',
|
|
136
|
-
`$conns = Get-NetTCPConnection -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue; foreach ($c in $conns) { taskkill /F /T /PID $c.OwningProcess 2>$null }`,
|
|
137
|
-
], { stdio: 'ignore', timeout: 10000 });
|
|
138
|
-
}
|
|
139
91
|
//# sourceMappingURL=web-server.js.map
|
|
@@ -1 +1 @@
|
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,EAAE,CACpC,CAAC;AACJ,CAAC","sourcesContent":["import { spawnSync, spawn } from 'child_process';\nimport { killProcessTree } from '@gnuechtel/shared-util';\n\nexport interface WebServerConfig {\n command: string;\n url: string;\n reuseExistingServer?: boolean;\n timeout?: number;\n /** Working directory for the server process. Defaults to the current working directory. */\n cwd?: string;\n /** Environment variables for the server process. Defaults to the current process environment. */\n env?: NodeJS.ProcessEnv;\n /**\n * stdio mode for the server process. Defaults to 'ignore'.\n *\n * Keep the default 'ignore' when calling startWebServer at module load time or from any\n * synchronous context. waitForUrl uses Atomics.wait which blocks the entire Node.js event\n * loop - stdout data handlers cannot fire, so the pipe buffer fills up. On Windows the\n * pipe buffer is only 4 KB: Vite fills it during startup output, blocks on write, and\n * never starts the HTTP server, causing an indefinite hang.\n *\n * Use 'pipe' only when the event loop is free to process I/O during the wait (e.g. when\n * called from an async BeforeAll hook without Atomics.wait).\n */\n stdio?: 'pipe' | 'ignore';\n}\n\nlet serverProcess: ReturnType<typeof spawn> | undefined;\nlet serverPort: number | undefined;\n\n/**\n * Starts a web server before Cucumber runs and stops it when the process exits.\n * Mirrors Playwright's webServer config pattern.\n */\nexport function startWebServer(config: WebServerConfig): void {\n const { command, url, reuseExistingServer = true, timeout = 60000, cwd, env, stdio = 'ignore' } = config;\n\n if (reuseExistingServer && isUrlReachable(url)) {\n console.log(`Reusing existing server at ${url}`);\n return;\n }\n\n serverPort = extractPort(url);\n\n console.log(`Starting web server: ${command}`);\n serverProcess = spawn(command, {\n shell: true,\n stdio,\n detached: true,\n ...(cwd ? { cwd } : {}),\n ...(env ? { env } : {}),\n });\n\n if (stdio === 'pipe') {\n serverProcess.stdout?.on('data', (data: Buffer) => {\n process.stdout.write(`[serve] ${data}`);\n });\n serverProcess.stderr?.on('data', (data: Buffer) => {\n process.stderr.write(`[serve] ${data}`);\n });\n }\n\n serverProcess.unref();\n\n process.on('exit', stopWebServerOnProcessExit);\n process.on('SIGINT', stopWebServer);\n process.on('SIGTERM', stopWebServer);\n\n console.log(`Waiting for ${url}...`);\n waitForUrl(url, timeout);\n console.log(`Server ready at ${url}`);\n\n if (stdio === 'pipe') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (serverProcess.stdout as any)?.unref?.();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (serverProcess.stderr as any)?.unref?.();\n }\n}\n\nexport function stopWebServer(): void {\n if (!serverProcess || serverProcess.killed) return;\n const pid = serverProcess.pid;\n const port = serverPort;\n serverProcess = undefined;\n serverPort = undefined;\n if (pid) killProcessTree(pid);\n if (process.platform === 'win32' && port) {\n killProcessOnPort(port);\n }\n}\n\nfunction stopWebServerOnProcessExit(): void {\n if (!serverProcess || serverProcess.killed) return;\n const pid = serverProcess.pid;\n serverProcess = undefined;\n serverPort = undefined;\n if (!pid) return;\n try {\n // Avoid synchronous process-tree cleanup on process exit to prevent rare\n // Windows deadlocks while the Node.js process is shutting down.\n process.kill(pid, 'SIGTERM');\n } catch {\n // ignore - process may have already exited\n }\n}\n\nfunction waitForUrl(url: string, timeout: number): void {\n const interval = 1000;\n const deadline = Date.now() + timeout;\n while (Date.now() < deadline) {\n if (isUrlReachable(url)) return;\n if (serverProcess?.exitCode !== null && serverProcess?.exitCode !== undefined) {\n throw new Error(`Web server exited with code ${serverProcess.exitCode} before becoming ready`);\n }\n sleepSync(interval);\n }\n throw new Error(`Timed out after ${timeout}ms waiting for ${url}`);\n}\n\nfunction sleepSync(ms: number): void {\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);\n}\n\nfunction isUrlReachable(url: string): boolean {\n if (process.platform === 'win32') {\n return isUrlReachableOnWindows(url);\n }\n\n // Let the child process exit itself after 2s instead of relying on spawnSync timeout.\n // On Windows this path is avoided because GitLab Windows runners showed rare hangs with\n // node+fetch probes. The PowerShell probe below has a parent timeout as a hard guard.\n const result = spawnSync(\n 'node',\n [\n '-e',\n `setTimeout(()=>process.exit(1),2000);fetch('${url}').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))`,\n ],\n { stdio: 'ignore' }\n );\n return result.status === 0;\n}\n\nfunction isUrlReachableOnWindows(url: string): boolean {\n const escapedUrl = url.replace(/'/g, \"''\");\n const result = spawnSync(\n 'powershell',\n [\n '-NoProfile',\n '-NonInteractive',\n '-Command',\n `$ProgressPreference='SilentlyContinue'; try { $r = Invoke-WebRequest -UseBasicParsing -Uri '${escapedUrl}' -TimeoutSec 2; if ($r.StatusCode -ge 200 -and $r.StatusCode -lt 400) { exit 0 } else { exit 1 } } catch { exit 1 }`,\n ],\n { stdio: 'ignore', timeout: 10000 }\n );\n return result.status === 0;\n}\n\nfunction extractPort(url: string): number | undefined {\n try {\n const parsed = new URL(url);\n const port = parseInt(parsed.port, 10);\n if (port > 0) return port;\n return parsed.protocol === 'https:' ? 443 : 80;\n } catch {\n return undefined;\n }\n}\n\nfunction killProcessOnPort(port: number): void {\n spawnSync(\n 'powershell',\n [\n '-NoProfile',\n '-NonInteractive',\n '-Command',\n `$conns = Get-NetTCPConnection -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue; foreach ($c in $conns) { taskkill /F /T /PID $c.OwningProcess 2>$null }`,\n ],\n { stdio: 'ignore', timeout: 10000 }\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web-server.js","sourceRoot":"","sources":["../../../../../libs/nx-cucumber/src/core/web-server.ts"],"names":[],"mappings":";;AA8BA,wCA6CC;AAED,sCAKC;AAlFD,iDAAgD;AAChD,wDAAyD;AAmBzD,IAAI,aAAmD,CAAC;AAExD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,MAAuB;IACpD,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,mBAAmB,GAAG,IAAI,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;IAEvG,IAAI,mBAAmB,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO,CA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,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,CAAC;QACH,IAAA,wBAAQ,EAAC,mBAAmB,GAAG,wEAAwE,EAAE;YACvG,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import { execSync, spawn } from 'child_process';\nimport { killProcessTree } from '@gnuechtel/shared-util';\n\nexport interface WebServerConfig {\n command: string;\n url: string;\n reuseExistingServer?: boolean;\n timeout?: number;\n /** Working directory for the server process. Defaults to the current working directory. */\n cwd?: string;\n /** Environment variables for the server process. Defaults to the current process environment. */\n env?: NodeJS.ProcessEnv;\n /**\n * stdio mode for the server process.\n * Use 'pipe' (default) to forward server output prefixed with '[serve]'.\n * Use 'ignore' when starting the server inside a spawnSync context to avoid pipe-buffer deadlocks.\n */\n stdio?: 'pipe' | 'ignore';\n}\n\nlet serverProcess: ReturnType<typeof spawn> | undefined;\n\n/**\n * Starts a web server before Cucumber runs and stops it when the process exits.\n * Mirrors Playwright's webServer config pattern.\n *\n * Note: when running inside a parent `spawnSync` context (e.g., nyc coverage wrapper),\n * set stdio to 'ignore' to avoid pipe-buffer deadlocks, or start the server externally\n * before invoking cucumber and rely on `reuseExistingServer`.\n */\nexport function startWebServer(config: WebServerConfig): void {\n const { command, url, reuseExistingServer = true, timeout = 60000, cwd, env, stdio = 'pipe' } = config;\n\n if (reuseExistingServer && isUrlReachable(url)) {\n console.log(`Reusing existing server at ${url}`);\n return;\n }\n\n console.log(`Starting web server: ${command}`);\n serverProcess = spawn(command, {\n shell: true,\n stdio,\n detached: true,\n ...(cwd ? { cwd } : {}),\n ...(env ? { env } : {}),\n });\n\n if (stdio === 'pipe') {\n serverProcess.stdout?.on('data', (data: Buffer) => {\n process.stdout.write(`[serve] ${data}`);\n });\n serverProcess.stderr?.on('data', (data: Buffer) => {\n process.stderr.write(`[serve] ${data}`);\n });\n }\n\n serverProcess.unref();\n\n process.on('exit', stopWebServer);\n process.on('SIGINT', stopWebServer);\n process.on('SIGTERM', stopWebServer);\n\n console.log(`Waiting for ${url}...`);\n waitForUrl(url, timeout);\n console.log(`Server ready at ${url}`);\n\n if (stdio === 'pipe') {\n // Unref the stdio streams so they don't prevent the parent process from exiting\n // once the tests complete. The streams are still active and will forward output,\n // but the event loop won't be kept alive waiting for them.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (serverProcess.stdout as any)?.unref?.();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (serverProcess.stderr as any)?.unref?.();\n }\n}\n\nexport function stopWebServer(): void {\n if (!serverProcess || serverProcess.killed) return;\n const pid = serverProcess.pid;\n serverProcess = undefined;\n if (pid) killProcessTree(pid);\n}\n\nfunction waitForUrl(url: string, timeout: number): void {\n const interval = 1000;\n const deadline = Date.now() + timeout;\n while (Date.now() < deadline) {\n if (isUrlReachable(url)) return;\n if (serverProcess?.exitCode !== null && serverProcess?.exitCode !== undefined) {\n throw new Error(`Web server exited with code ${serverProcess.exitCode} before becoming ready`);\n }\n sleepSync(interval);\n }\n throw new Error(`Timed out after ${timeout}ms waiting for ${url}`);\n}\n\nfunction sleepSync(ms: number): void {\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);\n}\n\nfunction isUrlReachable(url: string): boolean {\n try {\n execSync(`node -e \"fetch('${url}').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))\"`, {\n stdio: 'ignore',\n timeout: 3000,\n });\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
process.env.TS_NODE_PROJECT = '<%= projectRoot %>/tsconfig.json';
|
|
2
2
|
const outputDir = 'dist/e2e/<%= projectRoot %>';
|
|
3
|
+
<% if (isPlaywright) { %>
|
|
4
|
+
const { startWebServer } = require('@gnuechtel/nx-cucumber');
|
|
5
|
+
startWebServer({
|
|
6
|
+
command: 'npx nx run <%= serveTarget %>',
|
|
7
|
+
url: '<%= baseUrl %>',
|
|
8
|
+
});
|
|
9
|
+
<% } %>
|
|
3
10
|
module.exports = {
|
|
4
11
|
default: {
|
|
5
12
|
paths: ['<%= projectRoot %>/features/**/*.feature'],
|
|
@@ -13,18 +13,12 @@ async function cucumberJsGenerator(tree, options) {
|
|
|
13
13
|
options.directory = options.name;
|
|
14
14
|
if (!options.testRunner)
|
|
15
15
|
options.testRunner = test_run_options_1.defaultTestRunner;
|
|
16
|
-
const isPlaywright = options.testRunner === 'playwright';
|
|
17
|
-
const baseUrl = isPlaywright ? 'http://localhost:4200' : undefined;
|
|
18
|
-
const serveTarget = isPlaywright ? `${options.project}:serve` : undefined;
|
|
19
16
|
const normalizedDirectory = (0, devkit_1.normalizePath)(options.directory);
|
|
20
17
|
const workspaceLayout = (0, devkit_1.getWorkspaceLayout)(tree);
|
|
21
18
|
const skipAppsDir = workspaceLayout.appsDir === '.' || options.ignoreWorkspaceLayout;
|
|
22
19
|
const parentDir = workspaceLayout.appsDir && !skipAppsDir ? workspaceLayout.appsDir + '/' : '';
|
|
23
20
|
const projectRoot = `${parentDir}${normalizedDirectory}`;
|
|
24
21
|
const workspaceRootRelative = (0, devkit_1.offsetFromRoot)(projectRoot).replace(/\/$/, '');
|
|
25
|
-
const playwrightTargets = isPlaywright && baseUrl && serveTarget
|
|
26
|
-
? buildPlaywrightTargets(tree, options.project, options.name, serveTarget, baseUrl, projectRoot)
|
|
27
|
-
: {};
|
|
28
22
|
(0, devkit_1.addProjectConfiguration)(tree, options.name, {
|
|
29
23
|
root: projectRoot,
|
|
30
24
|
sourceRoot: `${projectRoot}/src`,
|
|
@@ -37,7 +31,6 @@ async function cucumberJsGenerator(tree, options) {
|
|
|
37
31
|
lintFilePatterns: [`${projectRoot}/**/*.ts`],
|
|
38
32
|
},
|
|
39
33
|
},
|
|
40
|
-
...playwrightTargets,
|
|
41
34
|
},
|
|
42
35
|
implicitDependencies: [options.project],
|
|
43
36
|
});
|
|
@@ -47,14 +40,17 @@ async function cucumberJsGenerator(tree, options) {
|
|
|
47
40
|
'node_modules/@gnuechtel/nx-cucumber/src/playwright/playwright-hooks.js',
|
|
48
41
|
]
|
|
49
42
|
: [];
|
|
43
|
+
const isPlaywright = options.testRunner === 'playwright';
|
|
44
|
+
const baseUrl = isPlaywright ? 'http://localhost:4200' : '';
|
|
45
|
+
const serveTarget = isPlaywright ? `${options.project}:serve` : '';
|
|
50
46
|
const substitutions = {
|
|
51
47
|
...options,
|
|
52
48
|
workspaceRootRelative,
|
|
53
49
|
projectRoot,
|
|
54
50
|
playwrightRequires: JSON.stringify(playwrightRequires),
|
|
55
51
|
isPlaywright,
|
|
56
|
-
baseUrl
|
|
57
|
-
serveTarget
|
|
52
|
+
baseUrl,
|
|
53
|
+
serveTarget,
|
|
58
54
|
};
|
|
59
55
|
(0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files', 'all'), projectRoot, substitutions);
|
|
60
56
|
(0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files', options.testRunner), projectRoot, substitutions);
|
|
@@ -67,54 +63,8 @@ async function cucumberJsGenerator(tree, options) {
|
|
|
67
63
|
'ts-node': '10.9.1',
|
|
68
64
|
'tsconfig-paths': '4.2.0',
|
|
69
65
|
};
|
|
70
|
-
if (isPlaywright) {
|
|
71
|
-
additionalDevDependencies['kill-port'] = '2.0.1';
|
|
72
|
-
additionalDevDependencies['start-server-and-test'] = '3.0.0';
|
|
73
|
-
}
|
|
74
66
|
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, additionalDevDependencies);
|
|
75
67
|
return options.skipInstall ? () => undefined : installTask;
|
|
76
68
|
}
|
|
77
|
-
function buildPlaywrightTargets(tree, projectName, e2eProjectName, serveTarget, baseUrl, projectRoot) {
|
|
78
|
-
const prepareCommand = buildPlaywrightPrepareCommand();
|
|
79
|
-
const e2eCommand = buildPlaywrightE2eCommand(tree, projectName, serveTarget, baseUrl, projectRoot);
|
|
80
|
-
const e2eCiCommand = `npx nx run ${e2eProjectName}:e2e-prepare && npx nx run ${e2eProjectName}:e2e`;
|
|
81
|
-
return {
|
|
82
|
-
'e2e-prepare': {
|
|
83
|
-
command: prepareCommand,
|
|
84
|
-
},
|
|
85
|
-
e2e: {
|
|
86
|
-
command: e2eCommand,
|
|
87
|
-
},
|
|
88
|
-
'e2e-ci': {
|
|
89
|
-
command: e2eCiCommand,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function buildPlaywrightPrepareCommand() {
|
|
94
|
-
return `node -e "const { execSync } = require('node:child_process'); const installCommand = process.platform === 'linux' ? 'npx playwright install --with-deps chromium' : 'npx playwright install chromium'; execSync(installCommand, { stdio: 'inherit' });"`;
|
|
95
|
-
}
|
|
96
|
-
function buildPlaywrightE2eCommand(tree, projectName, serveTarget, baseUrl, projectRoot) {
|
|
97
|
-
const port = readPortFromUrl(baseUrl);
|
|
98
|
-
const serveExecutor = readServeExecutor(tree, projectName);
|
|
99
|
-
const serveCommand = serveExecutor === '@nx/vite:dev-server'
|
|
100
|
-
? `npx nx run ${serveTarget} --port=${port} --strictPort`
|
|
101
|
-
: `npx nx run ${serveTarget}`;
|
|
102
|
-
const testCommand = `npx cucumber-js --config ${projectRoot}/cucumber.js`;
|
|
103
|
-
return `npx kill-port ${port} && start-server-and-test "${serveCommand}" ${baseUrl} "${testCommand}"`;
|
|
104
|
-
}
|
|
105
|
-
function readServeExecutor(tree, projectName) {
|
|
106
|
-
try {
|
|
107
|
-
return (0, devkit_1.readProjectConfiguration)(tree, projectName).targets?.['serve']?.executor;
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function readPortFromUrl(url) {
|
|
114
|
-
const parsedUrl = new URL(url);
|
|
115
|
-
if (parsedUrl.port)
|
|
116
|
-
return parsedUrl.port;
|
|
117
|
-
return parsedUrl.protocol === 'https:' ? '443' : '80';
|
|
118
|
-
}
|
|
119
69
|
exports.default = cucumberJsGenerator;
|
|
120
70
|
//# sourceMappingURL=project.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../../../../libs/nx-cucumber/src/generators/project/project.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../../../../../../libs/nx-cucumber/src/generators/project/project.ts"],"names":[],"mappings":";;AAeA,kDAmEC;;AAlFD,uCASoB;AACpB,mDAA6B;AAE7B,2BAAgC;AAChC,kEAAgE;AAEzD,KAAK,UAAU,mBAAmB,CAAC,IAAU,EAAE,OAAkC;IACtF,IAAI,CAAC,OAAO,CAAC,IAAI;QAAE,OAAO,CAAC,IAAI,GAAG,GAAG,OAAO,CAAC,OAAO,MAAM,CAAC;IAC3D,IAAI,CAAC,OAAO,CAAC,SAAS;QAAE,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IACzD,IAAI,CAAC,OAAO,CAAC,UAAU;QAAE,OAAO,CAAC,UAAU,GAAG,oCAAiB,CAAC;IAEhE,MAAM,mBAAmB,GAAG,IAAA,sBAAa,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC7D,MAAM,eAAe,GAAG,IAAA,2BAAkB,EAAC,IAAI,CAAC,CAAC;IACjD,MAAM,WAAW,GAAG,eAAe,CAAC,OAAO,KAAK,GAAG,IAAI,OAAO,CAAC,qBAAqB,CAAC;IACrF,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/F,MAAM,WAAW,GAAG,GAAG,SAAS,GAAG,mBAAmB,EAAE,CAAC;IACzD,MAAM,qBAAqB,GAAG,IAAA,uBAAc,EAAC,WAAW,CAAC,CAAC,OAAO,CAAC,KAA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C,UAAU,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;IAEnG,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,UAAU,eAAe,CAAC,CAAC;IAC7F,IAAI,OAAO,CAAC,WAAW,IAAI,IAAA,eAAU,EAAC,gBAAgB,CAAC,EAAE,CAAC;QACxD,IAAA,sBAAa,EAAC,IAAI,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAExB,MAAM,yBAAyB,GAA2B;QACxD,SAAS,EAAE,QAAQ;QACnB,gBAAgB,EAAE,OAAO;KAC1B,CAAC;IAEF,MAAM,WAAW,GAAG,IAAA,qCAA4B,EAAC,IAAI,EAAE,EAAE,EAAE,yBAAyB,CAAC,CAAC;IACtF,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;AAC7D,CAAC;AAED,kBAAe,mBAAmB,CAAC","sourcesContent":["import {\n addProjectConfiguration,\n formatFiles,\n generateFiles,\n Tree,\n addDependenciesToPackageJson,\n normalizePath,\n offsetFromRoot,\n getWorkspaceLayout,\n} from '@nx/devkit';\nimport * as path from 'path';\nimport { CucumberJsGeneratorSchema } from './schema';\nimport { existsSync } from 'fs';\nimport { defaultTestRunner } from '../../core/test-run-options';\n\nexport async function cucumberJsGenerator(tree: Tree, options: CucumberJsGeneratorSchema) {\n if (!options.name) options.name = `${options.project}-e2e`;\n if (!options.directory) options.directory = options.name;\n if (!options.testRunner) options.testRunner = defaultTestRunner;\n\n const normalizedDirectory = normalizePath(options.directory);\n const workspaceLayout = getWorkspaceLayout(tree);\n const skipAppsDir = workspaceLayout.appsDir === '.' || options.ignoreWorkspaceLayout;\n const parentDir = workspaceLayout.appsDir && !skipAppsDir ? workspaceLayout.appsDir + '/' : '';\n const projectRoot = `${parentDir}${normalizedDirectory}`;\n const workspaceRootRelative = offsetFromRoot(projectRoot).replace(/\\/$/, '');\n\n addProjectConfiguration(tree, options.name, {\n root: projectRoot,\n sourceRoot: `${projectRoot}/src`,\n projectType: 'application',\n targets: {\n lint: {\n executor: '@nx/eslint:lint',\n outputs: ['{options.outputFile}'],\n options: {\n lintFilePatterns: [`${projectRoot}/**/*.ts`],\n },\n },\n },\n implicitDependencies: [options.project],\n });\n\n const playwrightRequires =\n options.testRunner === 'playwright'\n ? [\n 'node_modules/@gnuechtel/nx-cucumber/src/playwright/playwright-world-default.js',\n 'node_modules/@gnuechtel/nx-cucumber/src/playwright/playwright-hooks.js',\n ]\n : [];\n\n const isPlaywright = options.testRunner === 'playwright';\n const baseUrl = isPlaywright ? 'http://localhost:4200' : '';\n const serveTarget = isPlaywright ? `${options.project}:serve` : '';\n\n const substitutions = {\n ...options,\n workspaceRootRelative,\n projectRoot,\n playwrightRequires: JSON.stringify(playwrightRequires),\n isPlaywright,\n baseUrl,\n serveTarget,\n };\n\n generateFiles(tree, path.join(__dirname, 'files', 'all'), projectRoot, substitutions);\n generateFiles(tree, path.join(__dirname, 'files', options.testRunner), projectRoot, substitutions);\n\n const customWorldFiles = path.join(__dirname, 'files', `${options.testRunner}.custom-world`);\n if (options.customWorld && existsSync(customWorldFiles)) {\n generateFiles(tree, customWorldFiles, projectRoot, substitutions);\n }\n\n await formatFiles(tree);\n\n const additionalDevDependencies: Record<string, string> = {\n 'ts-node': '10.9.1',\n 'tsconfig-paths': '4.2.0',\n };\n\n const installTask = addDependenciesToPackageJson(tree, {}, additionalDevDependencies);\n return options.skipInstall ? () => undefined : installTask;\n}\n\nexport default cucumberJsGenerator;\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -9,4 +9,3 @@ export * from './adapters/validation';
|
|
|
9
9
|
export * from './adapters/registry';
|
|
10
10
|
export { createNodesV2 } from './plugin/create-nodes';
|
|
11
11
|
export type { NxCucumberPluginOptions } from './plugin/create-nodes';
|
|
12
|
-
export { migrateCucumberApiToInferredTasks } from './migrations/update-2-0-0/migrate-cucumber-api-to-inferred-tasks';
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createNodesV2 = exports.stopWebServer = exports.startWebServer = exports.createBeautifulHtmlReport = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./playwright/playwright-world"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./core/test-run-options"), exports);
|
|
@@ -14,6 +14,4 @@ tslib_1.__exportStar(require("./adapters/validation"), exports);
|
|
|
14
14
|
tslib_1.__exportStar(require("./adapters/registry"), exports);
|
|
15
15
|
var create_nodes_1 = require("./plugin/create-nodes");
|
|
16
16
|
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return create_nodes_1.createNodesV2; } });
|
|
17
|
-
var migrate_cucumber_api_to_inferred_tasks_1 = require("./migrations/update-2-0-0/migrate-cucumber-api-to-inferred-tasks");
|
|
18
|
-
Object.defineProperty(exports, "migrateCucumberApiToInferredTasks", { enumerable: true, get: function () { return migrate_cucumber_api_to_inferred_tasks_1.migrateCucumberApiToInferredTasks; } });
|
|
19
17
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nx-cucumber/src/index.ts"],"names":[],"mappings":";;;;AAAA,wEAA8C;AAC9C,kEAAwC;AACxC,oEAAwE;AAA/D,iIAAA,yBAAyB,OAAA;AAClC,gDAAkE;AAAzD,4GAAA,cAAc,OAAA;AAAE,2GAAA,aAAa,OAAA;AAGtC,8DAAoC;AACpC,gEAAsC;AACtC,8DAAoC;AACpC,sDAAsD;AAA7C,6GAAA,aAAa,OAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nx-cucumber/src/index.ts"],"names":[],"mappings":";;;;AAAA,wEAA8C;AAC9C,kEAAwC;AACxC,oEAAwE;AAA/D,iIAAA,yBAAyB,OAAA;AAClC,gDAAkE;AAAzD,4GAAA,cAAc,OAAA;AAAE,2GAAA,aAAa,OAAA;AAGtC,8DAAoC;AACpC,gEAAsC;AACtC,8DAAoC;AACpC,sDAAsD;AAA7C,6GAAA,aAAa,OAAA","sourcesContent":["export * from './playwright/playwright-world';\nexport * from './core/test-run-options';\nexport { createBeautifulHtmlReport } from './core/cucumber-report-html';\nexport { startWebServer, stopWebServer } from './core/web-server';\nexport type { WebServerConfig } from './core/web-server';\nexport type { BeautifulReportOptions } from './core/cucumber-report-html';\nexport * from './adapters/contract';\nexport * from './adapters/validation';\nexport * from './adapters/registry';\nexport { createNodesV2 } from './plugin/create-nodes';\nexport type { NxCucumberPluginOptions } from './plugin/create-nodes';\n"]}
|
|
@@ -16,71 +16,36 @@ const debug = require('debug')('e2e:hooks');
|
|
|
16
16
|
if (!global.nxCucumber) {
|
|
17
17
|
global.nxCucumber = { disableCoverage: false };
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
const browserLaunchHookTimeout = Math.max(defaultCucumberTimeout, 60_000);
|
|
21
|
-
// Use an explicit timeout so hooks are not bound to Cucumber's 5s default on slower Windows runners.
|
|
19
|
+
// Disable timeout on playwright debugging (let cucumber.js config handle the default otherwise)
|
|
22
20
|
if (process.env['PWDEBUG']) {
|
|
23
21
|
(0, cucumber_1.setDefaultTimeout)(-1);
|
|
24
22
|
}
|
|
25
|
-
else {
|
|
26
|
-
(0, cucumber_1.setDefaultTimeout)(defaultCucumberTimeout);
|
|
27
|
-
}
|
|
28
23
|
// We ignore all SSL errors, because we have self signed developer certificates
|
|
29
24
|
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
|
|
30
25
|
function configuredBrowser() {
|
|
31
26
|
return (0, playwright_browser_1.resolvePlaywrightBrowser)(global.nxCucumber.browser);
|
|
32
27
|
}
|
|
33
|
-
let browserLaunchPromise;
|
|
34
28
|
async function launchBrowser(label, headless) {
|
|
35
|
-
if (global.browserState.isStarted)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (global.browserState.isStarted) {
|
|
43
|
-
// A concurrent launch already produced a running browser (e.g. after a hook timeout).
|
|
44
|
-
// Close this duplicate instance so it cannot keep the process alive.
|
|
45
|
-
debug(`${label} - Closing duplicate ${browser} instance`);
|
|
46
|
-
try {
|
|
47
|
-
await launchedBrowser.close();
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
debug(`${label} - Could not close duplicate browser: %O`, e);
|
|
51
|
-
}
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
global.browser = launchedBrowser;
|
|
55
|
-
global.browserState.isHeadless = headless;
|
|
56
|
-
global.browserState.isStarted = true;
|
|
57
|
-
debug(`${label} - ${browser} instance created`);
|
|
58
|
-
})().finally(() => {
|
|
59
|
-
browserLaunchPromise = undefined;
|
|
60
|
-
});
|
|
29
|
+
if (!global.browserState.isStarted) {
|
|
30
|
+
const browser = configuredBrowser();
|
|
31
|
+
debug(`${label} - Creating new ${headless ? 'headless' : 'headed'} ${browser} instance`);
|
|
32
|
+
global.browser = await (0, playwright_browser_2.resolvePlaywrightBrowserType)(browser).launch((0, playwright_browser_2.createPlaywrightLaunchOptions)(browser, headless));
|
|
33
|
+
global.browserState.isHeadless = headless;
|
|
34
|
+
global.browserState.isStarted = true;
|
|
35
|
+
debug(`${label} - ${browser} instance created`);
|
|
61
36
|
}
|
|
62
|
-
else {
|
|
63
|
-
debug(`${label} - Waiting for ongoing browser launch`);
|
|
64
|
-
}
|
|
65
|
-
await browserLaunchPromise;
|
|
66
37
|
}
|
|
67
38
|
async function closeBrowser(label) {
|
|
68
|
-
if (browserLaunchPromise) {
|
|
69
|
-
debug(`${label} - Waiting for ongoing browser launch before close`);
|
|
70
|
-
await browserLaunchPromise;
|
|
71
|
-
}
|
|
72
39
|
if (global.browserState.isStarted) {
|
|
73
40
|
debug(`${label} - Closing ${configuredBrowser()} instance`);
|
|
74
41
|
try {
|
|
75
42
|
await global.browser.close();
|
|
43
|
+
global.browserState.isStarted = false;
|
|
76
44
|
debug(`${label} - ${configuredBrowser()} instance closed`);
|
|
77
45
|
}
|
|
78
46
|
catch (e) {
|
|
79
47
|
debug(`${label} - Could not close browser: %O`, e);
|
|
80
48
|
}
|
|
81
|
-
finally {
|
|
82
|
-
global.browserState.isStarted = false;
|
|
83
|
-
}
|
|
84
49
|
}
|
|
85
50
|
}
|
|
86
51
|
/**
|
|
@@ -104,7 +69,6 @@ async function launchBrowserIfRequired(label, launchHeadless) {
|
|
|
104
69
|
}
|
|
105
70
|
}
|
|
106
71
|
(0, cucumber_1.BeforeAll)(async function () {
|
|
107
|
-
browserLaunchPromise = undefined;
|
|
108
72
|
global.browserState = {
|
|
109
73
|
isStarted: false,
|
|
110
74
|
isHeadless: true,
|
|
@@ -152,10 +116,10 @@ async function launchBrowserIfRequired(label, launchHeadless) {
|
|
|
152
116
|
// When javascript is enabled by default, we disable it only for scenarios which are tagged by @noscript
|
|
153
117
|
this.parameters.disableJavaScript = true;
|
|
154
118
|
});
|
|
155
|
-
(0, cucumber_1.Before)({ name: 'ensure headed browser', tags: '@headed'
|
|
119
|
+
(0, cucumber_1.Before)({ name: 'ensure headed browser', tags: '@headed' }, async function () {
|
|
156
120
|
await launchBrowserIfRequired('Before @headed', false);
|
|
157
121
|
});
|
|
158
|
-
(0, cucumber_1.Before)({ name: 'ensure headless browser', tags: 'not @headed'
|
|
122
|
+
(0, cucumber_1.Before)({ name: 'ensure headless browser', tags: 'not @headed' }, async function () {
|
|
159
123
|
await launchBrowserIfRequired('Before not @headed', !this.parameters.headed);
|
|
160
124
|
});
|
|
161
125
|
(0, cucumber_1.BeforeStep)(async function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright-hooks.js","sourceRoot":"","sources":["../../../../../libs/nx-cucumber/src/playwright/playwright-hooks.ts"],"names":[],"mappings":";;;AAAA,iDAAkH;AAElH,+CAAyB;AACzB,mDAA6B;AAC7B,gEAA2E;AAC3E,yDAAmE;AACnE,gEAAmF;AACnF,wDAAuD;AACvD,mEAAsE;AACtE,6DAAmG;AAEnG,8DAA8D;AAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;AAE5C,2FAA2F;AAC3F,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IACvB,MAAM,CAAC,UAAU,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC;AAED,MAAM,sBAAsB,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,IAAI,MAAM,CAAC;AACnE,MAAM,wBAAwB,GAAG,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;AAE1E,qGAAqG;AACrG,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;IAC3B,IAAA,4BAAiB,EAAC,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;KAAM,CAAC;IACN,IAAA,4BAAiB,EAAC,sBAAsB,CAAC,CAAC;AAC5C,CAAC;AAED,+EAA+E;AAC/E,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,GAAG,GAAG,CAAC;AAElD,SAAS,iBAAiB;IACxB,OAAO,IAAA,6CAAwB,EAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC7D,CAAC;AAED,IAAI,oBAA+C,CAAC;AAEpD,KAAK,UAAU,aAAa,CAAC,KAAa,EAAE,QAAiB;IAC3D,IAAI,MAAM,CAAC,YAAY,CAAC,SAAS;QAAE,OAAO;IAE1C,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,oBA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Step, Before, BeforeAll, BeforeStep, setDefaultTimeout } from '@cucumber/cucumber';\nimport { ITestCaseHookParameter } from '@cucumber/cucumber';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { createIstanbulCoverageReports } from '@gnuechtel/shared-coverage';\nimport { PlaywrightWorld, scenarioName } from './playwright-world';\nimport { deleteExistingPlaywrightCoverageFiles } from '@gnuechtel/shared-coverage';\nimport { rootDirectory } from '@gnuechtel/shared-util';\nimport { resolvePlaywrightBrowser } from '../core/playwright-browser';\nimport { createPlaywrightLaunchOptions, resolvePlaywrightBrowserType } from './playwright-browser';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst debug = require('debug')('e2e:hooks');\n\n// Initialize global configuration with defaults if not set (2.x: no executor injects this)\nif (!global.nxCucumber) {\n global.nxCucumber = { disableCoverage: false };\n}\n\nconst defaultCucumberTimeout = global.nxCucumber.timeout || 30_000;\nconst browserLaunchHookTimeout = Math.max(defaultCucumberTimeout, 60_000);\n\n// Use an explicit timeout so hooks are not bound to Cucumber's 5s default on slower Windows runners.\nif (process.env['PWDEBUG']) {\n setDefaultTimeout(-1);\n} else {\n setDefaultTimeout(defaultCucumberTimeout);\n}\n\n// We ignore all SSL errors, because we have self signed developer certificates\nprocess.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';\n\nfunction configuredBrowser() {\n return resolvePlaywrightBrowser(global.nxCucumber.browser);\n}\n\nlet browserLaunchPromise: Promise<void> | undefined;\n\nasync function launchBrowser(label: string, headless: boolean) {\n if (global.browserState.isStarted) return;\n\n if (!browserLaunchPromise) {\n browserLaunchPromise = (async () => {\n const browser = configuredBrowser();\n debug(`${label} - Creating new ${headless ? 'headless' : 'headed'} ${browser} instance`);\n const launchedBrowser = await resolvePlaywrightBrowserType(browser).launch(\n createPlaywrightLaunchOptions(browser, headless)\n );\n\n if (global.browserState.isStarted) {\n // A concurrent launch already produced a running browser (e.g. after a hook timeout).\n // Close this duplicate instance so it cannot keep the process alive.\n debug(`${label} - Closing duplicate ${browser} instance`);\n try {\n await launchedBrowser.close();\n } catch (e) {\n debug(`${label} - Could not close duplicate browser: %O`, e);\n }\n return;\n }\n\n global.browser = launchedBrowser;\n global.browserState.isHeadless = headless;\n global.browserState.isStarted = true;\n debug(`${label} - ${browser} instance created`);\n })().finally(() => {\n browserLaunchPromise = undefined;\n });\n } else {\n debug(`${label} - Waiting for ongoing browser launch`);\n }\n\n await browserLaunchPromise;\n}\n\nasync function closeBrowser(label: string) {\n if (browserLaunchPromise) {\n debug(`${label} - Waiting for ongoing browser launch before close`);\n await browserLaunchPromise;\n }\n\n if (global.browserState.isStarted) {\n debug(`${label} - Closing ${configuredBrowser()} instance`);\n try {\n await global.browser.close();\n debug(`${label} - ${configuredBrowser()} instance closed`);\n } catch (e) {\n debug(`${label} - Could not close browser: %O`, e);\n } finally {\n global.browserState.isStarted = false;\n }\n }\n}\n\n/**\n * Launches the browser if it is not yet started or if the running headless state is different from `launchHeadless`.\n * Closes any existing browser before. This function has no effect, if a browser is currently running and has the same\n * headless state like `launchHeadless`.\n *\n * In other words, a new browser is launched\n * - headed, if running browser is headless\n * - headless, if running browser is headed\n * - headless/headed, if browser is not yet started.\n *\n * @param label the label for debugging\n * @param launchHeadless true, if browser should be launched headless, false otherwise\n */\nasync function launchBrowserIfRequired(label: string, launchHeadless: boolean) {\n if (global.browserState.isHeadless != launchHeadless || !global.browserState.isStarted) {\n // The closeBrowser invocation has only an effect, if browser is already running\n await closeBrowser(label);\n await launchBrowser(label, launchHeadless);\n }\n}\n\nBeforeAll(async function () {\n browserLaunchPromise = undefined;\n global.browserState = {\n isStarted: false,\n isHeadless: true,\n };\n if (!global.nxCucumber.disableCoverage) {\n debug('BeforeAll - Deleting existing coverage files');\n deleteExistingPlaywrightCoverageFiles();\n debug('BeforeAll - Existing coverage files deleted');\n }\n});\n\nAfterAll(async function () {\n if (!global.nxCucumber.disableCoverage) {\n const nycOutputDir = path.join(rootDirectory(), '.nyc_output');\n const hasCoverageFiles =\n fs.existsSync(nycOutputDir) &&\n fs.readdirSync(nycOutputDir).some((f) => f.startsWith('playwright_coverage_') && f.endsWith('.json'));\n if (hasCoverageFiles) {\n debug('AfterAll - Creating Istanbul coverage report');\n try {\n const projectDirectory = path.resolve(global.nxCucumber.cwd || process.cwd());\n await createIstanbulCoverageReports(rootDirectory(), projectDirectory);\n debug('AfterAll - Istanbul coverage report created');\n } catch (e) {\n debug('AfterAll - Could not create Istanbul coverage report: %O', e);\n }\n } else {\n debug('AfterAll - No coverage files found, skipping Istanbul coverage report');\n }\n }\n await closeBrowser('AfterAll');\n});\n\nBefore({ name: 'prepare' }, async function (this: PlaywrightWorld, testCase: ITestCaseHookParameter) {\n debug('Before - Cleaning up');\n // Always clean-up any running stuff\n await this.cleanUp();\n this.setItem(scenarioName, testCase.pickle.name); // save scenario name for screenshots or video files\n debug('Before - Cleaned up');\n});\n\nBefore({ name: 'enable javascript', tags: '@javascript' }, async function (this: PlaywrightWorld) {\n // When javascript is disabled by default, we enable it only for scenarios which are tagged by @javascript\n this.parameters.disableJavaScript = false;\n});\n\nBefore({ name: 'disable javascript', tags: '@noscript' }, async function (this: PlaywrightWorld) {\n // When javascript is enabled by default, we disable it only for scenarios which are tagged by @noscript\n this.parameters.disableJavaScript = true;\n});\n\nBefore({ name: 'ensure headed browser', tags: '@headed', timeout: browserLaunchHookTimeout }, async function () {\n await launchBrowserIfRequired('Before @headed', false);\n});\n\nBefore(\n { name: 'ensure headless browser', tags: 'not @headed', timeout: browserLaunchHookTimeout },\n async function (this: PlaywrightWorld) {\n await launchBrowserIfRequired('Before not @headed', !this.parameters.headed);\n }\n);\n\nBeforeStep(async function (this: PlaywrightWorld) {\n debug('BeforeStep');\n this.prepareStep();\n});\n\nAfterStep(async function (this: PlaywrightWorld, { result }) {\n if (!this.parameters.disableScreenshotAttachments || !this.parameters.disableScreenshotFiles) {\n try {\n debug('AfterStep - Creating screenshots');\n await this.createScreenshots(result);\n debug('AfterStep - Screenshots created');\n } catch (e) {\n debug('AfterStep - Could not create screenshots: %O', e);\n }\n }\n});\n\nAfter({ name: 'clean up' }, async function (this: PlaywrightWorld) {\n if (!this.parameters.disableCoverage) {\n // Wait for any pending network activity (e.g. lazy-loaded components) to settle before collecting coverage.\n try {\n for (const page of this.pages) {\n await page.waitForLoadState('networkidle', { timeout: 5000 });\n }\n } catch (_) {\n // best-effort — ignore timeouts\n }\n try {\n debug('After - Collecting coverage');\n await this.collectIstanbulCoverage();\n debug('After - Coverage collected');\n } catch (e) {\n debug('After - Could not create coverage: %O', e);\n }\n }\n try {\n debug('After - Cleaning up');\n await this.cleanUp();\n debug('After - Cleaned up');\n } catch (e) {\n debug('After - Could not clean up properly: %O', e);\n }\n});\n"]}
|
|
1
|
+
{"version":3,"file":"playwright-hooks.js","sourceRoot":"","sources":["../../../../../libs/nx-cucumber/src/playwright/playwright-hooks.ts"],"names":[],"mappings":";;;AAAA,iDAAkH;AAElH,+CAAyB;AACzB,mDAA6B;AAC7B,gEAA2E;AAC3E,yDAAmE;AACnE,gEAAmF;AACnF,wDAAuD;AACvD,mEAAsE;AACtE,6DAAmG;AAEnG,8DAA8D;AAC9D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;AAE5C,2FAA2F;AAC3F,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IACvB,MAAM,CAAC,UAAU,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC;AAED,gGAAgG;AAChG,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;IAC3B,IAAA,4BAAiB,EAAC,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,+EAA+E;AAC/E,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,GAAG,GAAG,CAAC;AAElD,SAAS,iBAAiB;IACxB,OAAO,IAAA,6CAAwB,EAAC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC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ACrC,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;YACrC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,KAAK,CAAC,uCAAuC,EAAE,CAAC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IACD,IAAI,CAAC;QACH,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAC7B,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,KAAK,CAAC,yCAAyC,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { After, AfterAll, AfterStep, Before, BeforeAll, BeforeStep, setDefaultTimeout } from '@cucumber/cucumber';\nimport { ITestCaseHookParameter } from '@cucumber/cucumber';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { createIstanbulCoverageReports } from '@gnuechtel/shared-coverage';\nimport { PlaywrightWorld, scenarioName } from './playwright-world';\nimport { deleteExistingPlaywrightCoverageFiles } from '@gnuechtel/shared-coverage';\nimport { rootDirectory } from '@gnuechtel/shared-util';\nimport { resolvePlaywrightBrowser } from '../core/playwright-browser';\nimport { createPlaywrightLaunchOptions, resolvePlaywrightBrowserType } from './playwright-browser';\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst debug = require('debug')('e2e:hooks');\n\n// Initialize global configuration with defaults if not set (2.x: no executor injects this)\nif (!global.nxCucumber) {\n global.nxCucumber = { disableCoverage: false };\n}\n\n// Disable timeout on playwright debugging (let cucumber.js config handle the default otherwise)\nif (process.env['PWDEBUG']) {\n setDefaultTimeout(-1);\n}\n\n// We ignore all SSL errors, because we have self signed developer certificates\nprocess.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';\n\nfunction configuredBrowser() {\n return resolvePlaywrightBrowser(global.nxCucumber.browser);\n}\n\nasync function launchBrowser(label: string, headless: boolean) {\n if (!global.browserState.isStarted) {\n const browser = configuredBrowser();\n debug(`${label} - Creating new ${headless ? 'headless' : 'headed'} ${browser} instance`);\n global.browser = await resolvePlaywrightBrowserType(browser).launch(\n createPlaywrightLaunchOptions(browser, headless)\n );\n global.browserState.isHeadless = headless;\n global.browserState.isStarted = true;\n debug(`${label} - ${browser} instance created`);\n }\n}\n\nasync function closeBrowser(label: string) {\n if (global.browserState.isStarted) {\n debug(`${label} - Closing ${configuredBrowser()} instance`);\n try {\n await global.browser.close();\n global.browserState.isStarted = false;\n debug(`${label} - ${configuredBrowser()} instance closed`);\n } catch (e) {\n debug(`${label} - Could not close browser: %O`, e);\n }\n }\n}\n\n/**\n * Launches the browser if it is not yet started or if the running headless state is different from `launchHeadless`.\n * Closes any existing browser before. This function has no effect, if a browser is currently running and has the same\n * headless state like `launchHeadless`.\n *\n * In other words, a new browser is launched\n * - headed, if running browser is headless\n * - headless, if running browser is headed\n * - headless/headed, if browser is not yet started.\n *\n * @param label the label for debugging\n * @param launchHeadless true, if browser should be launched headless, false otherwise\n */\nasync function launchBrowserIfRequired(label: string, launchHeadless: boolean) {\n if (global.browserState.isHeadless != launchHeadless || !global.browserState.isStarted) {\n // The closeBrowser invocation has only an effect, if browser is already running\n await closeBrowser(label);\n await launchBrowser(label, launchHeadless);\n }\n}\n\nBeforeAll(async function () {\n global.browserState = {\n isStarted: false,\n isHeadless: true,\n };\n if (!global.nxCucumber.disableCoverage) {\n debug('BeforeAll - Deleting existing coverage files');\n deleteExistingPlaywrightCoverageFiles();\n debug('BeforeAll - Existing coverage files deleted');\n }\n});\n\nAfterAll(async function () {\n if (!global.nxCucumber.disableCoverage) {\n const nycOutputDir = path.join(rootDirectory(), '.nyc_output');\n const hasCoverageFiles =\n fs.existsSync(nycOutputDir) &&\n fs.readdirSync(nycOutputDir).some((f) => f.startsWith('playwright_coverage_') && f.endsWith('.json'));\n if (hasCoverageFiles) {\n debug('AfterAll - Creating Istanbul coverage report');\n try {\n const projectDirectory = path.resolve(global.nxCucumber.cwd || process.cwd());\n await createIstanbulCoverageReports(rootDirectory(), projectDirectory);\n debug('AfterAll - Istanbul coverage report created');\n } catch (e) {\n debug('AfterAll - Could not create Istanbul coverage report: %O', e);\n }\n } else {\n debug('AfterAll - No coverage files found, skipping Istanbul coverage report');\n }\n }\n await closeBrowser('AfterAll');\n});\n\nBefore({ name: 'prepare' }, async function (this: PlaywrightWorld, testCase: ITestCaseHookParameter) {\n debug('Before - Cleaning up');\n // Always clean-up any running stuff\n await this.cleanUp();\n this.setItem(scenarioName, testCase.pickle.name); // save scenario name for screenshots or video files\n debug('Before - Cleaned up');\n});\n\nBefore({ name: 'enable javascript', tags: '@javascript' }, async function (this: PlaywrightWorld) {\n // When javascript is disabled by default, we enable it only for scenarios which are tagged by @javascript\n this.parameters.disableJavaScript = false;\n});\n\nBefore({ name: 'disable javascript', tags: '@noscript' }, async function (this: PlaywrightWorld) {\n // When javascript is enabled by default, we disable it only for scenarios which are tagged by @noscript\n this.parameters.disableJavaScript = true;\n});\n\nBefore({ name: 'ensure headed browser', tags: '@headed' }, async function () {\n await launchBrowserIfRequired('Before @headed', false);\n});\n\nBefore({ name: 'ensure headless browser', tags: 'not @headed' }, async function (this: PlaywrightWorld) {\n await launchBrowserIfRequired('Before not @headed', !this.parameters.headed);\n});\n\nBeforeStep(async function (this: PlaywrightWorld) {\n debug('BeforeStep');\n this.prepareStep();\n});\n\nAfterStep(async function (this: PlaywrightWorld, { result }) {\n if (!this.parameters.disableScreenshotAttachments || !this.parameters.disableScreenshotFiles) {\n try {\n debug('AfterStep - Creating screenshots');\n await this.createScreenshots(result);\n debug('AfterStep - Screenshots created');\n } catch (e) {\n debug('AfterStep - Could not create screenshots: %O', e);\n }\n }\n});\n\nAfter({ name: 'clean up' }, async function (this: PlaywrightWorld) {\n if (!this.parameters.disableCoverage) {\n // Wait for any pending network activity (e.g. lazy-loaded components) to settle before collecting coverage.\n try {\n for (const page of this.pages) {\n await page.waitForLoadState('networkidle', { timeout: 5000 });\n }\n } catch (_) {\n // best-effort — ignore timeouts\n }\n try {\n debug('After - Collecting coverage');\n await this.collectIstanbulCoverage();\n debug('After - Coverage collected');\n } catch (e) {\n debug('After - Could not create coverage: %O', e);\n }\n }\n try {\n debug('After - Cleaning up');\n await this.cleanUp();\n debug('After - Cleaned up');\n } catch (e) {\n debug('After - Could not clean up properly: %O', e);\n }\n});\n"]}
|
package/migrations.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"generators": {
|
|
3
|
-
"migrate-cucumber-api-to-inferred-tasks": {
|
|
4
|
-
"version": "2.0.0-beta.4",
|
|
5
|
-
"description": "Migrate legacy cucumber-api executor projects to adapter-based inferred tasks",
|
|
6
|
-
"implementation": "./src/migrations/update-2-0-0/migrate-cucumber-api-to-inferred-tasks",
|
|
7
|
-
"cli": "nx"
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
|
2
|
-
interface MigratedProjectReport {
|
|
3
|
-
project: string;
|
|
4
|
-
projectRoot: string;
|
|
5
|
-
removedTargets: string[];
|
|
6
|
-
createdCucumberConfig: boolean;
|
|
7
|
-
manualFollowUps: string[];
|
|
8
|
-
}
|
|
9
|
-
interface MigrationReport {
|
|
10
|
-
dryRun: boolean;
|
|
11
|
-
pluginAdded: boolean;
|
|
12
|
-
removedLegacyTargetDefaults: boolean;
|
|
13
|
-
migratedProjects: MigratedProjectReport[];
|
|
14
|
-
}
|
|
15
|
-
interface MigrationOptions {
|
|
16
|
-
dryRun?: boolean;
|
|
17
|
-
}
|
|
18
|
-
export declare function migrateCucumberApiToInferredTasks(tree: Tree, options?: MigrationOptions): Promise<MigrationReport>;
|
|
19
|
-
export default function migrateCucumberApiToInferredTasksEntry(tree: Tree): Promise<void>;
|
|
20
|
-
export {};
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateCucumberApiToInferredTasks = migrateCucumberApiToInferredTasks;
|
|
4
|
-
exports.default = migrateCucumberApiToInferredTasksEntry;
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const LEGACY_EXECUTOR = '@gnuechtel/nx-cucumber:cucumber-api';
|
|
7
|
-
const REPORT_PATH = 'tmp/nx-cucumber-migration-report.json';
|
|
8
|
-
const PLUGIN_NAME = '@gnuechtel/nx-cucumber';
|
|
9
|
-
function isDryRunRequested() {
|
|
10
|
-
const arg = process.argv.some((v) => v === '--dry-run' || v === '--dryRun');
|
|
11
|
-
const env = `${process.env['NX_CUCUMBER_MIGRATION_DRY_RUN'] || ''}`.toLowerCase();
|
|
12
|
-
return arg || env === '1' || env === 'true' || env === 'yes';
|
|
13
|
-
}
|
|
14
|
-
function normalizePath(p) {
|
|
15
|
-
return p.replace(/\\/g, '/');
|
|
16
|
-
}
|
|
17
|
-
function resolveTsNodeProject(projectRoot, tsConfig) {
|
|
18
|
-
if (!tsConfig)
|
|
19
|
-
return `${projectRoot}/tsconfig.json`;
|
|
20
|
-
if (tsConfig.includes('/'))
|
|
21
|
-
return normalizePath(tsConfig);
|
|
22
|
-
return `${projectRoot}/${tsConfig}`;
|
|
23
|
-
}
|
|
24
|
-
function hasNxCucumberPlugin(nxJson) {
|
|
25
|
-
if (!nxJson)
|
|
26
|
-
return false;
|
|
27
|
-
return (nxJson.plugins?.some((plugin) => typeof plugin === 'string' ? plugin === PLUGIN_NAME : plugin?.plugin === PLUGIN_NAME) ?? false);
|
|
28
|
-
}
|
|
29
|
-
function getLegacyTargetNames(project) {
|
|
30
|
-
return Object.entries(project.targets ?? {})
|
|
31
|
-
.filter(([, target]) => target.executor === LEGACY_EXECUTOR)
|
|
32
|
-
.map(([targetName]) => targetName);
|
|
33
|
-
}
|
|
34
|
-
function pickLegacyOptions(project) {
|
|
35
|
-
const targets = project.targets ?? {};
|
|
36
|
-
const legacyTarget = targets['e2e-cucumber']?.executor === LEGACY_EXECUTOR
|
|
37
|
-
? targets['e2e-cucumber']
|
|
38
|
-
: Object.values(targets).find((target) => target.executor === LEGACY_EXECUTOR);
|
|
39
|
-
return (legacyTarget?.options ?? {});
|
|
40
|
-
}
|
|
41
|
-
function extractWorldParameters(options) {
|
|
42
|
-
const worldParameters = {};
|
|
43
|
-
const allowedKeys = [
|
|
44
|
-
'baseUrl',
|
|
45
|
-
'browser',
|
|
46
|
-
'headed',
|
|
47
|
-
'debug',
|
|
48
|
-
'disableAnimations',
|
|
49
|
-
'disableCoverage',
|
|
50
|
-
'disableScreenshotAttachments',
|
|
51
|
-
'disableScreenshotFiles',
|
|
52
|
-
'enableSuccessfulScreenshotFiles',
|
|
53
|
-
'disableVideoAttachments',
|
|
54
|
-
'disableVideoFiles',
|
|
55
|
-
'disableJavaScript',
|
|
56
|
-
'additionalPlaywrightConfiguration',
|
|
57
|
-
'viewport',
|
|
58
|
-
'videoSize',
|
|
59
|
-
];
|
|
60
|
-
for (const key of allowedKeys) {
|
|
61
|
-
if (options[key] !== undefined) {
|
|
62
|
-
worldParameters[key] = options[key];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return worldParameters;
|
|
66
|
-
}
|
|
67
|
-
function createCucumberConfigContent(projectRoot, options) {
|
|
68
|
-
const outputDir = `dist/e2e/${projectRoot}`;
|
|
69
|
-
const featuresDirectory = normalizePath(options.featuresDirectory || `${projectRoot}/features`);
|
|
70
|
-
const testRunner = options.testRunner === 'playwright' ? 'playwright' : 'core';
|
|
71
|
-
const tsNodeProject = resolveTsNodeProject(projectRoot, typeof options.tsConfig === 'string' ? options.tsConfig : undefined);
|
|
72
|
-
const requireEntries = [`'${projectRoot}/src/**/*.ts'`];
|
|
73
|
-
if (testRunner === 'playwright') {
|
|
74
|
-
requireEntries.push(`'node_modules/@gnuechtel/nx-cucumber/src/playwright/playwright-world-default.js'`);
|
|
75
|
-
requireEntries.push(`'node_modules/@gnuechtel/nx-cucumber/src/playwright/playwright-hooks.js'`);
|
|
76
|
-
}
|
|
77
|
-
const worldParameters = {
|
|
78
|
-
outputDirectory: outputDir,
|
|
79
|
-
...extractWorldParameters(options),
|
|
80
|
-
};
|
|
81
|
-
const lines = [
|
|
82
|
-
`process.env.TS_NODE_PROJECT = '${tsNodeProject}';`,
|
|
83
|
-
'module.exports = {',
|
|
84
|
-
' default: {',
|
|
85
|
-
` paths: ['${featuresDirectory}/**/*.feature'],`,
|
|
86
|
-
` requireModule: ['ts-node/register', 'tsconfig-paths/register'],`,
|
|
87
|
-
` require: [${requireEntries.join(', ')}],`,
|
|
88
|
-
` tags: '${typeof options.tags === 'string' ? options.tags : 'not @ignore'}',`,
|
|
89
|
-
' format: [',
|
|
90
|
-
` 'summary',`,
|
|
91
|
-
` 'progress-bar',`,
|
|
92
|
-
` 'json:dist/e2e/${projectRoot}/reports/cucumber-json/cucumber-test-report.json',`,
|
|
93
|
-
` 'html:dist/e2e/${projectRoot}/reports/html/cucumber-test-report-builtin.html',`,
|
|
94
|
-
` 'junit:dist/e2e/${projectRoot}/reports/test-results/cucumber-test-report.xml',`,
|
|
95
|
-
' ],',
|
|
96
|
-
` worldParameters: ${JSON.stringify(worldParameters, null, 4).replace(/\n/g, '\n ')},`,
|
|
97
|
-
...(typeof options.cucumberTimeout === 'number' ? [` timeout: ${options.cucumberTimeout},`] : []),
|
|
98
|
-
' publishQuiet: true,',
|
|
99
|
-
' },',
|
|
100
|
-
'};',
|
|
101
|
-
'',
|
|
102
|
-
];
|
|
103
|
-
return lines.join('\n');
|
|
104
|
-
}
|
|
105
|
-
function shouldFlagWatchTarget(targets) {
|
|
106
|
-
const watchCommand = targets?.['e2e-watch']?.options?.['commands'];
|
|
107
|
-
if (!Array.isArray(watchCommand))
|
|
108
|
-
return false;
|
|
109
|
-
return watchCommand.some((cmd) => typeof cmd === 'string' && cmd.includes('watch-message'));
|
|
110
|
-
}
|
|
111
|
-
function shouldRemoveLegacyE2eRunCommand(targets) {
|
|
112
|
-
const e2e = targets?.['e2e'];
|
|
113
|
-
if (!e2e || e2e.executor !== 'nx:run-commands')
|
|
114
|
-
return false;
|
|
115
|
-
const command = e2e.options?.['command'];
|
|
116
|
-
return typeof command === 'string' && command.includes('e2e-cucumber');
|
|
117
|
-
}
|
|
118
|
-
async function migrateCucumberApiToInferredTasks(tree, options = {}) {
|
|
119
|
-
const dryRun = options.dryRun ?? isDryRunRequested();
|
|
120
|
-
const nxJson = ((0, devkit_1.readNxJson)(tree) ?? {});
|
|
121
|
-
const report = {
|
|
122
|
-
dryRun,
|
|
123
|
-
pluginAdded: false,
|
|
124
|
-
removedLegacyTargetDefaults: false,
|
|
125
|
-
migratedProjects: [],
|
|
126
|
-
};
|
|
127
|
-
const hadPlugin = hasNxCucumberPlugin(nxJson);
|
|
128
|
-
if (!hadPlugin) {
|
|
129
|
-
report.pluginAdded = true;
|
|
130
|
-
if (!dryRun) {
|
|
131
|
-
nxJson.plugins ??= [];
|
|
132
|
-
nxJson.plugins.push(PLUGIN_NAME);
|
|
133
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (nxJson.targetDefaults?.[LEGACY_EXECUTOR]) {
|
|
137
|
-
report.removedLegacyTargetDefaults = true;
|
|
138
|
-
if (!dryRun) {
|
|
139
|
-
delete nxJson.targetDefaults[LEGACY_EXECUTOR];
|
|
140
|
-
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
for (const [projectName, projectConfig] of (0, devkit_1.getProjects)(tree).entries()) {
|
|
144
|
-
const legacyTargets = getLegacyTargetNames(projectConfig);
|
|
145
|
-
const removeLegacyRunCommandTarget = shouldRemoveLegacyE2eRunCommand(projectConfig.targets);
|
|
146
|
-
if (legacyTargets.length === 0 && !removeLegacyRunCommandTarget)
|
|
147
|
-
continue;
|
|
148
|
-
const manualFollowUps = [];
|
|
149
|
-
const removedTargets = [...legacyTargets];
|
|
150
|
-
if (removeLegacyRunCommandTarget && !removedTargets.includes('e2e')) {
|
|
151
|
-
removedTargets.push('e2e');
|
|
152
|
-
}
|
|
153
|
-
const cucumberConfigPath = `${projectConfig.root}/cucumber.js`;
|
|
154
|
-
const hasCucumberConfig = tree.exists(cucumberConfigPath);
|
|
155
|
-
const legacyOptions = pickLegacyOptions(projectConfig);
|
|
156
|
-
if (shouldFlagWatchTarget(projectConfig.targets)) {
|
|
157
|
-
manualFollowUps.push('Target "e2e-watch" still uses legacy watch-message flow. Review whether it should be replaced by framework-native watch mode.');
|
|
158
|
-
}
|
|
159
|
-
if (hasCucumberConfig) {
|
|
160
|
-
manualFollowUps.push(`Existing ${cucumberConfigPath} was kept. Verify tags/paths/worldParameters still reflect prior executor options.`);
|
|
161
|
-
}
|
|
162
|
-
const updatedProject = {
|
|
163
|
-
...projectConfig,
|
|
164
|
-
targets: {
|
|
165
|
-
...(projectConfig.targets ?? {}),
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
for (const targetName of removedTargets) {
|
|
169
|
-
delete updatedProject.targets?.[targetName];
|
|
170
|
-
}
|
|
171
|
-
if (!dryRun) {
|
|
172
|
-
(0, devkit_1.updateProjectConfiguration)(tree, projectName, updatedProject);
|
|
173
|
-
if (!hasCucumberConfig) {
|
|
174
|
-
tree.write(cucumberConfigPath, createCucumberConfigContent(projectConfig.root, legacyOptions));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
report.migratedProjects.push({
|
|
178
|
-
project: projectName,
|
|
179
|
-
projectRoot: projectConfig.root,
|
|
180
|
-
removedTargets,
|
|
181
|
-
createdCucumberConfig: !hasCucumberConfig,
|
|
182
|
-
manualFollowUps,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
if (!dryRun) {
|
|
186
|
-
tree.write(REPORT_PATH, JSON.stringify(report, null, 2));
|
|
187
|
-
}
|
|
188
|
-
devkit_1.logger.info(`[nx-cucumber migration] migrated projects: ${report.migratedProjects.length}, pluginAdded: ${report.pluginAdded}, dryRun: ${report.dryRun}`);
|
|
189
|
-
if (report.migratedProjects.length > 0) {
|
|
190
|
-
for (const project of report.migratedProjects) {
|
|
191
|
-
devkit_1.logger.info(`[nx-cucumber migration] ${project.project}: removed targets [${project.removedTargets.join(', ')}], created cucumber.js: ${project.createdCucumberConfig}`);
|
|
192
|
-
for (const followUp of project.manualFollowUps) {
|
|
193
|
-
devkit_1.logger.warn(`[nx-cucumber migration] ${project.project}: ${followUp}`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (!dryRun) {
|
|
198
|
-
devkit_1.logger.info(`[nx-cucumber migration] report written to ${REPORT_PATH}`);
|
|
199
|
-
}
|
|
200
|
-
return report;
|
|
201
|
-
}
|
|
202
|
-
async function migrateCucumberApiToInferredTasksEntry(tree) {
|
|
203
|
-
await migrateCucumberApiToInferredTasks(tree);
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=migrate-cucumber-api-to-inferred-tasks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-cucumber-api-to-inferred-tasks.js","sourceRoot":"","sources":["../../../../../../libs/nx-cucumber/src/migrations/update-2-0-0/migrate-cucumber-api-to-inferred-tasks.ts"],"names":[],"mappings":";;AAwLA,8EA6GC;AAED,yDAEC;AAzSD,uCASoB;AAEpB,MAAM,eAAe,GAAG,qCAAqC,CAAC;AAC9D,MAAM,WAAW,GAAG,uCAAuC,CAAC;AAC5D,MAAM,WAAW,GAAG,wBAAwB,CAAC;AA6C7C,SAAS,iBAAiB;IACxB,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,WAAW,IAAI,CAAC,KAAK,UAAU,CAAC,CAAC;IAC5E,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,GAAG,CA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AW,aAAa,MAAM,CAAC,MAAM,EAAE,CAC7I,CAAC;IACF,IAAI,MAAM,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvC,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC9C,eAAM,CAAC,IAAI,CACT,2BAA2B,OAAO,CAAC,OAAO,sBAAsB,OAAO,CAAC,cAAc,CAAC,IAAI,CACzF,IAAI,CACL,2BAA2B,OAAO,CAAC,qBAAqB,EAAE,CAC5D,CAAC;YACF,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;gBAC/C,eAAM,CAAC,IAAI,CAAC,2BAA2B,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,eAAM,CAAC,IAAI,CAAC,6CAA6C,WAAW,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAEc,KAAK,UAAU,sCAAsC,CAAC,IAAU;IAC7E,MAAM,iCAAiC,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import {\n logger,\n NxJsonConfiguration,\n ProjectConfiguration,\n readNxJson,\n Tree,\n updateNxJson,\n updateProjectConfiguration,\n getProjects,\n} from '@nx/devkit';\n\nconst LEGACY_EXECUTOR = '@gnuechtel/nx-cucumber:cucumber-api';\nconst REPORT_PATH = 'tmp/nx-cucumber-migration-report.json';\nconst PLUGIN_NAME = '@gnuechtel/nx-cucumber';\n\ninterface LegacyOptions {\n testRunner?: 'core' | 'playwright';\n featuresDirectory?: string;\n tags?: string;\n cucumberTimeout?: number;\n tsConfig?: string;\n baseUrl?: string;\n browser?: string;\n headed?: boolean;\n debug?: boolean;\n disableAnimations?: boolean;\n disableCoverage?: boolean;\n disableScreenshotAttachments?: boolean;\n disableScreenshotFiles?: boolean;\n enableSuccessfulScreenshotFiles?: boolean;\n disableVideoAttachments?: boolean;\n disableVideoFiles?: boolean;\n disableJavaScript?: boolean;\n additionalPlaywrightConfiguration?: Record<string, unknown>;\n viewport?: Record<string, unknown>;\n videoSize?: Record<string, unknown>;\n [key: string]: unknown;\n}\n\ninterface MigratedProjectReport {\n project: string;\n projectRoot: string;\n removedTargets: string[];\n createdCucumberConfig: boolean;\n manualFollowUps: string[];\n}\n\ninterface MigrationReport {\n dryRun: boolean;\n pluginAdded: boolean;\n removedLegacyTargetDefaults: boolean;\n migratedProjects: MigratedProjectReport[];\n}\n\ninterface MigrationOptions {\n dryRun?: boolean;\n}\n\nfunction isDryRunRequested(): boolean {\n const arg = process.argv.some((v) => v === '--dry-run' || v === '--dryRun');\n const env = `${process.env['NX_CUCUMBER_MIGRATION_DRY_RUN'] || ''}`.toLowerCase();\n return arg || env === '1' || env === 'true' || env === 'yes';\n}\n\nfunction normalizePath(p: string): string {\n return p.replace(/\\\\/g, '/');\n}\n\nfunction resolveTsNodeProject(projectRoot: string, tsConfig?: string): string {\n if (!tsConfig) return `${projectRoot}/tsconfig.json`;\n if (tsConfig.includes('/')) return normalizePath(tsConfig);\n return `${projectRoot}/${tsConfig}`;\n}\n\nfunction hasNxCucumberPlugin(nxJson: NxJsonConfiguration | null): boolean {\n if (!nxJson) return false;\n return (\n nxJson.plugins?.some((plugin) =>\n typeof plugin === 'string' ? plugin === PLUGIN_NAME : plugin?.plugin === PLUGIN_NAME\n ) ?? false\n );\n}\n\nfunction getLegacyTargetNames(project: ProjectConfiguration): string[] {\n return Object.entries(project.targets ?? {})\n .filter(([, target]) => target.executor === LEGACY_EXECUTOR)\n .map(([targetName]) => targetName);\n}\n\nfunction pickLegacyOptions(project: ProjectConfiguration): LegacyOptions {\n const targets = project.targets ?? {};\n const legacyTarget =\n targets['e2e-cucumber']?.executor === LEGACY_EXECUTOR\n ? targets['e2e-cucumber']\n : Object.values(targets).find((target) => target.executor === LEGACY_EXECUTOR);\n return (legacyTarget?.options ?? {}) as LegacyOptions;\n}\n\nfunction extractWorldParameters(options: LegacyOptions): Record<string, unknown> {\n const worldParameters: Record<string, unknown> = {};\n const allowedKeys = [\n 'baseUrl',\n 'browser',\n 'headed',\n 'debug',\n 'disableAnimations',\n 'disableCoverage',\n 'disableScreenshotAttachments',\n 'disableScreenshotFiles',\n 'enableSuccessfulScreenshotFiles',\n 'disableVideoAttachments',\n 'disableVideoFiles',\n 'disableJavaScript',\n 'additionalPlaywrightConfiguration',\n 'viewport',\n 'videoSize',\n ];\n\n for (const key of allowedKeys) {\n if (options[key] !== undefined) {\n worldParameters[key] = options[key];\n }\n }\n return worldParameters;\n}\n\nfunction createCucumberConfigContent(projectRoot: string, options: LegacyOptions): string {\n const outputDir = `dist/e2e/${projectRoot}`;\n const featuresDirectory = normalizePath(options.featuresDirectory || `${projectRoot}/features`);\n const testRunner = options.testRunner === 'playwright' ? 'playwright' : 'core';\n const tsNodeProject = resolveTsNodeProject(\n projectRoot,\n typeof options.tsConfig === 'string' ? options.tsConfig : undefined\n );\n\n const requireEntries: string[] = [`'${projectRoot}/src/**/*.ts'`];\n if (testRunner === 'playwright') {\n requireEntries.push(`'node_modules/@gnuechtel/nx-cucumber/src/playwright/playwright-world-default.js'`);\n requireEntries.push(`'node_modules/@gnuechtel/nx-cucumber/src/playwright/playwright-hooks.js'`);\n }\n\n const worldParameters = {\n outputDirectory: outputDir,\n ...extractWorldParameters(options),\n };\n\n const lines: string[] = [\n `process.env.TS_NODE_PROJECT = '${tsNodeProject}';`,\n 'module.exports = {',\n ' default: {',\n ` paths: ['${featuresDirectory}/**/*.feature'],`,\n ` requireModule: ['ts-node/register', 'tsconfig-paths/register'],`,\n ` require: [${requireEntries.join(', ')}],`,\n ` tags: '${typeof options.tags === 'string' ? options.tags : 'not @ignore'}',`,\n ' format: [',\n ` 'summary',`,\n ` 'progress-bar',`,\n ` 'json:dist/e2e/${projectRoot}/reports/cucumber-json/cucumber-test-report.json',`,\n ` 'html:dist/e2e/${projectRoot}/reports/html/cucumber-test-report-builtin.html',`,\n ` 'junit:dist/e2e/${projectRoot}/reports/test-results/cucumber-test-report.xml',`,\n ' ],',\n ` worldParameters: ${JSON.stringify(worldParameters, null, 4).replace(/\\n/g, '\\n ')},`,\n ...(typeof options.cucumberTimeout === 'number' ? [` timeout: ${options.cucumberTimeout},`] : []),\n ' publishQuiet: true,',\n ' },',\n '};',\n '',\n ];\n return lines.join('\\n');\n}\n\nfunction shouldFlagWatchTarget(targets: ProjectConfiguration['targets']): boolean {\n const watchCommand = targets?.['e2e-watch']?.options?.['commands'];\n if (!Array.isArray(watchCommand)) return false;\n return watchCommand.some((cmd) => typeof cmd === 'string' && cmd.includes('watch-message'));\n}\n\nfunction shouldRemoveLegacyE2eRunCommand(targets: ProjectConfiguration['targets']): boolean {\n const e2e = targets?.['e2e'];\n if (!e2e || e2e.executor !== 'nx:run-commands') return false;\n const command = e2e.options?.['command'];\n return typeof command === 'string' && command.includes('e2e-cucumber');\n}\n\nexport async function migrateCucumberApiToInferredTasks(\n tree: Tree,\n options: MigrationOptions = {}\n): Promise<MigrationReport> {\n const dryRun = options.dryRun ?? isDryRunRequested();\n const nxJson = (readNxJson(tree) ?? {}) as NxJsonConfiguration;\n const report: MigrationReport = {\n dryRun,\n pluginAdded: false,\n removedLegacyTargetDefaults: false,\n migratedProjects: [],\n };\n\n const hadPlugin = hasNxCucumberPlugin(nxJson);\n if (!hadPlugin) {\n report.pluginAdded = true;\n if (!dryRun) {\n nxJson.plugins ??= [];\n nxJson.plugins.push(PLUGIN_NAME);\n updateNxJson(tree, nxJson);\n }\n }\n\n if (nxJson.targetDefaults?.[LEGACY_EXECUTOR]) {\n report.removedLegacyTargetDefaults = true;\n if (!dryRun) {\n delete nxJson.targetDefaults[LEGACY_EXECUTOR];\n updateNxJson(tree, nxJson);\n }\n }\n\n for (const [projectName, projectConfig] of getProjects(tree).entries()) {\n const legacyTargets = getLegacyTargetNames(projectConfig);\n const removeLegacyRunCommandTarget = shouldRemoveLegacyE2eRunCommand(projectConfig.targets);\n if (legacyTargets.length === 0 && !removeLegacyRunCommandTarget) continue;\n\n const manualFollowUps: string[] = [];\n const removedTargets = [...legacyTargets];\n if (removeLegacyRunCommandTarget && !removedTargets.includes('e2e')) {\n removedTargets.push('e2e');\n }\n\n const cucumberConfigPath = `${projectConfig.root}/cucumber.js`;\n const hasCucumberConfig = tree.exists(cucumberConfigPath);\n const legacyOptions = pickLegacyOptions(projectConfig);\n\n if (shouldFlagWatchTarget(projectConfig.targets)) {\n manualFollowUps.push(\n 'Target \"e2e-watch\" still uses legacy watch-message flow. Review whether it should be replaced by framework-native watch mode.'\n );\n }\n\n if (hasCucumberConfig) {\n manualFollowUps.push(\n `Existing ${cucumberConfigPath} was kept. Verify tags/paths/worldParameters still reflect prior executor options.`\n );\n }\n\n const updatedProject: ProjectConfiguration = {\n ...projectConfig,\n targets: {\n ...(projectConfig.targets ?? {}),\n },\n };\n\n for (const targetName of removedTargets) {\n delete updatedProject.targets?.[targetName];\n }\n\n if (!dryRun) {\n updateProjectConfiguration(tree, projectName, updatedProject);\n if (!hasCucumberConfig) {\n tree.write(cucumberConfigPath, createCucumberConfigContent(projectConfig.root, legacyOptions));\n }\n }\n\n report.migratedProjects.push({\n project: projectName,\n projectRoot: projectConfig.root,\n removedTargets,\n createdCucumberConfig: !hasCucumberConfig,\n manualFollowUps,\n });\n }\n\n if (!dryRun) {\n tree.write(REPORT_PATH, JSON.stringify(report, null, 2));\n }\n\n logger.info(\n `[nx-cucumber migration] migrated projects: ${report.migratedProjects.length}, pluginAdded: ${report.pluginAdded}, dryRun: ${report.dryRun}`\n );\n if (report.migratedProjects.length > 0) {\n for (const project of report.migratedProjects) {\n logger.info(\n `[nx-cucumber migration] ${project.project}: removed targets [${project.removedTargets.join(\n ', '\n )}], created cucumber.js: ${project.createdCucumberConfig}`\n );\n for (const followUp of project.manualFollowUps) {\n logger.warn(`[nx-cucumber migration] ${project.project}: ${followUp}`);\n }\n }\n }\n if (!dryRun) {\n logger.info(`[nx-cucumber migration] report written to ${REPORT_PATH}`);\n }\n\n return report;\n}\n\nexport default async function migrateCucumberApiToInferredTasksEntry(tree: Tree): Promise<void> {\n await migrateCucumberApiToInferredTasks(tree);\n}\n"]}
|