test: fix flaky sleep test (#571)
This commit is contained in:
@@ -3,11 +3,13 @@ import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('sleep', () => {
|
||||
it('should resolve after the specified number of milliseconds', async () => {
|
||||
const start = Date.now();
|
||||
const start = performance.now();
|
||||
const milliseconds = 1000;
|
||||
await sleep(milliseconds);
|
||||
const end = Date.now();
|
||||
const end = performance.now();
|
||||
const elapsed = end - start;
|
||||
expect(elapsed).toBeGreaterThanOrEqual(milliseconds);
|
||||
// Flaky test due to JS's lack of precision in setTimeout,
|
||||
// so we allow for a 1ms difference
|
||||
expect(elapsed).toBeGreaterThanOrEqual(milliseconds - 1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user