Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove shared mocks package. #601

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/mocks.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/react-native-detox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ on:
- 'packages/shared/common/**'
- 'packages/shared/sdk-client/**'
- 'packages/sdk/react-native/**'
- 'packages/shared/mocks/**'

jobs:
detox-android:
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "@launchdarkly/js-core",
"workspaces": [
"packages/shared/common",
"packages/shared/mocks",
"packages/shared/sdk-client",
"packages/shared/sdk-server",
"packages/shared/sdk-server-edge",
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@launchdarkly/private-js-mocks": "0.0.1",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.0.2",
Expand Down
12 changes: 2 additions & 10 deletions packages/sdk/cloudflare/jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
"version": "2.5.14",
"exports": "./src/index.ts",
"publish": {
"include": [
"LICENSE",
"README.md",
"package.json",
"jsr.json",
"src/**/*.ts"
],
"exclude": [
"src/**/*.test.ts"
]
"include": ["LICENSE", "README.md", "package.json", "jsr.json", "src/**/*.ts"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated lint change.

"exclude": ["src/**/*.test.ts"]
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { type EventName } from '@launchdarkly/js-client-sdk-common';
import { createLogger } from '@launchdarkly/private-js-mocks';
import { type EventName, LDLogger } from '@launchdarkly/js-client-sdk-common';

import EventSource, {
backoff,
jitter,
} from '../../../src/fromExternal/react-native-sse/EventSource';

let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

describe('EventSource', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"base64-js": "^1.5.1"
},
"devDependencies": {
"@launchdarkly/private-js-mocks": "0.0.1",
"@testing-library/react": "^14.1.2",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/jest": "^29.5.11",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { integrations } from '@launchdarkly/js-server-sdk-common';
import { createLogger } from '@launchdarkly/private-js-mocks';
import { integrations, LDLogger } from '@launchdarkly/js-server-sdk-common';

import { Context, LDClient } from '../src';
import LDClientNode from '../src/LDClientNode';

let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

describe('given an LDClient with test data', () => {
let client: LDClient;
let td: integrations.TestData;
Expand Down
12 changes: 8 additions & 4 deletions packages/sdk/server-node/__tests__/LDClientNode.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { LDContext } from '@launchdarkly/js-server-sdk-common';
import { createLogger } from '@launchdarkly/private-js-mocks';
import { LDContext, LDLogger } from '@launchdarkly/js-server-sdk-common';

import { init } from '../src';

let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

it('fires ready event in offline mode', (done) => {
Expand Down
13 changes: 8 additions & 5 deletions packages/sdk/server-node/__tests__/LDClientNode.tls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import {
TestHttpServer,
} from 'launchdarkly-js-test-helpers';

import { createLogger } from '@launchdarkly/private-js-mocks';

import { LDClient } from '../src';
import { LDClient, LDLogger } from '../src';
import LDClientNode from '../src/LDClientNode';

let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

describe('When using a TLS connection', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/server-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"launchdarkly-eventsource": "2.0.3"
},
"devDependencies": {
"@launchdarkly/private-js-mocks": "0.0.1",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Context, subsystem } from '@common';
import { subsystem } from '../src/api';
import Context from '../src/Context';

export default class ContextDeduplicator implements subsystem.LDContextDeduplicator {
flushInterval?: number | undefined = 0.1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { PlatformData, SdkData } from '@common';

import { setupCrypto } from './crypto';
import { PlatformData, SdkData } from '../src/api';
import { setupCrypto } from './setupCrypto';

const setupInfo = () => ({
platformData: jest.fn(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createBasicPlatform } from '@launchdarkly/private-js-mocks';

import DiagnosticsManager from './DiagnosticsManager';
import DiagnosticsManager from '../../../src/internal/diagnostics/DiagnosticsManager';
import { createBasicPlatform } from '../../createBasicPlatform';

describe('given a diagnostics manager', () => {
const dateNowString = '2023-08-10';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {
ContextDeduplicator,
createBasicPlatform,
createLogger,
} from '@launchdarkly/private-js-mocks';

import { LDContextCommon, LDMultiKindContext } from '../../../src/api/context';
import { LDLogger } from '../../../src/api/logging/LDLogger';
import { LDContextDeduplicator, LDDeliveryStatus, LDEventType } from '../../../src/api/subsystem';
import Context from '../../../src/Context';
import { EventProcessor, InputIdentifyEvent } from '../../../src/internal';
Expand All @@ -13,13 +8,20 @@ import shouldSample from '../../../src/internal/events/sampling';
import BasicLogger from '../../../src/logging/BasicLogger';
import format from '../../../src/logging/format';
import ClientContext from '../../../src/options/ClientContext';
import ContextDeduplicator from '../../contextDeduplicator';
import { createBasicPlatform } from '../../createBasicPlatform';

let mockPlatform: ReturnType<typeof createBasicPlatform>;
let clientContext: ClientContext;
let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

beforeEach(() => {
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
mockPlatform = createBasicPlatform();
clientContext = {
basicConfiguration: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { createBasicPlatform } from '@launchdarkly/private-js-mocks';

import { Info, PlatformData, SdkData } from '../../api';
import { LDDeliveryStatus, LDEventSenderResult, LDEventType } from '../../api/subsystem';
import { ApplicationTags, ClientContext } from '../../options';
import EventSender from './EventSender';
import { Info, PlatformData, SdkData } from '../../../src/api';
import { LDDeliveryStatus, LDEventSenderResult, LDEventType } from '../../../src/api/subsystem';
import EventSender from '../../../src/internal/events/EventSender';
import { ApplicationTags, ClientContext } from '../../../src/options';
import { createBasicPlatform } from '../../createBasicPlatform';

let mockPlatform: ReturnType<typeof createBasicPlatform>;

function runWithTimers<T>(fn: () => Promise<T>) {
const promise = fn();
return jest.runAllTimersAsync().then(() => promise);
}

beforeEach(() => {
mockPlatform = createBasicPlatform();
});

jest.mock('../../utils', () => {
const actual = jest.requireActual('../../utils');
return { ...actual, sleep: jest.fn() };
});

const basicConfig = {
tags: new ApplicationTags({ application: { id: 'testApplication1', version: '1.0.0' } }),
serviceEndpoints: {
Expand Down Expand Up @@ -120,9 +119,8 @@ describe('given an event sender', () => {
},
);

eventSenderResult = await eventSender.sendEventData(
LDEventType.AnalyticsEvents,
testEventData1,
eventSenderResult = await runWithTimers(() =>
eventSender.sendEventData(LDEventType.AnalyticsEvents, testEventData1),
);
});

Expand All @@ -142,9 +140,8 @@ describe('given an event sender', () => {

it('includes the payload', async () => {
const { status: status1 } = eventSenderResult;
const { status: status2 } = await eventSender.sendEventData(
LDEventType.DiagnosticEvent,
testEventData2,
const { status: status2 } = await runWithTimers(() =>
eventSender.sendEventData(LDEventType.DiagnosticEvent, testEventData2),
);

expect(status1).toEqual(LDDeliveryStatus.Succeeded);
Expand All @@ -168,7 +165,9 @@ describe('given an event sender', () => {

it('sends a unique payload for analytics events', async () => {
// send the same request again to assert unique uuids
await eventSender.sendEventData(LDEventType.AnalyticsEvents, testEventData1);
await runWithTimers(() =>
eventSender.sendEventData(LDEventType.AnalyticsEvents, testEventData1),
);

expect(mockFetch).toHaveBeenCalledTimes(2);
expect(mockFetch).toHaveBeenNthCalledWith(
Expand All @@ -190,9 +189,8 @@ describe('given an event sender', () => {
describe.each([400, 408, 429, 503])('given recoverable errors', (responseStatusCode) => {
beforeEach(async () => {
setupMockFetch(responseStatusCode);
eventSenderResult = await eventSender.sendEventData(
LDEventType.AnalyticsEvents,
testEventData1,
eventSenderResult = await runWithTimers(() =>
eventSender.sendEventData(LDEventType.AnalyticsEvents, testEventData1),
);
});

Expand All @@ -210,9 +208,8 @@ describe('given an event sender', () => {

it('given a result for too large of a payload', async () => {
setupMockFetch(413);
eventSenderResult = await eventSender.sendEventData(
LDEventType.AnalyticsEvents,
testEventData1,
eventSenderResult = await runWithTimers(() =>
eventSender.sendEventData(LDEventType.AnalyticsEvents, testEventData1),
);

const errorMessage = `Received error 413 for event posting - giving up permanently`;
Expand All @@ -228,9 +225,8 @@ describe('given an event sender', () => {
describe.each([401, 403])('given unrecoverable errors', (responseStatusCode) => {
beforeEach(async () => {
setupMockFetch(responseStatusCode);
eventSenderResult = await eventSender.sendEventData(
LDEventType.AnalyticsEvents,
testEventData1,
eventSenderResult = await runWithTimers(() =>
eventSender.sendEventData(LDEventType.AnalyticsEvents, testEventData1),
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { createBasicPlatform, createLogger } from '@launchdarkly/private-js-mocks';
import { EventName, Info, LDLogger, ProcessStreamResponse } from '../../../src/api';
import { LDStreamProcessor } from '../../../src/api/subsystem';
import { DataSourceErrorKind } from '../../../src/datasource/DataSourceErrorKinds';
import { LDStreamingError } from '../../../src/datasource/errors';
import { DiagnosticsManager } from '../../../src/internal/diagnostics';
import StreamingProcessor from '../../../src/internal/stream/StreamingProcessor';
import { defaultHeaders } from '../../../src/utils';
import { createBasicPlatform } from '../../createBasicPlatform';

import { EventName, Info, LDLogger, ProcessStreamResponse } from '../../api';
import { LDStreamProcessor } from '../../api/subsystem';
import { DataSourceErrorKind } from '../../datasource/DataSourceErrorKinds';
import { LDStreamingError } from '../../datasource/errors';
import { defaultHeaders } from '../../utils';
import { DiagnosticsManager } from '../diagnostics';
import StreamingProcessor from './StreamingProcessor';

let logger: ReturnType<typeof createLogger>;
let logger: LDLogger;

const serviceEndpoints = {
events: '',
Expand Down Expand Up @@ -44,7 +43,12 @@ let basicPlatform: any;

beforeEach(() => {
basicPlatform = createBasicPlatform();
logger = createLogger();
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
});

const createMockEventSource = (streamUri: string = '', options: any = {}) => ({
Expand Down
Loading
Loading