Skip to content

Commit b9414ca

Browse files
committed
[feat] Await all promises before exit
1 parent 3637c7d commit b9414ca

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

dist/index.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -34359,14 +34359,16 @@ async function run() {
3435934359
const failFast = core.getInput('fail-fast', { required: false }) === 'true';
3436034360
const flags = core.getInput('flags', { required: false });
3436134361
const cloudRunLocally = core.getInput('cloud-run-locally', { required: false }) === 'true';
34362+
const shouldCommentCloudTestRunUrlOnPR = core.getInput('comment-cloud-test-run-url-on-pr', { required: false }) === 'true';
34363+
const allPromises = [];
3436234364
const isCloud = await isCloudIntegrationEnabled();
3436334365
const commands = testPaths.map(testPath => generateCommand(testPath)), TOTAL_TEST_RUNS = commands.length, TEST_RESULT_URLS_MAP = new Proxy({}, {
3436434366
set: (target, key, value) => {
3436534367
target[key] = value;
3436634368
if (Object.keys(target).length === TOTAL_TEST_RUNS) {
34367-
if (isCloud) {
34369+
if (isCloud && shouldCommentCloudTestRunUrlOnPR) {
3436834370
// Generate PR comment with test run URLs
34369-
(0, githubHelper_1.generatePRComment)(target);
34371+
allPromises.push((0, githubHelper_1.generatePRComment)(target));
3437034372
}
3437134373
}
3437234374
return true;
@@ -34379,12 +34381,11 @@ async function run() {
3437934381
let allTestsPassed = true;
3438034382
if (parallel) {
3438134383
const childProcesses = [];
34382-
const exitPromises = [];
3438334384
commands.forEach(command => {
3438434385
const child = runCommand(command);
3438534386
childProcesses.push(child);
3438634387
TEST_PIDS.push(child.pid);
34387-
exitPromises.push(new Promise(resolve => {
34388+
allPromises.push(new Promise(resolve => {
3438834389
child.on('exit', (code, signal) => {
3438934390
const index = TEST_PIDS.indexOf(child.pid);
3439034391
if (index > -1) {
@@ -34412,13 +34413,12 @@ async function run() {
3441234413
});
3441334414
}));
3441434415
});
34415-
await Promise.all(exitPromises);
3441634416
}
3441734417
else {
3441834418
for (const command of commands) {
3441934419
const child = runCommand(command);
3442034420
TEST_PIDS.push(child.pid);
34421-
await new Promise(resolve => {
34421+
allPromises.push(new Promise(resolve => {
3442234422
child.on('exit', (code, signal) => {
3442334423
const index = TEST_PIDS.indexOf(child.pid);
3442434424
if (index > -1) {
@@ -34439,9 +34439,10 @@ async function run() {
3443934439
}
3444034440
resolve();
3444134441
});
34442-
});
34442+
}));
3444334443
}
3444434444
}
34445+
await Promise.all(allPromises);
3444534446
if (!allTestsPassed) {
3444634447
console.log('🚨 Some tests failed');
3444734448
process.exit(1);

src/index.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export async function run(): Promise<void> {
2222
const flags = core.getInput('flags', { required: false })
2323
const cloudRunLocally = core.getInput('cloud-run-locally', { required: false }) === 'true'
2424
const shouldCommentCloudTestRunUrlOnPR = core.getInput('comment-cloud-test-run-url-on-pr', { required: false }) === 'true'
25+
const allPromises: Promise<void>[] = [];
2526

2627
const isCloud = await isCloudIntegrationEnabled()
2728

@@ -33,7 +34,7 @@ export async function run(): Promise<void> {
3334
if (Object.keys(target).length === TOTAL_TEST_RUNS) {
3435
if (isCloud && shouldCommentCloudTestRunUrlOnPR) {
3536
// Generate PR comment with test run URLs
36-
generatePRComment(target);
37+
allPromises.push(generatePRComment(target));
3738
}
3839
}
3940
return true;
@@ -48,12 +49,12 @@ export async function run(): Promise<void> {
4849

4950
if (parallel) {
5051
const childProcesses = [] as any[];
51-
const exitPromises: Promise<void>[] = [];
52+
5253
commands.forEach(command => {
5354
const child = runCommand(command);
5455
childProcesses.push(child);
5556
TEST_PIDS.push(child.pid);
56-
exitPromises.push(new Promise(resolve => {
57+
allPromises.push(new Promise(resolve => {
5758
child.on('exit', (code: number, signal: string) => {
5859
const index = TEST_PIDS.indexOf(child.pid);
5960
if (index > -1) {
@@ -79,13 +80,11 @@ export async function run(): Promise<void> {
7980
});
8081
}));
8182
});
82-
83-
await Promise.all(exitPromises);
8483
} else {
8584
for (const command of commands) {
8685
const child = runCommand(command);
8786
TEST_PIDS.push(child.pid);
88-
await new Promise<void>(resolve => {
87+
allPromises.push(new Promise<void>(resolve => {
8988
child.on('exit', (code: number, signal: string) => {
9089
const index = TEST_PIDS.indexOf(child.pid);
9190
if (index > -1) {
@@ -104,9 +103,10 @@ export async function run(): Promise<void> {
104103
}
105104
resolve();
106105
});
107-
});
106+
}));
108107
}
109108
}
109+
await Promise.all(allPromises);
110110

111111
if (!allTestsPassed) {
112112
console.log('🚨 Some tests failed');

0 commit comments

Comments
 (0)