Skip to content

Commit 98cf4b7

Browse files
authored
chore(react-native): fix nightly (#32507)
## Current Behavior The React Native e2e tests contain variable naming conflicts and inconsistent error handling in the process cleanup sections: - Variables named `process` shadow the global Node.js `process` object - Inconsistent error handling patterns in process cleanup logic - Some cleanup operations attempt to kill processes that may not exist ## Expected Behavior The React Native e2e tests should have: - Clear variable names that don't shadow global objects - Consistent error handling patterns throughout all test cleanup sections - Robust process cleanup that handles cases where processes may not be running ### Changes Made 1. **Variable Naming**: Renamed `process` variables to `childProcess` to avoid shadowing the global Node.js `process` object 2. **Error Handling**: Added consistent try-catch blocks around all process cleanup operations 3. **Process Cleanup**: Simplified cleanup logic by passing `undefined` for process ID when the process reference is not available, allowing `killProcessAndPorts` to handle port cleanup appropriately This fixes issues that could occur in nightly builds where process cleanup wasn't being handled consistently, potentially leading to hanging processes or ports.
1 parent 3d2e256 commit 98cf4b7

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

e2e/react-native/src/react-native.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ describe('@nx/react-native', () => {
7878
}, 200_000);
7979

8080
it('should start the app', async () => {
81-
let process: ChildProcess;
81+
let childProcess: ChildProcess;
8282
const port = 8082;
8383

8484
try {
85-
process = await runCommandUntil(
85+
childProcess = await runCommandUntil(
8686
`start ${appName} --no-interactive --port=${port}`,
8787
(output) => {
8888
return (
@@ -97,17 +97,21 @@ describe('@nx/react-native', () => {
9797
}
9898

9999
// port and process cleanup
100-
if (process && process.pid) {
101-
await killProcessAndPorts(process.pid, port);
100+
try {
101+
if (childProcess && childProcess.pid) {
102+
await killProcessAndPorts(childProcess.pid, port);
103+
}
104+
} catch (err) {
105+
expect(err).toBeFalsy();
102106
}
103107
});
104108

105109
it('should serve', async () => {
106-
let process: ChildProcess;
110+
let childProcess: ChildProcess;
107111
const port = 8081;
108112

109113
try {
110-
process = await runCommandUntil(
114+
childProcess = await runCommandUntil(
111115
`serve ${appName} --port=${port}`,
112116
(output) => {
113117
return output.includes(`http://localhost:${port}`);
@@ -119,8 +123,8 @@ describe('@nx/react-native', () => {
119123

120124
// port and process cleanup
121125
try {
122-
if (process && process.pid) {
123-
await killProcessAndPorts(process.pid, port);
126+
if (childProcess && childProcess.pid) {
127+
await killProcessAndPorts(childProcess.pid, port);
124128
}
125129
} catch (err) {
126130
expect(err).toBeFalsy();
@@ -137,9 +141,7 @@ describe('@nx/react-native', () => {
137141

138142
// port and process cleanup
139143
try {
140-
if (process && process.pid) {
141-
await killProcessAndPorts(process.pid, 4200);
142-
}
144+
await killProcessAndPorts(undefined, 4200);
143145
} catch (err) {
144146
expect(err).toBeFalsy();
145147
}
@@ -192,9 +194,7 @@ describe('@nx/react-native', () => {
192194
expect(() => runCLI(`e2e ${appName2}-e2e`)).not.toThrow();
193195
// port and process cleanup
194196
try {
195-
if (process && process.pid) {
196-
await killProcessAndPorts(process.pid, 4200);
197-
}
197+
await killProcessAndPorts(undefined, 4200);
198198
} catch (err) {
199199
expect(err).toBeFalsy();
200200
}

0 commit comments

Comments
 (0)