Skip to content

Commit ef6c9a9

Browse files
committed
Fix Windows test failures by catching spawn promises immediately
1 parent 37937e0 commit ef6c9a9

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

test/agent.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,9 @@ describe('agent', () => {
473473
describe('execNpm argument transformation', () => {
474474
it('should have a function that returns a promise', () => {
475475
const result = execNpm(['--version'])
476-
expect(result).toBeInstanceOf(Promise)
477-
// Catch promise to prevent unhandled rejection on Windows.
476+
// Catch promise immediately to prevent unhandled rejection on Windows.
478477
result.catch(() => {})
478+
expect(result).toBeInstanceOf(Promise)
479479
})
480480

481481
it('should be a function', () => {
@@ -486,9 +486,9 @@ describe('agent', () => {
486486
describe('execPnpm argument transformation', () => {
487487
it('should have a function that returns a promise', () => {
488488
const result = execPnpm(['--version'])
489-
expect(result).toBeInstanceOf(Promise)
490-
// Catch promise to prevent unhandled rejection on Windows.
489+
// Catch promise immediately to prevent unhandled rejection on Windows.
491490
result.catch(() => {})
491+
expect(result).toBeInstanceOf(Promise)
492492
})
493493

494494
it('should be a function', () => {
@@ -499,9 +499,9 @@ describe('agent', () => {
499499
describe('execYarn argument transformation', () => {
500500
it('should have a function that returns a promise', () => {
501501
const result = execYarn(['--version'])
502-
expect(result).toBeInstanceOf(Promise)
503-
// Catch promise to prevent unhandled rejection on Windows.
502+
// Catch promise immediately to prevent unhandled rejection on Windows.
504503
result.catch(() => {})
504+
expect(result).toBeInstanceOf(Promise)
505505
})
506506

507507
it('should be a function', () => {
@@ -512,9 +512,9 @@ describe('agent', () => {
512512
describe('execScript argument transformation', () => {
513513
it('should have a function that returns a promise', () => {
514514
const result = execScript('test')
515-
expect(result).toBeInstanceOf(Promise)
516-
// Catch promise to prevent unhandled rejection on Windows.
515+
// Catch promise immediately to prevent unhandled rejection on Windows.
517516
result.catch(() => {})
517+
expect(result).toBeInstanceOf(Promise)
518518
})
519519

520520
it('should be a function', () => {
@@ -523,25 +523,25 @@ describe('agent', () => {
523523

524524
it('should handle script name with array args', () => {
525525
const result = execScript('test', ['--coverage'])
526-
expect(result).toBeInstanceOf(Promise)
527-
// Catch promise to prevent unhandled rejection on Windows.
526+
// Catch promise immediately to prevent unhandled rejection on Windows.
528527
result.catch(() => {})
528+
expect(result).toBeInstanceOf(Promise)
529529
})
530530

531531
it('should handle script name with options object', () => {
532532
const result = execScript('test', { cwd: process.cwd() })
533-
expect(result).toBeInstanceOf(Promise)
534-
// Catch promise to prevent unhandled rejection on Windows.
533+
// Catch promise immediately to prevent unhandled rejection on Windows.
535534
result.catch(() => {})
535+
expect(result).toBeInstanceOf(Promise)
536536
})
537537

538538
it('should handle script name with args and options', () => {
539539
const result = execScript('test', ['--coverage'], {
540540
cwd: process.cwd(),
541541
})
542-
expect(result).toBeInstanceOf(Promise)
543-
// Catch promise to prevent unhandled rejection on Windows.
542+
// Catch promise immediately to prevent unhandled rejection on Windows.
544543
result.catch(() => {})
544+
expect(result).toBeInstanceOf(Promise)
545545
})
546546
})
547547
})

test/dlx-binary.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,19 @@ describe('dlx-binary', () => {
140140
name: 'cached-binary',
141141
url,
142142
})
143+
// Catch spawn promise immediately to prevent unhandled rejection on Windows.
144+
result1.spawnPromise.catch(() => {})
143145
expect(result1.downloaded).toBe(true)
144146

145147
// Second call - should use cache
146148
const result2 = await dlxBinary(['--version'], {
147149
name: 'cached-binary',
148150
url,
149151
})
152+
// Catch spawn promise immediately to prevent unhandled rejection on Windows.
153+
result2.spawnPromise.catch(() => {})
150154
expect(result2.downloaded).toBe(false)
151155
expect(result2.binaryPath).toBe(result1.binaryPath)
152-
await result1.spawnPromise.catch(() => {})
153-
await result2.spawnPromise.catch(() => {})
154156
} finally {
155157
restoreHome()
156158
}
@@ -326,6 +328,8 @@ describe('dlx-binary', () => {
326328
name: 'ttl-binary',
327329
url,
328330
})
331+
// Catch spawn promise immediately to prevent unhandled rejection on Windows.
332+
result.spawnPromise.catch(() => {})
329333

330334
expect(result.downloaded).toBe(true)
331335

@@ -338,10 +342,10 @@ describe('dlx-binary', () => {
338342
name: 'ttl-binary',
339343
url,
340344
})
345+
// Catch spawn promise immediately to prevent unhandled rejection on Windows.
346+
result2.spawnPromise.catch(() => {})
341347

342348
expect(result2.downloaded).toBe(true)
343-
await result.spawnPromise.catch(() => {})
344-
await result2.spawnPromise.catch(() => {})
345349
} finally {
346350
restoreHome()
347351
}
@@ -1109,16 +1113,18 @@ describe('dlx-binary', () => {
11091113
name: 'concurrent-binary',
11101114
url,
11111115
})
1116+
// Catch spawn promise immediately to prevent unhandled rejection on Windows.
1117+
result1.spawnPromise.catch(() => {})
11121118
expect(result1.downloaded).toBe(true)
11131119

11141120
// Second download should use cache
11151121
const result2 = await dlxBinary(['--version'], {
11161122
name: 'concurrent-binary',
11171123
url,
11181124
})
1125+
// Catch spawn promise immediately to prevent unhandled rejection on Windows.
1126+
result2.spawnPromise.catch(() => {})
11191127
expect(result2.downloaded).toBe(false)
1120-
await result1.spawnPromise.catch(() => {})
1121-
await result2.spawnPromise.catch(() => {})
11221128
} finally {
11231129
restoreHome()
11241130
}

0 commit comments

Comments
 (0)