Skip to content

Commit 7ce0982

Browse files
jbedarddgp1130
authored andcommitted
test: keep npm servers alive while in debug state
1 parent 438ee6d commit 7ce0982

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

tests/legacy-cli/e2e_runner.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ setGlobalVariable('argv', argv);
122122
setGlobalVariable('ci', process.env['CI']?.toLowerCase() === 'true' || process.env['CI'] === '1');
123123
setGlobalVariable('package-manager', argv.yarn ? 'yarn' : 'npm');
124124

125-
Promise.all([findFreePort(), findFreePort()])
126-
.then(async ([httpPort, httpsPort]) => {
127-
setGlobalVariable('package-registry', 'http://localhost:' + httpPort);
128-
setGlobalVariable('package-secure-registry', 'http://localhost:' + httpsPort);
125+
Promise.all([findFreePort(), findFreePort()]).then(async ([httpPort, httpsPort]) => {
126+
setGlobalVariable('package-registry', 'http://localhost:' + httpPort);
127+
setGlobalVariable('package-secure-registry', 'http://localhost:' + httpsPort);
129128

130-
const registryProcess = await createNpmRegistry(httpPort, httpPort);
131-
const secureRegistryProcess = await createNpmRegistry(httpPort, httpsPort, true);
129+
const registryProcess = await createNpmRegistry(httpPort, httpPort);
130+
const secureRegistryProcess = await createNpmRegistry(httpPort, httpsPort, true);
132131

133-
return testsToRun
132+
return (
133+
testsToRun
134134
.reduce((previous, relativeName, testIndex) => {
135135
// Make sure this is a windows compatible path.
136136
let absoluteName = path.join(e2eRoot, relativeName);
@@ -207,35 +207,39 @@ Promise.all([findFreePort(), findFreePort()])
207207
);
208208
});
209209
}, Promise.resolve())
210-
.finally(() => {
211-
registryProcess.kill();
212-
secureRegistryProcess.kill();
213-
});
214-
})
215-
.then(
216-
() => {
217-
console.log(colors.green('Done.'));
218-
process.exit(0);
219-
},
220-
(err) => {
221-
console.log('\n');
222-
console.error(colors.red(`Test "${currentFileName}" failed...`));
223-
console.error(colors.red(err.message));
224-
console.error(colors.red(err.stack));
210+
// Output success vs failure information.
211+
.then(
212+
() => console.log(colors.green('Done.')),
213+
(err) => {
214+
console.log('\n');
215+
console.error(colors.red(`Test "${currentFileName}" failed...`));
216+
console.error(colors.red(err.message));
217+
console.error(colors.red(err.stack));
225218

226-
if (argv.debug) {
227-
console.log(`Current Directory: ${process.cwd()}`);
228-
console.log('Will loop forever while you debug... CTRL-C to quit.');
219+
if (argv.debug) {
220+
console.log(`Current Directory: ${process.cwd()}`);
221+
console.log('Will loop forever while you debug... CTRL-C to quit.');
229222

230-
/* eslint-disable no-constant-condition */
231-
while (1) {
232-
// That's right!
233-
}
234-
}
223+
/* eslint-disable no-constant-condition */
224+
while (1) {
225+
// That's right!
226+
}
227+
}
235228

236-
process.exit(1);
237-
},
229+
return Promise.reject(err);
230+
},
231+
)
232+
// Kill the registry processes before exiting.
233+
.finally(() => {
234+
registryProcess.kill();
235+
secureRegistryProcess.kill();
236+
})
237+
.then(
238+
() => process.exit(0),
239+
() => process.exit(1),
240+
)
238241
);
242+
});
239243

240244
function printHeader(testName: string, testIndex: number) {
241245
const text = `${testIndex + 1} of ${testsToRun.length}`;

0 commit comments

Comments
 (0)