Skip to content

Commit

Permalink
ci: jest runs on individual packages
Browse files Browse the repository at this point in the history
  • Loading branch information
oscb committed Dec 7, 2023
1 parent d9ad83f commit eba6846
Show file tree
Hide file tree
Showing 52 changed files with 127 additions and 440 deletions.
5 changes: 5 additions & 0 deletions examples/AnalyticsReactNativeExample/react-native.config.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions examples/E2E/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const { rootMap } = require('./workspace') // Load the linked data

module.exports = {
project: {
ios: {
automaticPodsInstallation: true,
}
},
dependencies: {
...rootMap
},
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/__tests__/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/client.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/__tests__/internal/fetchSettings.test.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/__tests__/internal/trackDeepLinks.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/methods/alias.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTestClient } from '../../test-helpers';
import { EventType, SegmentEvent } from '../../types';
import { createTestClient } from '../__helpers__/setupSegmentClient';

jest.mock('uuid');

Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/__tests__/methods/flush.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/__tests__/methods/group.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/methods/identify.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTestClient } from '../../test-helpers';
import { EventType, SegmentEvent } from '../../types';
import { createTestClient } from '../__helpers__/setupSegmentClient';

describe('methods #identify', () => {
const initialUserInfo = {
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/__tests__/methods/process.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/__tests__/methods/screen.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/__tests__/methods/track.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/__tests__/timeline.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/plugins/__tests__/SegmentDestination.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = () =>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = () =>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = () =>
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/plugins/__tests__/consent/unmapped.test.ts
Original file line number Diff line number Diff line change
@@ -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 = () =>
Expand Down
11 changes: 4 additions & 7 deletions packages/core/src/plugins/__tests__/consent/utils.ts
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/storage/__tests__/sovranStorage.test.ts
Original file line number Diff line number Diff line change
@@ -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: <T extends object>(initialState: T) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/test-helpers/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DestinationPlugin } from '../../plugin';
import { DestinationPlugin } from '../plugin';

export const getMockDestinationPlugin = () => {
const destinationPlugin = new DestinationPlugin();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from '../../logger';
import { Logger } from '../logger';

export const getMockLogger = () => {
const logger = new Logger();
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Timeline } from '../../timeline';
import { Timeline } from '../timeline';
import { getMockDestinationPlugin } from './mockDestinationPlugin';

export const getMockTimeline = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../../tsconfig",
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "lib/typescript",
"rootDir": ".",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/plugin-adjust/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SegmentAdjustSettings } from '../../../core/src/types';
import type { SegmentAdjustSettings } from '@segment/analytics-react-native';

export const mappedCustomEventToken = (
eventName: string,
Expand Down
Loading

0 comments on commit eba6846

Please sign in to comment.