diff --git a/examples/AnalyticsReactNativeExample/react-native.config.js b/examples/AnalyticsReactNativeExample/react-native.config.js index 2bf3c6fe7..e56fe7b93 100644 --- a/examples/AnalyticsReactNativeExample/react-native.config.js +++ b/examples/AnalyticsReactNativeExample/react-native.config.js @@ -1,6 +1,11 @@ const { rootMap } = require('./workspace') // Load the linked data module.exports = { + project: { + ios: { + automaticPodsInstallation: true, + } + }, dependencies: { // Local packages need to be referenced here to be linked to the app // This is not required in a standalone production app diff --git a/examples/E2E/react-native.config.js b/examples/E2E/react-native.config.js index a7eb5f0a3..849119b2f 100644 --- a/examples/E2E/react-native.config.js +++ b/examples/E2E/react-native.config.js @@ -1,6 +1,11 @@ const { rootMap } = require('./workspace') // Load the linked data module.exports = { + project: { + ios: { + automaticPodsInstallation: true, + } + }, dependencies: { ...rootMap }, diff --git a/packages/core/src/__tests__/analytics.test.ts b/packages/core/src/__tests__/analytics.test.ts index 8be3536fc..f2bd05959 100644 --- a/packages/core/src/__tests__/analytics.test.ts +++ b/packages/core/src/__tests__/analytics.test.ts @@ -3,8 +3,7 @@ import { AppState } from 'react-native'; import { SegmentClient } from '../analytics'; import { ErrorType, SegmentError } from '../errors'; import { CountFlushPolicy, TimerFlushPolicy } from '../flushPolicies'; -import { getMockLogger } from './__helpers__/mockLogger'; -import { MockSegmentStore } from './__helpers__/mockSegmentStore'; +import { getMockLogger, MockSegmentStore } from '../test-helpers'; jest.mock('../api'); diff --git a/packages/core/src/__tests__/client.test.ts b/packages/core/src/__tests__/client.test.ts index a1c02af57..2916bf9d4 100644 --- a/packages/core/src/__tests__/client.test.ts +++ b/packages/core/src/__tests__/client.test.ts @@ -1,6 +1,6 @@ import type { SegmentClient } from '../analytics'; import { createClient } from '../client'; -import { getMockLogger } from './__helpers__/mockLogger'; +import { getMockLogger } from '../test-helpers'; jest.mock('uuid'); diff --git a/packages/core/src/__tests__/internal/checkInstalledVersion.test.ts b/packages/core/src/__tests__/internal/checkInstalledVersion.test.ts index cf6c589a1..3fae590de 100644 --- a/packages/core/src/__tests__/internal/checkInstalledVersion.test.ts +++ b/packages/core/src/__tests__/internal/checkInstalledVersion.test.ts @@ -1,9 +1,9 @@ +import deepmerge from 'deepmerge'; + import { SegmentClient } from '../../analytics'; -import { getMockLogger } from '../__helpers__/mockLogger'; import * as context from '../../context'; -import { MockSegmentStore } from '../__helpers__/mockSegmentStore'; +import { getMockLogger, MockSegmentStore } from '../../test-helpers'; import { Context, EventType } from '../../types'; -import deepmerge from 'deepmerge'; jest.mock('uuid'); diff --git a/packages/core/src/__tests__/internal/fetchSettings.test.ts b/packages/core/src/__tests__/internal/fetchSettings.test.ts index 1f385840a..643d2f53e 100644 --- a/packages/core/src/__tests__/internal/fetchSettings.test.ts +++ b/packages/core/src/__tests__/internal/fetchSettings.test.ts @@ -1,8 +1,7 @@ -import { getMockLogger } from '../__helpers__/mockLogger'; import { SegmentClient } from '../../analytics'; -import { MockSegmentStore } from '../__helpers__/mockSegmentStore'; -import { SEGMENT_DESTINATION_KEY } from '../../plugins/SegmentDestination'; import { settingsCDN } from '../../constants'; +import { SEGMENT_DESTINATION_KEY } from '../../plugins/SegmentDestination'; +import { getMockLogger, MockSegmentStore } from '../../test-helpers'; describe('internal #getSettings', () => { const defaultIntegrationSettings = { diff --git a/packages/core/src/__tests__/internal/handleAppStateChange.test.ts b/packages/core/src/__tests__/internal/handleAppStateChange.test.ts index 06bdfc0f2..d1ec68b44 100644 --- a/packages/core/src/__tests__/internal/handleAppStateChange.test.ts +++ b/packages/core/src/__tests__/internal/handleAppStateChange.test.ts @@ -1,10 +1,11 @@ import { AppState, AppStateStatus } from 'react-native'; -import type { SegmentClient } from '../../analytics'; -import type { UtilityPlugin } from '../../plugin'; + +import { createTestClient } from '../../test-helpers'; import { EventType, SegmentEvent } from '../../types'; -import type { MockSegmentStore } from '../__helpers__/mockSegmentStore'; -import { createTestClient } from '../__helpers__/setupSegmentClient'; +import type { SegmentClient } from '../../analytics'; +import type { UtilityPlugin } from '../../plugin'; +import type { MockSegmentStore } from '../../test-helpers'; jest.mock('uuid'); jest.mock('../../context'); jest.mock('react-native'); diff --git a/packages/core/src/__tests__/internal/trackDeepLinks.test.ts b/packages/core/src/__tests__/internal/trackDeepLinks.test.ts index 705fede5c..34290056d 100644 --- a/packages/core/src/__tests__/internal/trackDeepLinks.test.ts +++ b/packages/core/src/__tests__/internal/trackDeepLinks.test.ts @@ -1,11 +1,12 @@ -import { SegmentClient } from '../../analytics'; -import { getMockLogger } from '../__helpers__/mockLogger'; import * as ReactNative from 'react-native'; -import { EventType } from '../../types'; + +import { SegmentClient } from '../../analytics'; import { createMockStoreGetter, + getMockLogger, MockSegmentStore, -} from '../__helpers__/mockSegmentStore'; +} from '../../test-helpers'; +import { EventType } from '../../types'; jest.mock('uuid'); diff --git a/packages/core/src/__tests__/methods/alias.test.ts b/packages/core/src/__tests__/methods/alias.test.ts index 18802ce57..f1f03be2d 100644 --- a/packages/core/src/__tests__/methods/alias.test.ts +++ b/packages/core/src/__tests__/methods/alias.test.ts @@ -1,5 +1,5 @@ +import { createTestClient } from '../../test-helpers'; import { EventType, SegmentEvent } from '../../types'; -import { createTestClient } from '../__helpers__/setupSegmentClient'; jest.mock('uuid'); diff --git a/packages/core/src/__tests__/methods/flush.test.ts b/packages/core/src/__tests__/methods/flush.test.ts index addfce5b2..7e1acc2bc 100644 --- a/packages/core/src/__tests__/methods/flush.test.ts +++ b/packages/core/src/__tests__/methods/flush.test.ts @@ -1,10 +1,12 @@ import { SegmentClient } from '../../analytics'; -import { getMockLogger } from '../__helpers__/mockLogger'; +import { + getMockLogger, + getMockTimeline, + MockSegmentStore, +} from '../../test-helpers'; import { PluginType } from '../../types'; -import { getMockTimeline } from '../__helpers__/mockTimeline'; -import type { DestinationPlugin } from '../../plugin'; -import { MockSegmentStore } from '../__helpers__/mockSegmentStore'; +import type { DestinationPlugin } from '../../plugin'; jest.mock('react-native'); jest.mock('uuid'); diff --git a/packages/core/src/__tests__/methods/group.test.ts b/packages/core/src/__tests__/methods/group.test.ts index a4006c807..d8d8984a8 100644 --- a/packages/core/src/__tests__/methods/group.test.ts +++ b/packages/core/src/__tests__/methods/group.test.ts @@ -1,6 +1,5 @@ import { SegmentClient } from '../../analytics'; -import { getMockLogger } from '../__helpers__/mockLogger'; -import { MockSegmentStore } from '../__helpers__/mockSegmentStore'; +import { getMockLogger, MockSegmentStore } from '../../test-helpers'; jest.mock('uuid'); diff --git a/packages/core/src/__tests__/methods/identify.test.ts b/packages/core/src/__tests__/methods/identify.test.ts index b3e5c85fe..c61f2be17 100644 --- a/packages/core/src/__tests__/methods/identify.test.ts +++ b/packages/core/src/__tests__/methods/identify.test.ts @@ -1,5 +1,5 @@ +import { createTestClient } from '../../test-helpers'; import { EventType, SegmentEvent } from '../../types'; -import { createTestClient } from '../__helpers__/setupSegmentClient'; describe('methods #identify', () => { const initialUserInfo = { diff --git a/packages/core/src/__tests__/methods/process.test.ts b/packages/core/src/__tests__/methods/process.test.ts index 852977f99..ba99ca2e2 100644 --- a/packages/core/src/__tests__/methods/process.test.ts +++ b/packages/core/src/__tests__/methods/process.test.ts @@ -1,9 +1,7 @@ import { SegmentClient } from '../../analytics'; +import { getMockLogger, MockSegmentStore } from '../../test-helpers'; import { EventType, SegmentEvent } from '../../types'; -import { getMockLogger } from '../__helpers__/mockLogger'; -import { MockSegmentStore } from '../__helpers__/mockSegmentStore'; - jest.mock('uuid'); jest diff --git a/packages/core/src/__tests__/methods/screen.test.ts b/packages/core/src/__tests__/methods/screen.test.ts index c2e44dce7..1f3cf1bdb 100644 --- a/packages/core/src/__tests__/methods/screen.test.ts +++ b/packages/core/src/__tests__/methods/screen.test.ts @@ -1,6 +1,5 @@ import { SegmentClient } from '../../analytics'; -import { getMockLogger } from '../__helpers__/mockLogger'; -import { MockSegmentStore } from '../__helpers__/mockSegmentStore'; +import { getMockLogger, MockSegmentStore } from '../../test-helpers'; jest.mock('uuid'); diff --git a/packages/core/src/__tests__/methods/track.test.ts b/packages/core/src/__tests__/methods/track.test.ts index 8d285f474..dea47988f 100644 --- a/packages/core/src/__tests__/methods/track.test.ts +++ b/packages/core/src/__tests__/methods/track.test.ts @@ -1,9 +1,7 @@ import { SegmentClient } from '../../analytics'; +import { getMockLogger, MockSegmentStore } from '../../test-helpers'; import { EventType } from '../../types'; -import { getMockLogger } from '../__helpers__/mockLogger'; -import { MockSegmentStore } from '../__helpers__/mockSegmentStore'; - jest.mock('uuid'); jest diff --git a/packages/core/src/__tests__/timeline.test.ts b/packages/core/src/__tests__/timeline.test.ts index 4569f2263..bb905d245 100644 --- a/packages/core/src/__tests__/timeline.test.ts +++ b/packages/core/src/__tests__/timeline.test.ts @@ -1,9 +1,8 @@ import { SegmentClient } from '../analytics'; import { Plugin } from '../plugin'; +import { getMockLogger, MockSegmentStore } from '../test-helpers'; import { Timeline } from '../timeline'; import { EventType, PluginType, SegmentEvent, TrackEventType } from '../types'; -import { getMockLogger } from './__helpers__/mockLogger'; -import { MockSegmentStore } from './__helpers__/mockSegmentStore'; jest.mock('uuid'); diff --git a/packages/core/src/plugins/__tests__/QueueFlushingPlugin.test.ts b/packages/core/src/plugins/__tests__/QueueFlushingPlugin.test.ts index 4e83a9ee4..81eabac7b 100644 --- a/packages/core/src/plugins/__tests__/QueueFlushingPlugin.test.ts +++ b/packages/core/src/plugins/__tests__/QueueFlushingPlugin.test.ts @@ -1,9 +1,10 @@ -import { MockEventStore } from '../../__tests__/__helpers__/mockEventStore'; -import type { SegmentClient } from '../../analytics'; -import { QueueFlushingPlugin } from '../QueueFlushingPlugin'; -import { EventType, SegmentEvent } from '../../types'; import { createStore } from '@segment/sovran-react-native'; +import { MockEventStore } from '../../test-helpers'; +import { EventType, SegmentEvent } from '../../types'; +import { QueueFlushingPlugin } from '../QueueFlushingPlugin'; + +import type { SegmentClient } from '../../analytics'; jest.mock('@segment/sovran-react-native'); describe('QueueFlushingPlugin', () => { diff --git a/packages/core/src/plugins/__tests__/SegmentDestination.test.ts b/packages/core/src/plugins/__tests__/SegmentDestination.test.ts index b959a66ea..11f0a49f9 100644 --- a/packages/core/src/plugins/__tests__/SegmentDestination.test.ts +++ b/packages/core/src/plugins/__tests__/SegmentDestination.test.ts @@ -1,6 +1,11 @@ import { SegmentClient } from '../../analytics'; import * as api from '../../api'; import { defaultApiHost } from '../../constants'; +import { + createMockStoreGetter, + getMockLogger, + MockSegmentStore, +} from '../../test-helpers'; import { Config, EventType, @@ -9,14 +14,9 @@ import { TrackEventType, UpdateType, } from '../../types'; -import { getMockLogger } from '../../__tests__/__helpers__/mockLogger'; -import { - createMockStoreGetter, - MockSegmentStore, -} from '../../__tests__/__helpers__/mockSegmentStore'; import { - SegmentDestination, SEGMENT_DESTINATION_KEY, + SegmentDestination, } from '../SegmentDestination'; jest.mock('uuid'); diff --git a/packages/core/src/plugins/__tests__/consent/consentNotEnabledAtSegment.test.ts b/packages/core/src/plugins/__tests__/consent/consentNotEnabledAtSegment.test.ts index 7fcf3ef43..4d194b22f 100644 --- a/packages/core/src/plugins/__tests__/consent/consentNotEnabledAtSegment.test.ts +++ b/packages/core/src/plugins/__tests__/consent/consentNotEnabledAtSegment.test.ts @@ -1,12 +1,11 @@ -import { createTestClient } from '../../../__tests__/__helpers__/setupSegmentClient'; +import { createTestClient } from '../../../test-helpers'; import { ConsentPlugin } from '../../ConsentPlugin'; - +import consentNotEnabledAtSegment from './mockSettings/ConsentNotEnabledAtSegment.json'; import { - setupTestDestinations, createConsentProvider, createSegmentWatcher, + setupTestDestinations, } from './utils'; -import consentNotEnabledAtSegment from './mockSettings/ConsentNotEnabledAtSegment.json'; describe('Consent not enabled at Segment', () => { const createClient = () => diff --git a/packages/core/src/plugins/__tests__/consent/destinationMultipleCategories.test.ts b/packages/core/src/plugins/__tests__/consent/destinationMultipleCategories.test.ts index 6b3aa87a4..48fb24cb9 100644 --- a/packages/core/src/plugins/__tests__/consent/destinationMultipleCategories.test.ts +++ b/packages/core/src/plugins/__tests__/consent/destinationMultipleCategories.test.ts @@ -1,12 +1,11 @@ -import { createTestClient } from '../../../__tests__/__helpers__/setupSegmentClient'; +import { createTestClient } from '../../../test-helpers'; import { ConsentPlugin } from '../../ConsentPlugin'; - +import destinationsMultipleCategories from './mockSettings/DestinationsMultipleCategories.json'; import { - setupTestDestinations, createConsentProvider, createSegmentWatcher, + setupTestDestinations, } from './utils'; -import destinationsMultipleCategories from './mockSettings/DestinationsMultipleCategories.json'; describe('Destinations multiple categories', () => { const createClient = () => diff --git a/packages/core/src/plugins/__tests__/consent/noUnmapped.test.ts b/packages/core/src/plugins/__tests__/consent/noUnmapped.test.ts index 17f86fb8c..8bfbc6688 100644 --- a/packages/core/src/plugins/__tests__/consent/noUnmapped.test.ts +++ b/packages/core/src/plugins/__tests__/consent/noUnmapped.test.ts @@ -1,8 +1,7 @@ -import { createTestClient } from '../../../__tests__/__helpers__/setupSegmentClient'; +import { createTestClient } from '../../../test-helpers'; import { ConsentPlugin } from '../../ConsentPlugin'; - -import { setupTestDestinations, createConsentProvider } from './utils'; import noUnmappedDestinations from './mockSettings/NoUnmappedDestinations.json'; +import { createConsentProvider, setupTestDestinations } from './utils'; describe('No unmapped destinations', () => { const createClient = () => diff --git a/packages/core/src/plugins/__tests__/consent/unmapped.test.ts b/packages/core/src/plugins/__tests__/consent/unmapped.test.ts index 1678e77a5..8aa4074cb 100644 --- a/packages/core/src/plugins/__tests__/consent/unmapped.test.ts +++ b/packages/core/src/plugins/__tests__/consent/unmapped.test.ts @@ -1,12 +1,11 @@ -import { createTestClient } from '../../../__tests__/__helpers__/setupSegmentClient'; +import { createTestClient } from '../../../test-helpers'; import { ConsentPlugin } from '../../ConsentPlugin'; - +import unmappedDestinations from './mockSettings/UnmappedDestinations.json'; import { - setupTestDestinations, createConsentProvider, createSegmentWatcher, + setupTestDestinations, } from './utils'; -import unmappedDestinations from './mockSettings/UnmappedDestinations.json'; describe('Unmapped destinations', () => { const createClient = () => diff --git a/packages/core/src/plugins/__tests__/consent/utils.ts b/packages/core/src/plugins/__tests__/consent/utils.ts index c3997968e..5b58f98aa 100644 --- a/packages/core/src/plugins/__tests__/consent/utils.ts +++ b/packages/core/src/plugins/__tests__/consent/utils.ts @@ -1,10 +1,7 @@ -import { - CategoryConsentStatusProvider, - DestinationPlugin, - PluginType, - SegmentClient, - UtilityPlugin, -} from '@segment/analytics-react-native'; +import { SegmentClient } from '../../..'; +import { UtilityPlugin, DestinationPlugin } from '../../../plugin'; +import { PluginType } from '../../../types'; +import { CategoryConsentStatusProvider } from '../../ConsentPlugin'; import { SegmentDestination } from '../../SegmentDestination'; beforeEach(() => { diff --git a/packages/core/src/storage/__tests__/sovranStorage.test.ts b/packages/core/src/storage/__tests__/sovranStorage.test.ts index 3a3e9712d..d49bba29f 100644 --- a/packages/core/src/storage/__tests__/sovranStorage.test.ts +++ b/packages/core/src/storage/__tests__/sovranStorage.test.ts @@ -1,9 +1,10 @@ -import type { Persistor } from '@segment/sovran-react-native'; import deepmerge from 'deepmerge'; -import type { Context, DeepPartial } from '../../types'; -import { createCallbackManager as mockCreateCallbackManager } from '../../__tests__/__helpers__/utils'; + +import { createCallbackManager as mockCreateCallbackManager } from '../../test-helpers/utils'; import { SovranStorage } from '../sovranStorage'; +import type { Persistor } from '@segment/sovran-react-native'; +import type { Context, DeepPartial } from '../../types'; jest.mock('@segment/sovran-react-native', () => ({ registerBridgeStore: jest.fn(), createStore: (initialState: T) => { diff --git a/packages/core/src/test-helpers/index.ts b/packages/core/src/test-helpers/index.ts new file mode 100644 index 000000000..d8a6aff04 --- /dev/null +++ b/packages/core/src/test-helpers/index.ts @@ -0,0 +1,7 @@ +export * from './mockDestinationPlugin'; +export * from './mockEventStore'; +export * from './mockLogger'; +export * from './mockSegmentStore'; +export * from './mockTimeline'; +export * from './setupSegmentClient'; +export * from './utils'; diff --git a/packages/core/src/__tests__/__helpers__/mockDestinationPlugin.ts b/packages/core/src/test-helpers/mockDestinationPlugin.ts similarity index 80% rename from packages/core/src/__tests__/__helpers__/mockDestinationPlugin.ts rename to packages/core/src/test-helpers/mockDestinationPlugin.ts index 376ad5795..5110cb741 100644 --- a/packages/core/src/__tests__/__helpers__/mockDestinationPlugin.ts +++ b/packages/core/src/test-helpers/mockDestinationPlugin.ts @@ -1,4 +1,4 @@ -import { DestinationPlugin } from '../../plugin'; +import { DestinationPlugin } from '../plugin'; export const getMockDestinationPlugin = () => { const destinationPlugin = new DestinationPlugin(); diff --git a/packages/core/src/__tests__/__helpers__/mockEventStore.ts b/packages/core/src/test-helpers/mockEventStore.ts similarity index 90% rename from packages/core/src/__tests__/__helpers__/mockEventStore.ts rename to packages/core/src/test-helpers/mockEventStore.ts index 084d09ea4..00bf20f1f 100644 --- a/packages/core/src/__tests__/__helpers__/mockEventStore.ts +++ b/packages/core/src/test-helpers/mockEventStore.ts @@ -1,6 +1,5 @@ -import type { SegmentEvent } from '../../types'; +import type { SegmentEvent } from '../types'; import { createMockStoreGetter } from './mockSegmentStore'; -// import { createMockStoreGetter } from './mockSegmentStore'; import { createCallbackManager } from './utils'; export class MockEventStore { diff --git a/packages/core/src/__tests__/__helpers__/mockLogger.ts b/packages/core/src/test-helpers/mockLogger.ts similarity index 83% rename from packages/core/src/__tests__/__helpers__/mockLogger.ts rename to packages/core/src/test-helpers/mockLogger.ts index 785e5ec1d..0c63a56f8 100644 --- a/packages/core/src/__tests__/__helpers__/mockLogger.ts +++ b/packages/core/src/test-helpers/mockLogger.ts @@ -1,4 +1,4 @@ -import { Logger } from '../../logger'; +import { Logger } from '../logger'; export const getMockLogger = () => { const logger = new Logger(); diff --git a/packages/core/src/__tests__/__helpers__/mockSegmentStore.ts b/packages/core/src/test-helpers/mockSegmentStore.ts similarity index 96% rename from packages/core/src/__tests__/__helpers__/mockSegmentStore.ts rename to packages/core/src/test-helpers/mockSegmentStore.ts index 94624e210..5273fe9b4 100644 --- a/packages/core/src/__tests__/__helpers__/mockSegmentStore.ts +++ b/packages/core/src/test-helpers/mockSegmentStore.ts @@ -1,11 +1,11 @@ -import { SEGMENT_DESTINATION_KEY } from '../../plugins/SegmentDestination'; +import { SEGMENT_DESTINATION_KEY } from '../plugins/SegmentDestination'; import type { DeepLinkData, Dictionary, Settable, Storage, Watchable, -} from '../../storage'; +} from '../storage'; import type { Context, DeepPartial, @@ -14,9 +14,9 @@ import type { RoutingRule, SegmentAPIIntegrations, UserInfoState, -} from '../../types'; +} from '../types'; import { createCallbackManager } from './utils'; -import { createGetter } from '../../storage/helpers'; +import { createGetter } from '../storage/helpers'; export type StoreData = { isReady: boolean; diff --git a/packages/core/src/__tests__/__helpers__/mockTimeline.ts b/packages/core/src/test-helpers/mockTimeline.ts similarity index 85% rename from packages/core/src/__tests__/__helpers__/mockTimeline.ts rename to packages/core/src/test-helpers/mockTimeline.ts index 4abad2e57..b1996ee1b 100644 --- a/packages/core/src/__tests__/__helpers__/mockTimeline.ts +++ b/packages/core/src/test-helpers/mockTimeline.ts @@ -1,4 +1,4 @@ -import { Timeline } from '../../timeline'; +import { Timeline } from '../timeline'; import { getMockDestinationPlugin } from './mockDestinationPlugin'; export const getMockTimeline = () => { diff --git a/packages/core/src/__tests__/__helpers__/setupSegmentClient.ts b/packages/core/src/test-helpers/setupSegmentClient.ts similarity index 88% rename from packages/core/src/__tests__/__helpers__/setupSegmentClient.ts rename to packages/core/src/test-helpers/setupSegmentClient.ts index f918fdb8b..6eb00db1a 100644 --- a/packages/core/src/__tests__/__helpers__/setupSegmentClient.ts +++ b/packages/core/src/test-helpers/setupSegmentClient.ts @@ -1,6 +1,6 @@ -import { SegmentClient } from '../../analytics'; -import { UtilityPlugin } from '../../plugin'; -import { Config, PluginType, SegmentEvent } from '../../types'; +import { SegmentClient } from '../analytics'; +import { UtilityPlugin } from '../plugin'; +import { Config, PluginType, SegmentEvent } from '../types'; import { getMockLogger } from './mockLogger'; import { MockSegmentStore, StoreData } from './mockSegmentStore'; diff --git a/packages/core/src/__tests__/__helpers__/utils.ts b/packages/core/src/test-helpers/utils.ts similarity index 100% rename from packages/core/src/__tests__/__helpers__/utils.ts rename to packages/core/src/test-helpers/utils.ts diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index fb8dbb41f..d6c29ccc4 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../tsconfig", + "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "lib/typescript", "rootDir": ".", diff --git a/packages/plugins/plugin-adjust/src/util.ts b/packages/plugins/plugin-adjust/src/util.ts index bbe6a77b8..78853bab2 100644 --- a/packages/plugins/plugin-adjust/src/util.ts +++ b/packages/plugins/plugin-adjust/src/util.ts @@ -1,4 +1,4 @@ -import type { SegmentAdjustSettings } from '../../../core/src/types'; +import type { SegmentAdjustSettings } from '@segment/analytics-react-native'; export const mappedCustomEventToken = ( eventName: string, diff --git a/packages/plugins/plugin-clevertap/src/__tests__/ClevertapPlugin.test.ts b/packages/plugins/plugin-clevertap/src/__tests__/ClevertapPlugin.test.ts index 4f33a2abc..e6bd9218c 100644 --- a/packages/plugins/plugin-clevertap/src/__tests__/ClevertapPlugin.test.ts +++ b/packages/plugins/plugin-clevertap/src/__tests__/ClevertapPlugin.test.ts @@ -1,14 +1,17 @@ +import { SegmentClient } from '@segment/analytics-react-native'; +import { + getMockLogger, + MockSegmentStore, +} from '@segment/analytics-react-native/src/test-helpers'; +import CleverTap from 'clevertap-react-native'; + +import { ClevertapPlugin } from '../ClevertapPlugin'; + import type { IdentifyEventType, TrackEventType, ScreenEventType, } from '@segment/analytics-react-native'; -import { ClevertapPlugin } from '../ClevertapPlugin'; -import CleverTap from 'clevertap-react-native'; -import { MockSegmentStore } from '@segment/analytics-rn-shared/__helpers__/mockSegmentStore'; -import { SegmentClient } from '@segment/analytics-react-native'; -import { getMockLogger } from '@segment/analytics-rn-shared/__helpers__/mockLogger'; - jest.mock('clevertap-react-native'); describe('ClevertapPlugin ', () => { diff --git a/packages/plugins/plugin-destination-filters/src/__tests__/DestinationFilters.test.ts b/packages/plugins/plugin-destination-filters/src/__tests__/DestinationFilters.test.ts index 498165709..dcc3810a2 100644 --- a/packages/plugins/plugin-destination-filters/src/__tests__/DestinationFilters.test.ts +++ b/packages/plugins/plugin-destination-filters/src/__tests__/DestinationFilters.test.ts @@ -1,9 +1,9 @@ +import { createTestClient } from '@segment/analytics-react-native/src/test-helpers'; import { DestinationFiltersPlugin } from '../DestinationFilters'; import { DestinationPlugin, SegmentClient, } from '@segment/analytics-react-native'; -import { createTestClient } from '@segment/analytics-rn-shared/__helpers__/setupSegmentClient'; describe('DestinationFiltersPlugin', () => { const { store, client: c } = createTestClient(); diff --git a/packages/plugins/plugin-device-token/src/methods/___tests__/DeviceTokenPlugin.test.ts b/packages/plugins/plugin-device-token/src/methods/___tests__/DeviceTokenPlugin.test.ts index e872370c0..297dec594 100644 --- a/packages/plugins/plugin-device-token/src/methods/___tests__/DeviceTokenPlugin.test.ts +++ b/packages/plugins/plugin-device-token/src/methods/___tests__/DeviceTokenPlugin.test.ts @@ -1,8 +1,11 @@ -import { DeviceTokenPlugin } from '../../DeviceTokenPlugin'; -import { Platform } from 'react-native'; -import { MockSegmentStore } from '@segment/analytics-rn-shared/__helpers__/mockSegmentStore'; -import { getMockLogger } from '@segment/analytics-rn-shared/__helpers__/mockLogger'; import { SegmentClient } from '@segment/analytics-react-native'; +import { + getMockLogger, + MockSegmentStore, +} from '@segment/analytics-react-native/src/test-helpers'; +import { Platform } from 'react-native'; + +import { DeviceTokenPlugin } from '../../DeviceTokenPlugin'; const mockRequestPermission = jest.fn().mockReturnValue(1); const mockGetAPNSToken = jest.fn().mockReturnValue('device-token'); diff --git a/packages/plugins/plugin-mixpanel/src/methods/__tests__/MixpanelPlugin.test.ts b/packages/plugins/plugin-mixpanel/src/methods/__tests__/MixpanelPlugin.test.ts index 384badd02..d99554560 100644 --- a/packages/plugins/plugin-mixpanel/src/methods/__tests__/MixpanelPlugin.test.ts +++ b/packages/plugins/plugin-mixpanel/src/methods/__tests__/MixpanelPlugin.test.ts @@ -1,6 +1,8 @@ import { SegmentClient, UpdateType } from '@segment/analytics-react-native'; -import { getMockLogger } from '@segment/analytics-rn-shared/__helpers__/mockLogger'; -import { MockSegmentStore } from '@segment/analytics-rn-shared/__helpers__/mockSegmentStore'; +import { + getMockLogger, + MockSegmentStore, +} from '@segment/analytics-react-native/src/test-helpers'; import { EU_SERVER, MixpanelPlugin } from '../../MixpanelPlugin'; import { initMock, setServerMock } from '../__mocks__/mixpanel-react-native'; diff --git a/packages/plugins/plugin-mixpanel/src/methods/__tests__/alias.test.ts b/packages/plugins/plugin-mixpanel/src/methods/__tests__/alias.test.ts index 1439365e7..19d9f879d 100644 --- a/packages/plugins/plugin-mixpanel/src/methods/__tests__/alias.test.ts +++ b/packages/plugins/plugin-mixpanel/src/methods/__tests__/alias.test.ts @@ -1,13 +1,14 @@ import { SegmentClient } from '@segment/analytics-react-native'; -import { getMockLogger } from '@segment/analytics-rn-shared/__helpers__/mockLogger'; -import { MockSegmentStore } from '@segment/analytics-rn-shared/__helpers__/mockSegmentStore'; +import { + getMockLogger, + MockSegmentStore, +} from '@segment/analytics-react-native/src/test-helpers'; import { MixpanelPlugin } from '../../MixpanelPlugin'; import { Mixpanel } from '../__mocks__/mixpanel-react-native'; import alias from '../alias'; import type { AliasEventType } from '@segment/analytics-react-native'; - jest.mock('mixpanel-react-native'); describe('#alias', () => { diff --git a/packages/plugins/plugin-onetrust/src/__tests__/OneTrust.test.ts b/packages/plugins/plugin-onetrust/src/__tests__/OneTrust.test.ts index 6b74f5569..136d80dee 100644 --- a/packages/plugins/plugin-onetrust/src/__tests__/OneTrust.test.ts +++ b/packages/plugins/plugin-onetrust/src/__tests__/OneTrust.test.ts @@ -4,11 +4,12 @@ import { PluginType, SegmentClient, } from '@segment/analytics-react-native'; -import { OneTrustPlugin } from '../OneTrust'; +import { createTestClient } from '@segment/analytics-react-native/src/test-helpers'; import onChange from 'on-change'; -import type { OTPublishersNativeSDK } from '../OTProvider'; -import { createTestClient } from '@segment/analytics-rn-shared/__helpers__/setupSegmentClient'; +import { OneTrustPlugin } from '../OneTrust'; + +import type { OTPublishersNativeSDK } from '../OTProvider'; class MockDestination extends DestinationPlugin { track = jest.fn(); diff --git a/packages/shared/__helpers__/mockDestinationPlugin.ts b/packages/shared/__helpers__/mockDestinationPlugin.ts deleted file mode 100644 index 30b692aa4..000000000 --- a/packages/shared/__helpers__/mockDestinationPlugin.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { DestinationPlugin } from '../../core/src/plugin'; - -export const getMockDestinationPlugin: () => DestinationPlugin = () => { - const destinationPlugin = new DestinationPlugin(); - destinationPlugin.flush = jest.fn() as jest.MockedFunction; - return destinationPlugin; -}; diff --git a/packages/shared/__helpers__/mockEventStore.ts b/packages/shared/__helpers__/mockEventStore.ts deleted file mode 100644 index da6e18e2d..000000000 --- a/packages/shared/__helpers__/mockEventStore.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { SegmentEvent } from '../../core/src/types'; -import { createMockStoreGetter } from './mockSegmentStore'; -import { createCallbackManager } from './utils'; -import { getStateFunc } from '../../core/lib/typescript/src/storage/types'; - -export class MockEventStore { - private initialData: SegmentEvent[] = []; - private events: SegmentEvent[] = []; - - private callbackManager = createCallbackManager<{ events: SegmentEvent[] }>(); - - constructor(initialData?: SegmentEvent[]) { - this.events = [...(initialData ?? [])]; - this.initialData = JSON.parse( - JSON.stringify(initialData ?? []) - ) as SegmentEvent[]; - } - - reset = () => { - this.events = JSON.parse( - JSON.stringify(this.initialData) - ) as SegmentEvent[]; - }; - - getState: getStateFunc<{ - events: SegmentEvent[]; - }> = createMockStoreGetter(() => ({ events: this.events })); - - subscribe = (callback: (value: { events: SegmentEvent[] }) => void) => - this.callbackManager.register(callback); - - dispatch = ( - callback: (value: { events: SegmentEvent[] }) => { events: SegmentEvent[] } - ) => { - this.events = callback({ events: this.events }).events; - this.callbackManager.run({ events: this.events }); - }; -} diff --git a/packages/shared/__helpers__/mockLogger.ts b/packages/shared/__helpers__/mockLogger.ts deleted file mode 100644 index 3d458689f..000000000 --- a/packages/shared/__helpers__/mockLogger.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Logger } from '../../core/src/logger'; - -export const getMockLogger = () => { - const logger = new Logger(); - logger.disable(); - logger.info = jest.fn(); - logger.warn = jest.fn(); - logger.error = jest.fn(); - return logger; -}; diff --git a/packages/shared/__helpers__/mockSegmentStore.ts b/packages/shared/__helpers__/mockSegmentStore.ts deleted file mode 100644 index b2f67e04d..000000000 --- a/packages/shared/__helpers__/mockSegmentStore.ts +++ /dev/null @@ -1,172 +0,0 @@ -import { SEGMENT_DESTINATION_KEY } from '../../core/src/plugins/SegmentDestination'; -import type { - DeepLinkData, - Dictionary, - Settable, - Storage, - Watchable, -} from '../../core/src/storage'; -import type { - Context, - DeepPartial, - DestinationFilters, - IntegrationSettings, - RoutingRule, - SegmentAPIIntegrations, - UserInfoState, -} from '../../core/src/types'; -import { createCallbackManager } from './utils'; -import { createGetter } from '../../core/src/storage/helpers'; - -export type StoreData = { - isReady: boolean; - context?: DeepPartial; - settings: SegmentAPIIntegrations; - filters: DestinationFilters; - userInfo: UserInfoState; - deepLinkData: DeepLinkData; -}; - -const INITIAL_VALUES: StoreData = { - isReady: true, - context: undefined, - settings: { - [SEGMENT_DESTINATION_KEY]: {}, - }, - filters: {}, - userInfo: { - anonymousId: 'anonymousId', - userId: undefined, - traits: undefined, - }, - deepLinkData: { - referring_application: '', - url: '', - }, -}; - -export function createMockStoreGetter(fn: () => T) { - return createGetter(fn, () => { - return new Promise((resolve) => { - resolve(fn()); - }); - }); -} - -export class MockSegmentStore implements Storage { - private data: StoreData; - private initialData: StoreData; - - reset = () => { - this.data = JSON.parse(JSON.stringify(this.initialData)) as StoreData; - }; - - constructor(initialData?: Partial) { - this.data = { ...INITIAL_VALUES, ...initialData }; - this.initialData = JSON.parse( - JSON.stringify({ ...INITIAL_VALUES, ...initialData }) - ) as StoreData; - } - - private callbacks = { - context: createCallbackManager | undefined>(), - settings: createCallbackManager(), - filters: createCallbackManager(), - userInfo: createCallbackManager(), - deepLinkData: createCallbackManager(), - }; - - readonly isReady = { - get: createMockStoreGetter(() => { - return this.data.isReady; - }), - onChange: (_callback: (value: boolean) => void) => { - return () => { - return; - }; - }, - }; - - readonly context: Watchable | undefined> & - Settable> = { - get: createMockStoreGetter(() => ({ ...this.data.context })), - onChange: (callback: (value?: DeepPartial) => void) => - this.callbacks.context.register(callback), - set: (value) => { - this.data.context = - value instanceof Function - ? value(this.data.context ?? {}) - : { ...value }; - this.callbacks.context.run(this.data.context); - return this.data.context; - }, - }; - - readonly settings: Watchable & - Settable & - Dictionary = { - get: createMockStoreGetter(() => this.data.settings), - onChange: (callback: (value?: SegmentAPIIntegrations) => void) => - this.callbacks.settings.register(callback), - set: (value) => { - this.data.settings = - value instanceof Function - ? value(this.data.settings ?? {}) - : { ...value }; - this.callbacks.settings.run(this.data.settings); - return this.data.settings; - }, - add: (key: string, value: IntegrationSettings) => { - this.data.settings[key] = value; - this.callbacks.settings.run(this.data.settings); - return Promise.resolve(this.data.settings); - }, - }; - - readonly filters: Watchable & - Settable & - Dictionary = { - get: createMockStoreGetter(() => this.data.filters), - onChange: (callback: (value?: DestinationFilters) => void) => - this.callbacks.filters.register(callback), - set: (value) => { - this.data.filters = - value instanceof Function - ? value(this.data.filters ?? {}) - : { ...value }; - this.callbacks.filters.run(this.data.filters); - return this.data.filters; - }, - add: (key: string, value: RoutingRule) => { - this.data.filters[key] = value; - this.callbacks.filters.run(this.data.filters); - return Promise.resolve(this.data.filters); - }, - }; - - readonly userInfo: Watchable & Settable = { - get: createMockStoreGetter(() => this.data.userInfo), - onChange: (callback: (value: UserInfoState) => void) => - this.callbacks.userInfo.register(callback), - set: (value) => { - this.data.userInfo = - value instanceof Function - ? value(this.data.userInfo ?? {}) - : { ...value }; - this.callbacks.userInfo.run(this.data.userInfo); - return this.data.userInfo; - }, - }; - - readonly deepLinkData = { - get: createMockStoreGetter(() => { - return this.data.deepLinkData; - }), - set: (value: DeepLinkData) => { - this.data.deepLinkData = value; - this.callbacks.deepLinkData.run(value); - }, - onChange: (callback: (value: DeepLinkData) => void) => - this.callbacks.deepLinkData.register(callback), - }; -} diff --git a/packages/shared/__helpers__/mockTimeline.ts b/packages/shared/__helpers__/mockTimeline.ts deleted file mode 100644 index 48eb26c14..000000000 --- a/packages/shared/__helpers__/mockTimeline.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Timeline } from '../../core/src/timeline'; -import { getMockDestinationPlugin } from './mockDestinationPlugin'; -import { DestinationPlugin } from '../../core/src/plugin'; - -export const getMockTimeline = () => { - const timeline = new Timeline(); - const destinationPlugin: DestinationPlugin = getMockDestinationPlugin(); - timeline.add(destinationPlugin); - return timeline; -}; diff --git a/packages/shared/__helpers__/setup.ts b/packages/shared/__helpers__/setup.ts deleted file mode 100644 index a30b696bb..000000000 --- a/packages/shared/__helpers__/setup.ts +++ /dev/null @@ -1,8 +0,0 @@ -// This is our basic setup for all JS Tests -jest.mock('react-native'); -jest.mock('uuid'); -jest.mock('react-native-get-random-values'); -jest.mock('@react-native-async-storage/async-storage', () => - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - require('@react-native-async-storage/async-storage/jest/async-storage-mock') -); diff --git a/packages/shared/__helpers__/setupSegmentClient.ts b/packages/shared/__helpers__/setupSegmentClient.ts deleted file mode 100644 index fdfb8b46e..000000000 --- a/packages/shared/__helpers__/setupSegmentClient.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { SegmentClient } from '../../core/src/analytics'; -import { UtilityPlugin } from '../../core/src/plugin'; -import { Config, PluginType, SegmentEvent } from '../../core/src/types'; -import { getMockLogger } from './mockLogger'; -import { MockSegmentStore, StoreData } from './mockSegmentStore'; - -jest - .spyOn(Date.prototype, 'toISOString') - .mockReturnValue('2010-01-01T00:00:00.000Z'); - -jest.spyOn(console, 'warn'); - -export const createTestClient = ( - storeData?: Partial, - config?: Partial -) => { - const store = new MockSegmentStore({ - isReady: true, - ...storeData, - }); - - const clientArgs = { - config: { - writeKey: 'mock-write-key', - autoAddSegmentDestination: false, - flushInterval: 0, - ...config, - }, - logger: getMockLogger(), - store: store, - }; - - const client = new SegmentClient(clientArgs); - class ObservablePlugin extends UtilityPlugin { - type = PluginType.after; - - execute = async ( - event: SegmentEvent - ): Promise => { - await super.execute(event); - return event; - }; - } - - const mockPlugin = new ObservablePlugin(); - jest.spyOn(mockPlugin, 'execute'); - - client.add({ plugin: mockPlugin }); - - return { - client, - store, - plugin: mockPlugin as UtilityPlugin, - expectEvent: (event: Partial) => { - return expect(mockPlugin.execute).toHaveBeenCalledWith( - expect.objectContaining(event) - ); - }, - }; -}; diff --git a/packages/shared/__helpers__/utils.ts b/packages/shared/__helpers__/utils.ts deleted file mode 100644 index 70019230a..000000000 --- a/packages/shared/__helpers__/utils.ts +++ /dev/null @@ -1,23 +0,0 @@ -export const createCallbackManager = () => { - type Callback = (value: V) => R; - const callbacks: Callback[] = []; - - const deregister = (callback: Callback) => { - callbacks.splice(callbacks.indexOf(callback), 1); - }; - - const register = (callback: Callback) => { - callbacks.push(callback); - return () => { - deregister(callback); - }; - }; - - const run = (value: V) => { - for (const callback of [...callbacks]) { - callback(value); - } - }; - - return { register, deregister, run }; -}; diff --git a/packages/shared/jest.config.base.js b/packages/shared/jest.config.base.js index 468a5be63..b9b8e7d16 100644 --- a/packages/shared/jest.config.base.js +++ b/packages/shared/jest.config.base.js @@ -3,9 +3,9 @@ const { pathsToModuleNameMapper } = require('ts-jest'); const { compilerOptions } = require('../../tsconfig'); -Object.entries(compilerOptions.paths).map(([key, value]) => { - compilerOptions.paths[key] = value.map((p) => path.resolve(__dirname, '../../', p)); -}) +// Object.entries(compilerOptions.paths).map(([key, value]) => { +// compilerOptions.paths[key] = value.map((p) => path.resolve(__dirname, '../../', p)); +// }) module.exports = { preset: 'react-native', @@ -27,17 +27,14 @@ module.exports = { ], roots:[ path.resolve(__dirname, '__mocks__'), // Include shared mocks - path.resolve(__dirname, '__helpers__'), // Include shared mocks '' // Include the source code of the current package ], setupFiles: [ - path.resolve(__dirname, '__helpers__/setup.ts') + path.resolve(__dirname, 'src/setup.ts') ], moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], modulePaths: [compilerOptions.baseUrl], // Not required to module map as the core packages are referenced as devDependencies inside the workspace, // but keeping this around in case future packages need manual mapping - // moduleNameMapper: { - // ...pathsToModuleNameMapper( compilerOptions.paths) - // } + // moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '/' }), }; diff --git a/packages/core/src/__tests__/__helpers__/setup.ts b/packages/shared/src/setup.ts similarity index 100% rename from packages/core/src/__tests__/__helpers__/setup.ts rename to packages/shared/src/setup.ts diff --git a/tsconfig.json b/tsconfig.json index 8e1cf1c7a..b9e69072b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -31,6 +31,9 @@ }, "include": ["types.d.ts", "packages/**/*"], "exclude": [ + "node_modules", + "lib", + "**/lib/**/*", "**/*.test.ts", "**/__mocks__/**/*", "**/__tests__/**/*",