Skip to content

Commit 0342814

Browse files
amcaplanclaude
andcommitted
Fix lint error: use Promise.all instead of await in loop
Refactored the certificate error test to use Promise.all() instead of awaiting in a loop, which is more efficient and satisfies the no-await-in-loop eslint rule. The test still verifies that all 4 certificate error types are not retried, but now runs them in parallel instead of sequentially. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f8af4aa commit 0342814

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

packages/cli-kit/src/private/node/api.test.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -352,25 +352,27 @@ describe('retryAwareRequest', () => {
352352
'SSL certificate problem: unable to get local issuer certificate',
353353
]
354354

355-
for (const certError of certificateErrors) {
356-
const mockRequestFn = vi.fn().mockImplementation(() => {
357-
throw new Error(certError)
358-
})
355+
await Promise.all(
356+
certificateErrors.map(async (certError) => {
357+
const mockRequestFn = vi.fn().mockImplementation(() => {
358+
throw new Error(certError)
359+
})
359360

360-
const result = retryAwareRequest(
361-
{
362-
request: mockRequestFn,
363-
url: 'https://example.com/graphql.json',
364-
useNetworkLevelRetry: true,
365-
maxRetryTimeMs: 2000,
366-
},
367-
undefined,
368-
{defaultDelayMs: 10, scheduleDelay: (fn) => fn()},
369-
)
370-
371-
await expect(result).rejects.toThrowError(certError)
372-
expect(mockRequestFn).toHaveBeenCalledTimes(1)
373-
}
361+
const result = retryAwareRequest(
362+
{
363+
request: mockRequestFn,
364+
url: 'https://example.com/graphql.json',
365+
useNetworkLevelRetry: true,
366+
maxRetryTimeMs: 2000,
367+
},
368+
undefined,
369+
{defaultDelayMs: 10, scheduleDelay: (fn) => fn()},
370+
)
371+
372+
await expect(result).rejects.toThrowError(certError)
373+
expect(mockRequestFn).toHaveBeenCalledTimes(1)
374+
}),
375+
)
374376
})
375377
})
376378

@@ -447,13 +449,7 @@ describe('isTransientNetworkError', () => {
447449

448450
describe('isNetworkError', () => {
449451
test('identifies all transient network errors', () => {
450-
const transientErrors = [
451-
'ECONNRESET',
452-
'ETIMEDOUT',
453-
'ENOTFOUND',
454-
'socket hang up',
455-
'premature close',
456-
]
452+
const transientErrors = ['ECONNRESET', 'ETIMEDOUT', 'ENOTFOUND', 'socket hang up', 'premature close']
457453

458454
for (const errorMsg of transientErrors) {
459455
expect(isNetworkError(new Error(errorMsg))).toBe(true)

0 commit comments

Comments
 (0)