Skip to content

Commit f6442a5

Browse files
committed
fix test
1 parent 5678297 commit f6442a5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/core/test/lib/metrics/timing.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ describe('metrics.timing', () => {
1414
});
1515

1616
beforeEach(() => {
17-
jest.useFakeTimers('legacy');
1817
testClient = new TestClient(options);
1918
setCurrentClient(testClient);
2019
});
@@ -78,7 +77,10 @@ describe('metrics.timing', () => {
7877
});
7978

8079
it('works with a sync callback', async () => {
81-
const res = metricsDefault.timing('t1', () => 'oho');
80+
const res = metricsDefault.timing('t1', () => {
81+
sleepSync(200);
82+
return 'oho';
83+
});
8284
expect(res).toStrictEqual('oho');
8385

8486
const sendSpy = jest.spyOn(testClient.getTransport()!, 'send');
@@ -93,7 +95,10 @@ describe('metrics.timing', () => {
9395
});
9496

9597
it('works with an async callback', async () => {
96-
const res = metricsDefault.timing('t1', async () => 'oho');
98+
const res = metricsDefault.timing('t1', async () => {
99+
await new Promise(resolve => setTimeout(resolve, 200));
100+
return 'oho';
101+
});
97102
expect(res).toBeInstanceOf(Promise);
98103
expect(await res).toStrictEqual('oho');
99104

@@ -108,3 +113,12 @@ describe('metrics.timing', () => {
108113
]);
109114
});
110115
});
116+
117+
function sleepSync(milliseconds: number): void {
118+
const start = Date.now();
119+
for (let i = 0; i < 1e7; i++) {
120+
if (new Date().getTime() - start > milliseconds) {
121+
break;
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)