forked from nitrojs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: retry writing traced files if there are conflicts (nitrojs#537)
- Loading branch information
1 parent
de548f0
commit 03d420e
Showing
3 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { retry } from '../../src/utils' | ||
|
||
describe('retry', () => { | ||
it('retries function', async () => { | ||
let counter = 0 | ||
// eslint-disable-next-line require-await | ||
const fn = async () => { | ||
if (!counter++) { | ||
throw new Error('deliberate') | ||
} | ||
} | ||
|
||
await retry(fn, 3) | ||
expect(counter).toEqual(2) | ||
}) | ||
it('throws function', async () => { | ||
// eslint-disable-next-line require-await | ||
const fn = async () => { throw new Error('deliberate') } | ||
expect(await retry(fn, 2).catch(() => 'thrown')).toEqual('thrown') | ||
}) | ||
}) |