@gnuechtel/nx-cucumber 2.0.0-beta.1 → 2.0.0-beta.3

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 CHANGED
@@ -151,7 +151,13 @@ 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 is **not** defined in `project.json`. It is inferred by the plugin from the `cucumber.js` config file.
154
+ The `e2e` target behavior depends on the selected test runner:
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`.
155
161
 
156
162
  ### Additional project generator options
157
163
 
@@ -161,12 +167,18 @@ All possible project generator options may be passed as command-line parameters
161
167
 
162
168
  ### Inferred tasks
163
169
 
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:
170
+ In 2.x, no executor configuration is needed. For core projects, the `e2e` target is inferred automatically when the plugin detects a `cucumber.js` config file in a project directory:
165
171
 
166
172
  ```bash
167
173
  npx nx e2e my-project-e2e
168
174
  ```
169
175
 
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
+
170
182
  ### Plugin registration
171
183
 
172
184
  To enable inferred tasks, register the plugin in `nx.json`:
@@ -534,6 +546,32 @@ Since 2.x uses framework-native execution via `npx cucumber-js`, all Cucumber CL
534
546
 
535
547
  If a feature is missing, please open an issue with a minimal reproducible setup.
536
548
 
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
+
537
575
  ## Migration from 1.x
538
576
 
539
577
  ### Prerequisites
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gnuechtel/nx-cucumber",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.3",
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-beta.1",
16
- "@gnuechtel/shared-util": "2.0.0-beta.1"
15
+ "@gnuechtel/shared-coverage": "2.0.0-beta.3",
16
+ "@gnuechtel/shared-util": "2.0.0-beta.3"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "@cucumber/cucumber": ">=9 <13",
@@ -3,13 +3,27 @@ export interface WebServerConfig {
3
3
  url: string;
4
4
  reuseExistingServer?: boolean;
5
5
  timeout?: number;
6
+ /** Working directory for the server process. Defaults to the current working directory. */
7
+ cwd?: string;
8
+ /** Environment variables for the server process. Defaults to the current process environment. */
9
+ env?: NodeJS.ProcessEnv;
10
+ /**
11
+ * stdio mode for the server process. Defaults to 'ignore'.
12
+ *
13
+ * Keep the default 'ignore' when calling startWebServer at module load time or from any
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).
21
+ */
22
+ stdio?: 'pipe' | 'ignore';
6
23
  }
7
24
  /**
8
25
  * Starts a web server before Cucumber runs and stops it when the process exits.
9
26
  * Mirrors Playwright's webServer config pattern.
10
- *
11
- * Note: when running inside a parent `spawnSync` context (e.g., nyc coverage wrapper),
12
- * start the server externally before invoking cucumber and rely on `reuseExistingServer`.
13
27
  */
14
28
  export declare function startWebServer(config: WebServerConfig): void;
15
29
  export declare function stopWebServer(): void;
@@ -3,64 +3,79 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.startWebServer = startWebServer;
4
4
  exports.stopWebServer = stopWebServer;
5
5
  const child_process_1 = require("child_process");
6
+ const shared_util_1 = require("@gnuechtel/shared-util");
6
7
  let serverProcess;
8
+ let serverPort;
7
9
  /**
8
10
  * Starts a web server before Cucumber runs and stops it when the process exits.
9
11
  * Mirrors Playwright's webServer config pattern.
10
- *
11
- * Note: when running inside a parent `spawnSync` context (e.g., nyc coverage wrapper),
12
- * start the server externally before invoking cucumber and rely on `reuseExistingServer`.
13
12
  */
14
13
  function startWebServer(config) {
15
- const { command, url, reuseExistingServer = true, timeout = 60000 } = config;
14
+ const { command, url, reuseExistingServer = true, timeout = 60000, cwd, env, stdio = 'ignore' } = config;
16
15
  if (reuseExistingServer && isUrlReachable(url)) {
17
16
  console.log(`Reusing existing server at ${url}`);
18
17
  return;
19
18
  }
19
+ serverPort = extractPort(url);
20
20
  console.log(`Starting web server: ${command}`);
21
21
  serverProcess = (0, child_process_1.spawn)(command, {
22
22
  shell: true,
23
- stdio: 'pipe',
23
+ stdio,
24
24
  detached: true,
25
+ ...(cwd ? { cwd } : {}),
26
+ ...(env ? { env } : {}),
25
27
  });
26
- serverProcess.stdout?.on('data', (data) => {
27
- process.stdout.write(`[serve] ${data}`);
28
- });
29
- serverProcess.stderr?.on('data', (data) => {
30
- process.stderr.write(`[serve] ${data}`);
31
- });
28
+ if (stdio === 'pipe') {
29
+ serverProcess.stdout?.on('data', (data) => {
30
+ process.stdout.write(`[serve] ${data}`);
31
+ });
32
+ serverProcess.stderr?.on('data', (data) => {
33
+ process.stderr.write(`[serve] ${data}`);
34
+ });
35
+ }
32
36
  serverProcess.unref();
33
- process.on('exit', stopWebServer);
37
+ process.on('exit', stopWebServerOnProcessExit);
34
38
  process.on('SIGINT', stopWebServer);
35
39
  process.on('SIGTERM', stopWebServer);
36
40
  console.log(`Waiting for ${url}...`);
37
41
  waitForUrl(url, timeout);
38
42
  console.log(`Server ready at ${url}`);
39
- // Unref the stdio streams so they don't prevent the parent process from exiting
40
- // once the tests complete. The streams are still active and will forward output,
41
- // but the event loop won't be kept alive waiting for them.
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- serverProcess.stdout?.unref?.();
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
- serverProcess.stderr?.unref?.();
43
+ if (stdio === 'pipe') {
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ serverProcess.stdout?.unref?.();
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ serverProcess.stderr?.unref?.();
48
+ }
46
49
  }
47
50
  function stopWebServer() {
48
51
  if (!serverProcess || serverProcess.killed)
49
52
  return;
53
+ const pid = serverProcess.pid;
54
+ const port = serverPort;
55
+ serverProcess = undefined;
56
+ serverPort = undefined;
57
+ if (pid)
58
+ (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;
50
71
  try {
51
- if (serverProcess.pid) {
52
- process.kill(-serverProcess.pid, 'SIGTERM');
53
- }
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');
54
75
  }
55
76
  catch {
56
- try {
57
- serverProcess.kill();
58
- }
59
- catch {
60
- // ignore
61
- }
77
+ // ignore - process may have already exited
62
78
  }
63
- serverProcess = undefined;
64
79
  }
65
80
  function waitForUrl(url, timeout) {
66
81
  const interval = 1000;
@@ -79,15 +94,46 @@ function sleepSync(ms) {
79
94
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
80
95
  }
81
96
  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) {
82
120
  try {
83
- (0, child_process_1.execSync)(`node -e "fetch('${url}').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"`, {
84
- stdio: 'ignore',
85
- timeout: 3000,
86
- });
87
- return true;
121
+ const parsed = new URL(url);
122
+ const port = parseInt(parsed.port, 10);
123
+ if (port > 0)
124
+ return port;
125
+ return parsed.protocol === 'https:' ? 443 : 80;
88
126
  }
89
127
  catch {
90
- return false;
128
+ return undefined;
91
129
  }
92
130
  }
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
+ }
93
139
  //# sourceMappingURL=web-server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-server.js","sourceRoot":"","sources":["../../../../../libs/nx-cucumber/src/core/web-server.ts"],"names":[],"mappings":";;AAkBA,wCAwCC;AAED,sCAcC;AA1ED,iDAA8D;AAS9D,IAAI,aAAuC,CAAC;AAE5C;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,MAAuB;IACpD,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,mBAAmB,GAAG,IAAI,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC;IAE7E,IAAI,mBAAmB,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,8BAA8B,GAAG,EAAE,CAAC,CAAC;QACjD,OAAO;IACT,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;IAC/C,aAAa,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KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import { execSync, spawn, ChildProcess } from 'child_process';\n\nexport interface WebServerConfig {\n command: string;\n url: string;\n reuseExistingServer?: boolean;\n timeout?: number;\n}\n\nlet serverProcess: ChildProcess | 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 * start the server externally before invoking cucumber and rely on `reuseExistingServer`.\n */\nexport function startWebServer(config: WebServerConfig): void {\n const { command, url, reuseExistingServer = true, timeout = 60000 } = 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: 'pipe',\n detached: true,\n });\n\n serverProcess.stdout?.on('data', (data: Buffer) => {\n process.stdout.write(`[serve] ${data}`);\n });\n\n serverProcess.stderr?.on('data', (data: Buffer) => {\n process.stderr.write(`[serve] ${data}`);\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 // 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\nexport function stopWebServer(): void {\n if (!serverProcess || serverProcess.killed) return;\n try {\n if (serverProcess.pid) {\n process.kill(-serverProcess.pid, 'SIGTERM');\n }\n } catch {\n try {\n serverProcess.kill();\n } catch {\n // ignore\n }\n }\n serverProcess = undefined;\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
+ {"version":3,"file":"web-server.js","sourceRoot":"","sources":["../../../../../libs/nx-cucumber/src/core/web-server.ts"],"names":[],"mappings":";;AAkCA,wCA4CC;AAED,sCAUC;AA1FD,iDAAiD;AACjD,wDAAyD;AA0BzD,IAAI,aAAmD,CAAC;AACxD,IAAI,UAA8B,CAAC;AAEnC;;;GAGG;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,QAAQ,EAAE,GAAG,MAAM,CAAC;IAEzG,IAAI,mBAAmB,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,8BAA8B,GAAG,EAAE,CAAC,CAAC;QACjD,OAAO;IACT,CAAC;IAED,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAE9B,OAAO,CAAC,GAAG,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;IAC/C,aAAa,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE;QAC7B,KAAK,EAAE,IAAI;QACX,KAAK;QACL,QAAQ,EAAE,IAAI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AI,EAAE,EAAE,CAAC,CAAC;QACvC,IAAI,IAAI,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAC1B,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY;IACrC,IAAA,yBAAS,EACP,YAAY,EACZ;QACE,YAAY;QACZ,iBAAiB;QACjB,UAAU;QACV,4CAA4C,IAAI,uHAAuH;KACxK,EACD,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,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,12 +1,5 @@
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
- <% } %>
10
3
  module.exports = {
11
4
  default: {
12
5
  paths: ['<%= projectRoot %>/features/**/*.feature'],
@@ -13,12 +13,18 @@ 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;
16
19
  const normalizedDirectory = (0, devkit_1.normalizePath)(options.directory);
17
20
  const workspaceLayout = (0, devkit_1.getWorkspaceLayout)(tree);
18
21
  const skipAppsDir = workspaceLayout.appsDir === '.' || options.ignoreWorkspaceLayout;
19
22
  const parentDir = workspaceLayout.appsDir && !skipAppsDir ? workspaceLayout.appsDir + '/' : '';
20
23
  const projectRoot = `${parentDir}${normalizedDirectory}`;
21
24
  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
+ : {};
22
28
  (0, devkit_1.addProjectConfiguration)(tree, options.name, {
23
29
  root: projectRoot,
24
30
  sourceRoot: `${projectRoot}/src`,
@@ -31,6 +37,7 @@ async function cucumberJsGenerator(tree, options) {
31
37
  lintFilePatterns: [`${projectRoot}/**/*.ts`],
32
38
  },
33
39
  },
40
+ ...playwrightTargets,
34
41
  },
35
42
  implicitDependencies: [options.project],
36
43
  });
@@ -40,17 +47,14 @@ async function cucumberJsGenerator(tree, options) {
40
47
  'node_modules/@gnuechtel/nx-cucumber/src/playwright/playwright-hooks.js',
41
48
  ]
42
49
  : [];
43
- const isPlaywright = options.testRunner === 'playwright';
44
- const baseUrl = isPlaywright ? 'http://localhost:4200' : '';
45
- const serveTarget = isPlaywright ? `${options.project}:serve` : '';
46
50
  const substitutions = {
47
51
  ...options,
48
52
  workspaceRootRelative,
49
53
  projectRoot,
50
54
  playwrightRequires: JSON.stringify(playwrightRequires),
51
55
  isPlaywright,
52
- baseUrl,
53
- serveTarget,
56
+ baseUrl: baseUrl || '',
57
+ serveTarget: serveTarget || '',
54
58
  };
55
59
  (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files', 'all'), projectRoot, substitutions);
56
60
  (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files', options.testRunner), projectRoot, substitutions);
@@ -63,8 +67,54 @@ async function cucumberJsGenerator(tree, options) {
63
67
  'ts-node': '10.9.1',
64
68
  'tsconfig-paths': '4.2.0',
65
69
  };
70
+ if (isPlaywright) {
71
+ additionalDevDependencies['kill-port'] = '2.0.1';
72
+ additionalDevDependencies['start-server-and-test'] = '3.0.0';
73
+ }
66
74
  const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, additionalDevDependencies);
67
75
  return options.skipInstall ? () => undefined : installTask;
68
76
  }
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
+ }
69
119
  exports.default = cucumberJsGenerator;
70
120
  //# sourceMappingURL=project.js.map
@@ -1 +1 @@
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,O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AC;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"]}
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../../../../../../libs/nx-cucumber/src/generators/project/project.ts"],"names":[],"mappings":";;AAgBA,kDA2EC;;AA3FD,uCAUoB;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;IAChE,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,KAAK,YAAY,CAAC;IACzD,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC;IACnE,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAE1E,MAAM,mBAAmB,GAAG,IAAA,sBAAa,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC7D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AE,QAAQ,CAAC;IAClF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CAAC,GAAW;IAClC,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,SAAS,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC,IAAI,CAAC;IAC1C,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC;AAED,kBAAe,mBAAmB,CAAC","sourcesContent":["import {\n addProjectConfiguration,\n formatFiles,\n generateFiles,\n Tree,\n addDependenciesToPackageJson,\n normalizePath,\n offsetFromRoot,\n getWorkspaceLayout,\n readProjectConfiguration,\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 const isPlaywright = options.testRunner === 'playwright';\n const baseUrl = isPlaywright ? 'http://localhost:4200' : undefined;\n const serveTarget = isPlaywright ? `${options.project}:serve` : undefined;\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 const playwrightTargets =\n isPlaywright && baseUrl && serveTarget\n ? buildPlaywrightTargets(tree, options.project, options.name, serveTarget, baseUrl, projectRoot)\n : {};\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 ...playwrightTargets,\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 substitutions = {\n ...options,\n workspaceRootRelative,\n projectRoot,\n playwrightRequires: JSON.stringify(playwrightRequires),\n isPlaywright,\n baseUrl: baseUrl || '',\n serveTarget: 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 if (isPlaywright) {\n additionalDevDependencies['kill-port'] = '2.0.1';\n additionalDevDependencies['start-server-and-test'] = '3.0.0';\n }\n\n const installTask = addDependenciesToPackageJson(tree, {}, additionalDevDependencies);\n return options.skipInstall ? () => undefined : installTask;\n}\n\nfunction buildPlaywrightTargets(\n tree: Tree,\n projectName: string,\n e2eProjectName: string,\n serveTarget: string,\n baseUrl: string,\n projectRoot: string\n) {\n const prepareCommand = buildPlaywrightPrepareCommand();\n const e2eCommand = buildPlaywrightE2eCommand(tree, projectName, serveTarget, baseUrl, projectRoot);\n const e2eCiCommand = `npx nx run ${e2eProjectName}:e2e-prepare && npx nx run ${e2eProjectName}:e2e`;\n return {\n 'e2e-prepare': {\n command: prepareCommand,\n },\n e2e: {\n command: e2eCommand,\n },\n 'e2e-ci': {\n command: e2eCiCommand,\n },\n };\n}\n\nfunction buildPlaywrightPrepareCommand() {\n 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' });\"`;\n}\n\nfunction buildPlaywrightE2eCommand(\n tree: Tree,\n projectName: string,\n serveTarget: string,\n baseUrl: string,\n projectRoot: string\n) {\n const port = readPortFromUrl(baseUrl);\n const serveExecutor = readServeExecutor(tree, projectName);\n const serveCommand =\n serveExecutor === '@nx/vite:dev-server'\n ? `npx nx run ${serveTarget} --port=${port} --strictPort`\n : `npx nx run ${serveTarget}`;\n const testCommand = `npx cucumber-js --config ${projectRoot}/cucumber.js`;\n return `npx kill-port ${port} && start-server-and-test \"${serveCommand}\" ${baseUrl} \"${testCommand}\"`;\n}\n\nfunction readServeExecutor(tree: Tree, projectName: string) {\n try {\n return readProjectConfiguration(tree, projectName).targets?.['serve']?.executor;\n } catch {\n return undefined;\n }\n}\n\nfunction readPortFromUrl(url: string) {\n const parsedUrl = new URL(url);\n if (parsedUrl.port) return parsedUrl.port;\n return parsedUrl.protocol === 'https:' ? '443' : '80';\n}\n\nexport default cucumberJsGenerator;\n"]}
@@ -16,36 +16,71 @@ const debug = require('debug')('e2e:hooks');
16
16
  if (!global.nxCucumber) {
17
17
  global.nxCucumber = { disableCoverage: false };
18
18
  }
19
- // Disable timeout on playwright debugging (let cucumber.js config handle the default otherwise)
19
+ const defaultCucumberTimeout = global.nxCucumber.timeout || 30_000;
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.
20
22
  if (process.env['PWDEBUG']) {
21
23
  (0, cucumber_1.setDefaultTimeout)(-1);
22
24
  }
25
+ else {
26
+ (0, cucumber_1.setDefaultTimeout)(defaultCucumberTimeout);
27
+ }
23
28
  // We ignore all SSL errors, because we have self signed developer certificates
24
29
  process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
25
30
  function configuredBrowser() {
26
31
  return (0, playwright_browser_1.resolvePlaywrightBrowser)(global.nxCucumber.browser);
27
32
  }
33
+ let browserLaunchPromise;
28
34
  async function launchBrowser(label, headless) {
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`);
35
+ if (global.browserState.isStarted)
36
+ return;
37
+ if (!browserLaunchPromise) {
38
+ browserLaunchPromise = (async () => {
39
+ const browser = configuredBrowser();
40
+ debug(`${label} - Creating new ${headless ? 'headless' : 'headed'} ${browser} instance`);
41
+ const launchedBrowser = await (0, playwright_browser_2.resolvePlaywrightBrowserType)(browser).launch((0, playwright_browser_2.createPlaywrightLaunchOptions)(browser, headless));
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
+ });
36
61
  }
62
+ else {
63
+ debug(`${label} - Waiting for ongoing browser launch`);
64
+ }
65
+ await browserLaunchPromise;
37
66
  }
38
67
  async function closeBrowser(label) {
68
+ if (browserLaunchPromise) {
69
+ debug(`${label} - Waiting for ongoing browser launch before close`);
70
+ await browserLaunchPromise;
71
+ }
39
72
  if (global.browserState.isStarted) {
40
73
  debug(`${label} - Closing ${configuredBrowser()} instance`);
41
74
  try {
42
75
  await global.browser.close();
43
- global.browserState.isStarted = false;
44
76
  debug(`${label} - ${configuredBrowser()} instance closed`);
45
77
  }
46
78
  catch (e) {
47
79
  debug(`${label} - Could not close browser: %O`, e);
48
80
  }
81
+ finally {
82
+ global.browserState.isStarted = false;
83
+ }
49
84
  }
50
85
  }
51
86
  /**
@@ -69,6 +104,7 @@ async function launchBrowserIfRequired(label, launchHeadless) {
69
104
  }
70
105
  }
71
106
  (0, cucumber_1.BeforeAll)(async function () {
107
+ browserLaunchPromise = undefined;
72
108
  global.browserState = {
73
109
  isStarted: false,
74
110
  isHeadless: true,
@@ -116,10 +152,10 @@ async function launchBrowserIfRequired(label, launchHeadless) {
116
152
  // When javascript is enabled by default, we disable it only for scenarios which are tagged by @noscript
117
153
  this.parameters.disableJavaScript = true;
118
154
  });
119
- (0, cucumber_1.Before)({ name: 'ensure headed browser', tags: '@headed' }, async function () {
155
+ (0, cucumber_1.Before)({ name: 'ensure headed browser', tags: '@headed', timeout: browserLaunchHookTimeout }, async function () {
120
156
  await launchBrowserIfRequired('Before @headed', false);
121
157
  });
122
- (0, cucumber_1.Before)({ name: 'ensure headless browser', tags: 'not @headed' }, async function () {
158
+ (0, cucumber_1.Before)({ name: 'ensure headless browser', tags: 'not @headed', timeout: browserLaunchHookTimeout }, async function () {
123
159
  await launchBrowserIfRequired('Before not @headed', !this.parameters.headed);
124
160
  });
125
161
  (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;AACn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AC,CAAC;QAC3C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,KAAK,CAAC,8CAA8C,EAAE,CAAC,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,IAAA,gBAAK,EAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK;IAC/B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE,CAAC;QACrC,4GAA4G;QAC5G,IAAI,CAAC;YACH,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBAC9B,MAAM,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,gCAAgC;QAClC,CAAC;QACD,IAAI,CAAC;YACH,KAAK,CAAC,6BAA6B,CAAC,CAAC;YACrC,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"]}
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,MAA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C,UAAU,CAAC,eAAe,EAAE,CAAC;QACrC,4GAA4G;QAC5G,IAAI,CAAC;YACH,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBAC9B,MAAM,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,gCAAgC;QAClC,CAAC;QACD,IAAI,CAAC;YACH,KAAK,CAAC,6BAA6B,CAAC,CAAC;YACrC,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\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"]}