Skip to content

Commit ba966d6

Browse files
authored
test: Fix flaky App Start Tests (#4299)
1 parent 8cf605f commit ba966d6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/core/test/tracing/integrations/appStart.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { NATIVE } from '../../../src/js/wrapper';
3333
import { getDefaultTestClientOptions, TestClient } from '../../mocks/client';
3434
import { mockFunction } from '../../testutils';
3535

36+
let dateNowSpy: jest.SpyInstance;
37+
3638
jest.mock('../../../src/js/wrapper', () => {
3739
return {
3840
NATIVE: {
@@ -1057,6 +1059,9 @@ function mockTooOldAppStart() {
10571059
function mockReactNativeBundleExecutionStartTimestamp() {
10581060
RN_GLOBAL_OBJ.nativePerformanceNow = () => 100; // monotonic clock like `performance.now()`
10591061
RN_GLOBAL_OBJ.__BUNDLE_START_TIME__ = 50; // 50ms after time origin
1062+
1063+
const currentTimeMilliseconds = Date.now();
1064+
dateNowSpy = jest.spyOn(Date, 'now').mockImplementation(() => currentTimeMilliseconds);
10601065
}
10611066

10621067
/**
@@ -1065,6 +1070,10 @@ function mockReactNativeBundleExecutionStartTimestamp() {
10651070
function clearReactNativeBundleExecutionStartTimestamp() {
10661071
delete RN_GLOBAL_OBJ.nativePerformanceNow;
10671072
delete RN_GLOBAL_OBJ.__BUNDLE_START_TIME__;
1073+
1074+
if (dateNowSpy) {
1075+
dateNowSpy.mockRestore();
1076+
}
10681077
}
10691078

10701079
function set__DEV__(value: boolean) {

0 commit comments

Comments
 (0)