From 591174cf3df39a6d0c490b0a0227e58df7efbfdb Mon Sep 17 00:00:00 2001 From: Yousif Ahmed Date: Wed, 18 Dec 2024 16:34:12 +0000 Subject: [PATCH] test: fix unit tests --- .../tests/auto-instrumentation/app-start-plugin.test.ts | 5 +++-- .../react-native/tests/create-navigation-span.test.ts | 9 +++++---- .../react-native/tests/platform-extensions.test.ts | 3 ++- .../test/create-navigation-container.test.tsx | 6 +++--- .../test/navigation-context.test.tsx | 4 ++-- packages/test-utilities/lib/mock-span-factory.ts | 2 -- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/platforms/react-native/tests/auto-instrumentation/app-start-plugin.test.ts b/packages/platforms/react-native/tests/auto-instrumentation/app-start-plugin.test.ts index ffce03791..840159914 100644 --- a/packages/platforms/react-native/tests/auto-instrumentation/app-start-plugin.test.ts +++ b/packages/platforms/react-native/tests/auto-instrumentation/app-start-plugin.test.ts @@ -4,6 +4,7 @@ import createClock from '../../lib/clock' import { AppStartPlugin } from '../../lib/auto-instrumentation/app-start-plugin' import type { ReactNativeConfiguration } from '../../lib/config' import type { AppRegistry } from 'react-native' +import type { ReactNativeSpanFactory } from '../../lib/span-factory' describe('app start plugin', () => { let spanFactory: MockSpanFactory @@ -20,7 +21,7 @@ describe('app start plugin', () => { it('starts an app start span when autoInstrumentAppStarts is true', () => { const appStartTime = 1234 - const plugin = new AppStartPlugin(appStartTime, spanFactory, clock, appRegistry) + const plugin = new AppStartPlugin(appStartTime, spanFactory as unknown as ReactNativeSpanFactory, clock, appRegistry) plugin.configure(createConfiguration({ autoInstrumentAppStarts: true })) @@ -34,7 +35,7 @@ describe('app start plugin', () => { }) it('does not start an app start span when autoInstrumentAppStarts is false', () => { - const plugin = new AppStartPlugin(1234, spanFactory, clock, appRegistry) + const plugin = new AppStartPlugin(1234, spanFactory as unknown as ReactNativeSpanFactory, clock, appRegistry) plugin.configure(createConfiguration({ autoInstrumentAppStarts: false })) diff --git a/packages/platforms/react-native/tests/create-navigation-span.test.ts b/packages/platforms/react-native/tests/create-navigation-span.test.ts index 910e57865..fcf0c21d5 100644 --- a/packages/platforms/react-native/tests/create-navigation-span.test.ts +++ b/packages/platforms/react-native/tests/create-navigation-span.test.ts @@ -1,10 +1,11 @@ import { MockSpanFactory } from '@bugsnag/js-performance-test-utilities' import { createNavigationSpan } from '../lib/create-navigation-span' +import type { ReactNativeSpanFactory } from '../lib/span-factory' describe('createNavigationSpan', () => { it('sets the span name to the route prefixed with [Navigation]', () => { const spanFactory = new MockSpanFactory() - const span = createNavigationSpan(spanFactory, 'testRoute', { isFirstClass: false }) + const span = createNavigationSpan(spanFactory as unknown as ReactNativeSpanFactory, 'testRoute', { isFirstClass: false }) const endedSpan = span.end(12345, spanFactory.sampler.spanProbability) expect(endedSpan.name).toBe('[Navigation]testRoute') @@ -12,7 +13,7 @@ describe('createNavigationSpan', () => { it('always sets the span as first class', () => { const spanFactory = new MockSpanFactory() - const span = createNavigationSpan(spanFactory, 'testRoute', { isFirstClass: false }) + const span = createNavigationSpan(spanFactory as unknown as ReactNativeSpanFactory, 'testRoute', { isFirstClass: false }) const endedSpan = span.end(12345, spanFactory.sampler.spanProbability) expect(endedSpan.attributes.toJson()).toContainEqual({ key: 'bugsnag.span.first_class', value: { boolValue: true } }) @@ -20,7 +21,7 @@ describe('createNavigationSpan', () => { it('includes navigation category attribute', () => { const spanFactory = new MockSpanFactory() - const span = createNavigationSpan(spanFactory, 'testRoute', { isFirstClass: true }) + const span = createNavigationSpan(spanFactory as unknown as ReactNativeSpanFactory, 'testRoute', { isFirstClass: true }) const endedSpan = span.end(12345, spanFactory.sampler.spanProbability) expect(endedSpan.attributes.toJson()).toContainEqual({ key: 'bugsnag.span.category', value: { stringValue: 'navigation' } }) @@ -28,7 +29,7 @@ describe('createNavigationSpan', () => { it('includes the route attribute', () => { const spanFactory = new MockSpanFactory() - const span = createNavigationSpan(spanFactory, 'testRoute', { isFirstClass: true }) + const span = createNavigationSpan(spanFactory as unknown as ReactNativeSpanFactory, 'testRoute', { isFirstClass: true }) const endedSpan = span.end(12345, spanFactory.sampler.spanProbability) expect(endedSpan.attributes.toJson()).toContainEqual({ key: 'bugsnag.navigation.route', value: { stringValue: 'testRoute' } }) diff --git a/packages/platforms/react-native/tests/platform-extensions.test.ts b/packages/platforms/react-native/tests/platform-extensions.test.ts index 6810296c1..19597e7d7 100644 --- a/packages/platforms/react-native/tests/platform-extensions.test.ts +++ b/packages/platforms/react-native/tests/platform-extensions.test.ts @@ -1,3 +1,4 @@ +import type { ReactNativeSpanFactory } from '../lib' import { platformExtensions } from '../lib/platform-extensions' import { createTestClient, IncrementingClock, InMemoryDelivery, VALID_API_KEY } from '@bugsnag/js-performance-test-utilities' @@ -7,7 +8,7 @@ describe('startNavigationSpan', () => { it('creates a navigation span', async () => { const delivery = new InMemoryDelivery() const clock = new IncrementingClock() - const testClient = createTestClient({ deliveryFactory: () => delivery, platformExtensions: (spanFactory, spanContextStorage) => platformExtensions(0, clock, spanFactory, spanContextStorage) }) + const testClient = createTestClient({ deliveryFactory: () => delivery, platformExtensions: (spanFactory, spanContextStorage) => platformExtensions(0, clock, spanFactory as unknown as ReactNativeSpanFactory, spanContextStorage) }) testClient.start({ apiKey: VALID_API_KEY }) await jest.runOnlyPendingTimersAsync() diff --git a/packages/plugin-react-navigation/test/create-navigation-container.test.tsx b/packages/plugin-react-navigation/test/create-navigation-container.test.tsx index 43dc0516a..8e9d5f347 100644 --- a/packages/plugin-react-navigation/test/create-navigation-container.test.tsx +++ b/packages/plugin-react-navigation/test/create-navigation-container.test.tsx @@ -1,5 +1,5 @@ import { MockSpanFactory } from '@bugsnag/js-performance-test-utilities' -import type { ReactNativeConfiguration } from '@bugsnag/react-native-performance' +import type { ReactNativeConfiguration, ReactNativeSpanFactory } from '@bugsnag/react-native-performance' import { NavigationContainer, createNavigationContainerRef } from '@react-navigation/native' import type { ParamListBase } from '@react-navigation/native' import { createNativeStackNavigator } from '@react-navigation/native-stack' @@ -20,7 +20,7 @@ afterEach(() => { describe('createNavigationContainer', () => { it('creates a navigation span when the route changes', () => { const spanFactory = new MockSpanFactory() - const BugsnagNavigationContainer = createNavigationContainer(NavigationContainer, spanFactory) + const BugsnagNavigationContainer = createNavigationContainer(NavigationContainer, spanFactory as unknown as ReactNativeSpanFactory) render( @@ -44,7 +44,7 @@ describe('createNavigationContainer', () => { it('forwards the provided ref to the NavigationContainer', () => { const navigationRef = createNavigationContainerRef() const spanFactory = new MockSpanFactory() - const BugsnagNavigationContainer = createNavigationContainer(NavigationContainer, spanFactory) + const BugsnagNavigationContainer = createNavigationContainer(NavigationContainer, spanFactory as unknown as ReactNativeSpanFactory) render( diff --git a/packages/plugin-react-navigation/test/navigation-context.test.tsx b/packages/plugin-react-navigation/test/navigation-context.test.tsx index 589ace701..950b4ed9c 100644 --- a/packages/plugin-react-navigation/test/navigation-context.test.tsx +++ b/packages/plugin-react-navigation/test/navigation-context.test.tsx @@ -1,6 +1,6 @@ import type { SpanFactory } from '@bugsnag/core-performance' import { MockSpanFactory } from '@bugsnag/js-performance-test-utilities' -import type { ReactNativeConfiguration } from '@bugsnag/react-native-performance' +import type { ReactNativeConfiguration, ReactNativeSpanFactory } from '@bugsnag/react-native-performance' import { fireEvent, render, screen } from '@testing-library/react-native' import React, { useContext } from 'react' import { Button, View } from 'react-native' @@ -189,7 +189,7 @@ const App = ({ spanFactory }: AppProps) => { const [currentRoute, setCurrentRoute] = React.useState('initial-route') return ( - +