-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: should remove mockPath from callstack whether success or failed (#…
…3971) Co-authored-by: lijifei <lijifei@bytedance.com>
- Loading branch information
Showing
4 changed files
with
42 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {} |
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,16 @@ | ||
export async function retryDynamicImport() { | ||
let retryTimes = 0 | ||
const load = async () => { | ||
try { | ||
return await import('./dynamic-module.js') | ||
} | ||
catch (e) { | ||
if (retryTimes === 3) | ||
throw new Error('import dynamic module failed.') | ||
retryTimes += 1 | ||
return await load() | ||
} | ||
} | ||
|
||
return await load() | ||
} |
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,17 @@ | ||
import { retryDynamicImport } from '../src/retry-dynamic-import' | ||
|
||
vi.mock('../src/dynamic-module', () => { | ||
return { foo: 'bar' } | ||
}) | ||
|
||
describe('retry-dynamic-import', () => { | ||
it('should dynamic import module success', async () => { | ||
expect(await retryDynamicImport()).toEqual({ foo: 'bar' }) | ||
}) | ||
it('should throw when retry over 3 times', async () => { | ||
vi.doMock('../src/dynamic-module', () => { | ||
throw new Error('foobar') | ||
}) | ||
await expect(retryDynamicImport()).rejects.toThrowError(new Error('import dynamic module failed.')) | ||
}) | ||
}) |
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