Skip to content

Commit

Permalink
Switch to ts-expect-error and remove unused directives
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Sep 14, 2023
1 parent a271ad5 commit 4caca8a
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const PerformanceTimingScreen = () => {
const [dateTime, setDateTime] = React.useState(0);

React.useEffect(() => {
// @ts-ignore
// @ts-expect-error
if (typeof global.performance !== 'undefined') {
initialDate.current = Date.now();
// @ts-ignore
// @ts-expect-error
initialPerformance.current = global.performance.now();

const interval = setInterval(() => {
// @ts-ignore
// @ts-expect-error
setPerformanceTime(global.performance.now());
setDateTime(Date.now());
}, 1000);
Expand Down
1 change: 0 additions & 1 deletion src/js/profiling/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export class HermesProfiling implements Integration {
const client = this._getCurrentHub && this._getCurrentHub().getClient();
const options = client && client.getOptions();

// @ts-ignore not part of the browser options yet
const profilesSampleRate =
options && options._experiments && typeof options._experiments.profilesSampleRate === 'number'
? options._experiments.profilesSampleRate
Expand Down
2 changes: 0 additions & 2 deletions src/js/tracing/reactnativetracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ export class ReactNativeTracing implements Integration {
* Registers routing and request instrumentation.
*/
public setupOnce(
// @ts-ignore TODO
addGlobalEventProcessor: (callback: EventProcessor) => void,
getCurrentHub: () => Hub,
): void {
Expand All @@ -175,7 +174,6 @@ export class ReactNativeTracing implements Integration {
traceXHR,
// eslint-disable-next-line deprecation/deprecation
tracingOrigins,
// @ts-ignore TODO
shouldCreateSpanForRequest,
// eslint-disable-next-line deprecation/deprecation
tracePropagationTargets: thisOptionsTracePropagationTargets,
Expand Down
2 changes: 1 addition & 1 deletion src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ export const NATIVE: SentryNativeWrapper = {

if (NATIVE.platform === 'android') {
if ('message' in event) {
// @ts-ignore Android still uses the old message object, without this the serialization of events will break.
// @ts-expect-error Android still uses the old message object, without this the serialization of events will break.
event.message = { message: event.message };
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Tests ReactNativeClient', () => {
});

await expect(client.eventFromMessage('test')).resolves.toBeDefined();
// @ts-ignore: Is Mocked
// @ts-expect-error: Is Mocked
await expect(RN.LogBox.ignoreLogs).toBeCalled();
});

Expand Down
20 changes: 10 additions & 10 deletions test/integrations/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ describe('Tests the Release integration', () => {

let eventProcessor: EventProcessor = () => null;

// @ts-ignore Mock
// @ts-expect-error Mock
addGlobalEventProcessor.mockImplementation(e => (eventProcessor = e));
releaseIntegration.setupOnce();

expect(addGlobalEventProcessor).toBeCalled();

const client = getCurrentHub().getClient();

// @ts-ignore Mock
// @ts-expect-error Mock
client.getOptions.mockImplementation(() => ({}));

const event = await eventProcessor({}, {});
Expand All @@ -60,13 +60,13 @@ describe('Tests the Release integration', () => {

let eventProcessor: EventProcessor = () => null;

// @ts-ignore Mock
// @ts-expect-error Mock
addGlobalEventProcessor.mockImplementation(e => (eventProcessor = e));
releaseIntegration.setupOnce();

const client = getCurrentHub().getClient();

// @ts-ignore Mock
// @ts-expect-error Mock
client.getOptions.mockImplementation(() => ({
dist: 'options_dist',
}));
Expand All @@ -82,13 +82,13 @@ describe('Tests the Release integration', () => {

let eventProcessor: EventProcessor = () => null;

// @ts-ignore Mock
// @ts-expect-error Mock
addGlobalEventProcessor.mockImplementation(e => (eventProcessor = e));
releaseIntegration.setupOnce();

const client = getCurrentHub().getClient();

// @ts-ignore Mock
// @ts-expect-error Mock
client.getOptions.mockImplementation(() => ({
release: 'options_release',
}));
Expand All @@ -104,15 +104,15 @@ describe('Tests the Release integration', () => {

let eventProcessor: EventProcessor = () => null;

// @ts-ignore Mock
// @ts-expect-error Mock
addGlobalEventProcessor.mockImplementation(e => (eventProcessor = e));
releaseIntegration.setupOnce();

expect(addGlobalEventProcessor).toBeCalled();

const client = getCurrentHub().getClient();

// @ts-ignore Mock
// @ts-expect-error Mock
client.getOptions.mockImplementation(() => ({
dist: 'options_dist',
release: 'options_release',
Expand All @@ -129,15 +129,15 @@ describe('Tests the Release integration', () => {

let eventProcessor: EventProcessor = () => null;

// @ts-ignore Mock
// @ts-expect-error Mock
addGlobalEventProcessor.mockImplementation(e => (eventProcessor = e));
releaseIntegration.setupOnce();

expect(addGlobalEventProcessor).toBeCalled();

const client = getCurrentHub().getClient();

// @ts-ignore Mock
// @ts-expect-error Mock
client.getOptions.mockImplementation(() => ({
dist: 'options_dist',
release: 'options_release',
Expand Down
8 changes: 4 additions & 4 deletions test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe('Tests the SDK functionality', () => {
(NATIVE.isNativeAvailable as jest.Mock).mockImplementation(() => false);
init({});
expect(NATIVE.isNativeAvailable).toBeCalled();
// @ts-ignore enableNative not publicly available here.
// @ts-expect-error enableNative not publicly available here.
expect(usedOptions()?.enableNative).toEqual(false);
expect(usedOptions()?.transport).toEqual(makeFetchTransport);
});
Expand All @@ -226,7 +226,7 @@ describe('Tests the SDK functionality', () => {
(NATIVE.isNativeAvailable as jest.Mock).mockImplementation(() => false);
init({ enableNative: true });
expect(NATIVE.isNativeAvailable).toBeCalled();
// @ts-ignore enableNative not publicly available here.
// @ts-expect-error enableNative not publicly available here.
expect(usedOptions()?.enableNative).toEqual(false);
expect(usedOptions()?.transport).toEqual(makeFetchTransport);
});
Expand All @@ -235,7 +235,7 @@ describe('Tests the SDK functionality', () => {
(NATIVE.isNativeAvailable as jest.Mock).mockImplementation(() => false);
init({ enableNative: false });
expect(NATIVE.isNativeAvailable).not.toBeCalled();
// @ts-ignore enableNative not publicly available here.
// @ts-expect-error enableNative not publicly available here.
expect(usedOptions()?.enableNative).toEqual(false);
expect(usedOptions()?.transport).toEqual(makeFetchTransport);
});
Expand All @@ -248,7 +248,7 @@ describe('Tests the SDK functionality', () => {
});
expect(usedOptions()?.transport).toEqual(mockTransport);
expect(NATIVE.isNativeAvailable).toBeCalled();
// @ts-ignore enableNative not publicly available here.
// @ts-expect-error enableNative not publicly available here.
expect(usedOptions()?.enableNative).toEqual(false);
});
});
Expand Down
8 changes: 4 additions & 4 deletions test/touchevents.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('TouchEventBoundary._onTouchStart', () => {
},
};

// @ts-ignore Calling private member
// @ts-expect-error Calling private member
boundary._onTouchStart(event);

expect(addBreadcrumb).not.toBeCalled();
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('TouchEventBoundary._onTouchStart', () => {
},
};

// @ts-ignore Calling private member
// @ts-expect-error Calling private member
boundary._onTouchStart(event);

expect(addBreadcrumb).toBeCalledWith({
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('TouchEventBoundary._onTouchStart', () => {
},
};

// @ts-ignore Calling private member
// @ts-expect-error Calling private member
boundary._onTouchStart(event);

expect(addBreadcrumb).toBeCalledWith({
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('TouchEventBoundary._onTouchStart', () => {
},
};

// @ts-ignore Calling private member
// @ts-expect-error Calling private member
boundary._onTouchStart(event);

expect(addBreadcrumb).toBeCalledWith({
Expand Down
18 changes: 9 additions & 9 deletions test/tracing/reactnativetracing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ describe('ReactNativeTracing', () => {
expect(transaction.op).toBe(UI_LOAD);

expect(
// @ts-ignore access private for test
// @ts-expect-error access private for test
transaction._measurements[APP_START_COLD].value,
).toEqual(timeOriginMilliseconds - appStartTimeMilliseconds);
expect(
// @ts-ignore access private for test
// @ts-expect-error access private for test
transaction._measurements[APP_START_COLD].unit,
).toBe('millisecond');
}
Expand Down Expand Up @@ -163,11 +163,11 @@ describe('ReactNativeTracing', () => {
expect(transaction.op).toBe(UI_LOAD);

expect(
// @ts-ignore access private for test
// @ts-expect-error access private for test
transaction._measurements[APP_START_WARM].value,
).toEqual(timeOriginMilliseconds - appStartTimeMilliseconds);
expect(
// @ts-ignore access private for test
// @ts-expect-error access private for test
transaction._measurements[APP_START_WARM].unit,
).toBe('millisecond');
}
Expand Down Expand Up @@ -198,12 +198,12 @@ describe('ReactNativeTracing', () => {

if (transaction) {
expect(
// @ts-ignore access private for test
// @ts-expect-error access private for test
transaction._measurements[APP_START_WARM],
).toBeUndefined();

expect(
// @ts-ignore access private for test
// @ts-expect-error access private for test
transaction._measurements[APP_START_COLD],
).toBeUndefined();
}
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('ReactNativeTracing', () => {
// trigger idle transaction to finish and call before finish callbacks
jest.advanceTimersByTime(DEFAULT_IDLE_TIMEOUT);

// @ts-ignore access private for test
// @ts-expect-error access private for test
expect(routeTransaction._measurements[APP_START_COLD].value).toBe(
timeOriginMilliseconds - appStartTimeMilliseconds,
);
Expand Down Expand Up @@ -327,7 +327,7 @@ describe('ReactNativeTracing', () => {
// trigger idle transaction to finish and call before finish callbacks
jest.advanceTimersByTime(DEFAULT_IDLE_TIMEOUT);

// @ts-ignore access private for test
// @ts-expect-error access private for test
expect(routeTransaction._measurements[APP_START_WARM].value).toBe(
timeOriginMilliseconds - appStartTimeMilliseconds,
);
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('ReactNativeTracing', () => {
// trigger idle transaction to finish and call before finish callbacks
jest.advanceTimersByTime(DEFAULT_IDLE_TIMEOUT);

// @ts-ignore access private for test
// @ts-expect-error access private for test
expect(routeTransaction._measurements).toMatchObject({});

expect(routeTransaction.op).not.toBe(UI_LOAD);
Expand Down
4 changes: 2 additions & 2 deletions test/vendor/buffer/utf8ToBytes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ describe('Buffer utf8 tests', () => {
describe('test strings', () => {
for (const input of testCases) {
it(`should encode "${input}"`, () => {
// @ts-ignore The test run in node where Buffer is available
// @ts-expect-error The test run in node where Buffer is available
const actual = Buffer.from(utf8ToBytes(input));
// @ts-ignore The test run in node where Buffer is available
// @ts-expect-error The test run in node where Buffer is available
const expected = Buffer.from(input, 'utf8');

expect(actual).toEqual(expected);
Expand Down
16 changes: 8 additions & 8 deletions test/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jest.mock('react-native', () => {
return Promise.resolve(true);
}),
closeNativeSdk: jest.fn(() => Promise.resolve()),
// @ts-ignore for testing.
// @ts-expect-error for testing.
_getLastPayload: () => ({ initPayload }),
startProfiling: jest.fn(),
stopProfiling: jest.fn(),
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('Tests Native Wrapper', () => {
});

expect(RNSentry.initNativeSdk).toBeCalled();
// @ts-ignore mock value
// @ts-expect-error mock value
const initParameter = RNSentry.initNativeSdk.mock.calls[0][0];
expect(initParameter).not.toHaveProperty('beforeSend');
expect(NATIVE.enableNative).toBe(true);
Expand All @@ -150,7 +150,7 @@ describe('Tests Native Wrapper', () => {
});

expect(RNSentry.initNativeSdk).toBeCalled();
// @ts-ignore mock value
// @ts-expect-error mock value
const initParameter = RNSentry.initNativeSdk.mock.calls[0][0];
expect(initParameter).not.toHaveProperty('beforeBreadcrumb');
expect(NATIVE.enableNative).toBe(true);
Expand All @@ -165,7 +165,7 @@ describe('Tests Native Wrapper', () => {
});

expect(RNSentry.initNativeSdk).toBeCalled();
// @ts-ignore mock value
// @ts-expect-error mock value
const initParameter = RNSentry.initNativeSdk.mock.calls[0][0];
expect(initParameter).not.toHaveProperty('beforeSendTransaction');
expect(NATIVE.enableNative).toBe(true);
Expand All @@ -180,7 +180,7 @@ describe('Tests Native Wrapper', () => {
});

expect(RNSentry.initNativeSdk).toBeCalled();
// @ts-ignore mock value
// @ts-expect-error mock value
const initParameter = RNSentry.initNativeSdk.mock.calls[0][0];
expect(initParameter).not.toHaveProperty('integrations');
expect(NATIVE.enableNative).toBe(true);
Expand Down Expand Up @@ -311,10 +311,10 @@ describe('Tests Native Wrapper', () => {
try {
await NATIVE.initNativeSdk({ dsn: 'test-dsn', enableNative: false });

// @ts-ignore for testing, does not accept an empty class.
// @ts-expect-error for testing, does not accept an empty class.
await NATIVE.sendEnvelope({});
} catch (error) {
// @ts-ignore it is an error but it does not know the type.
// @ts-expect-error it is an error but it does not know the type.
expect(error.message).toMatch('Native is disabled');
}
expect(RNSentry.captureEnvelope).not.toBeCalled();
Expand Down Expand Up @@ -504,7 +504,7 @@ describe('Tests Native Wrapper', () => {
test('serializes all user object keys', async () => {
NATIVE.setUser({
email: '[email protected]',
// @ts-ignore Intentional incorrect type to simulate using a double as an id (We had a user open an issue because this didn't work before)
// @ts-expect-error Intentional incorrect type to simulate using a double as an id (We had a user open an issue because this didn't work before)
id: 3.14159265359,
unique: 123,
});
Expand Down

0 comments on commit 4caca8a

Please sign in to comment.