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: Standardize test organization. #565

Merged
merged 1 commit into from
Sep 5, 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
12 changes: 9 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ To install project dependencies, from the project root directory:
yarn
```

### Testing
### Build

To run all unit tests:
To build all projects, from the root directory:

```
yarn test
yarn build
```

### Testing

Unit tests should be implemented in a `__tests__` folder in the root of the package. The directory structure inside of `__tests__` should mirror that of the source directory.

Each package has its own testing requirements and tests should be only ran for single projects.

To run the SDK contract test suite (see [`contract-tests/README.md`](./contract-tests/README.md)):
The SDK contract test suite will run the Node.js Server version of the SDK.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EdgeProvider, init } from '../index';
import { EdgeProvider, init } from '../src/index';
import * as testData from './testData.json';

const sdkKey = 'test-sdk-key';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EdgeKV } from '../../edgekv/edgekv';
import EdgeKVProvider from '../../edgekv/edgeKVProvider';
import { EdgeKV } from '../../src/edgekv/edgekv';
import EdgeKVProvider from '../../src/edgekv/edgeKVProvider';

jest.mock('../../edgekv/edgekv', () => ({
jest.mock('../../src/edgekv/edgekv', () => ({
EdgeKV: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import EdgeKVProvider from '../edgekv/edgeKVProvider';
import { init as initWithEdgeKV, LDClient, LDContext } from '../index';
import EdgeKVProvider from '../src/edgekv/edgeKVProvider';
import { init as initWithEdgeKV, LDClient, LDContext } from '../src/index';
import * as testData from './testData.json';

jest.mock('../edgekv/edgekv', () => ({
jest.mock('../src/edgekv/edgekv', () => ({
EdgeKV: jest.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Miniflare } from 'miniflare';

import { LDClient, LDContext } from '@launchdarkly/js-server-sdk-common-edge';

import { init } from './index';
import { init } from '../src/index';
import * as allFlagsSegments from './testData.json';

const mf = new Miniflare({
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.12",
"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"],
"exclude": ["src/**/*.test.ts"]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AutoEnvAttributes, LDLogger } from '@launchdarkly/js-client-sdk-common';

import ReactNativeLDClient from './ReactNativeLDClient';
import ReactNativeLDClient from '../src/ReactNativeLDClient';

it('uses custom storage', async () => {
// This test just validates that the custom storage instance is being called.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AutoEnvAttributes, LDLogger, Response } from '@launchdarkly/js-client-sdk-common';

import createPlatform from './platform';
import PlatformCrypto from './platform/crypto';
import PlatformEncoding from './platform/PlatformEncoding';
import PlatformInfo from './platform/PlatformInfo';
import PlatformStorage from './platform/PlatformStorage';
import ReactNativeLDClient from './ReactNativeLDClient';
import createPlatform from '../src/platform';
import PlatformCrypto from '../src/platform/crypto';
import PlatformEncoding from '../src/platform/PlatformEncoding';
import PlatformInfo from '../src/platform/PlatformInfo';
import PlatformStorage from '../src/platform/PlatformStorage';
import ReactNativeLDClient from '../src/ReactNativeLDClient';

function mockResponse(value: string, statusCode: number) {
const response: Response = {
Expand Down Expand Up @@ -34,7 +34,7 @@ function mockFetch(value: string, statusCode: number = 200) {
return f;
}

jest.mock('./platform', () => ({
jest.mock('../src/platform', () => ({
__esModule: true,
default: jest.fn((logger: LDLogger) => ({
crypto: new PlatformCrypto(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { type EventName } from '@launchdarkly/js-client-sdk-common';
import { createLogger } from '@launchdarkly/private-js-mocks';

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

let logger: ReturnType<typeof createLogger>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LDLogger } from '@launchdarkly/js-client-sdk-common';

import validateOptions, { filterToBaseOptions } from './options';
import { RNStorage } from './RNOptions';
import validateOptions, { filterToBaseOptions } from '../src/options';
import { RNStorage } from '../src/RNOptions';

it('logs no warnings when all configuration is valid', () => {
const logger: LDLogger = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ConnectionManager,
NetworkState,
StateDetector,
} from './ConnectionManager';
} from '../../src/platform/ConnectionManager';

function mockDestination(): ConnectionDestination {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PlatformHasher from './PlatformHasher';
import PlatformHasher from '../../../src/platform/crypto/PlatformHasher';

/**
* The links below are different from js-sha256 and are useful to verify the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { render } from '@testing-library/react';

import { AutoEnvAttributes, LDContext, LDOptions } from '@launchdarkly/js-client-sdk-common';

import { useLDClient } from '../hooks';
import ReactNativeLDClient from '../ReactNativeLDClient';
import LDProvider from './LDProvider';
import setupListeners from './setupListeners';
import { useLDClient } from '../../src/hooks';
import LDProvider from '../../src/provider/LDProvider';
import setupListeners from '../../src/provider/setupListeners';
import ReactNativeLDClient from '../../src/ReactNativeLDClient';

jest.mock('../ReactNativeLDClient');
jest.mock('./setupListeners');
jest.mock('../../src/ReactNativeLDClient');
jest.mock('../../src/provider/setupListeners');

const TestApp = () => {
const ldClient = useLDClient();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AutoEnvAttributes } from '@launchdarkly/js-client-sdk-common';

import ReactNativeLDClient from '../ReactNativeLDClient';
import setupListeners from './setupListeners';
import setupListeners from '../../src/provider/setupListeners';
import ReactNativeLDClient from '../../src/ReactNativeLDClient';

import resetAllMocks = jest.resetAllMocks;

jest.mock('../ReactNativeLDClient');
jest.mock('../../src/ReactNativeLDClient');

describe('setupListeners', () => {
let ldc: ReactNativeLDClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import createPlatformInfo from './createPlatformInfo';
import createPlatformInfo from '../src/createPlatformInfo';

const packageJson = require('../package.json');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LDClient, LDContext } from '@launchdarkly/js-server-sdk-common-edge';

import { init } from './index';
import { init } from '../src/index';
import mockEdgeConfigClient from './utils/mockEdgeConfigClient';
import * as testData from './utils/testData.json';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AsyncStoreFacade, LDFeatureStore } from '@launchdarkly/js-server-sdk-common';

import { EdgeFeatureStore, EdgeProvider } from '../../featureStore';
import { EdgeFeatureStore, EdgeProvider } from '../../src/featureStore';
import * as testData from '../testData.json';

describe('EdgeFeatureStore', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EdgeProvider, init, LDLogger, LDMultiKindContext, LDSingleKindContext } from '../..';
import { EdgeProvider, init, LDLogger, LDMultiKindContext, LDSingleKindContext } from '../dist';
import * as testData from './testData.json';

const createClient = (sdkKey: string, mockLogger: LDLogger, mockEdgeProvider: EdgeProvider) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import createPlatformInfo from '../../../platform/info';
import createPlatformInfo from '../../../src/platform/info';

const packageJson = require('../../../../package.json');
const packageJson = require('../../../package.json');

describe('Akamai Platform Info', () => {
const { name, version } = packageJson;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventSourceInitDict } from '@launchdarkly/js-server-sdk-common';

import EdgeRequests from '../../platform/requests';
import EdgeRequests from '../../src/platform/requests';

const TEXT_RESPONSE = '';
const JSON_RESPONSE = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createCallbacks } from '../../utils/createCallbacks';
import { createCallbacks } from '../../src/utils/createCallbacks';

describe('create callback', () => {
it('creates valid callbacks', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createOptions, defaultOptions } from '../../utils/createOptions';
import { createOptions, defaultOptions } from '../../src/utils/createOptions';

describe('create options', () => {
it('returns default options', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BasicLogger } from '@launchdarkly/js-server-sdk-common';

import { EdgeFeatureStore } from '../../featureStore';
import { LDOptionsInternal, validateOptions } from '../../utils/validateOptions';
import { EdgeFeatureStore } from '../../src/featureStore';
import { LDOptionsInternal, validateOptions } from '../../src/utils/validateOptions';

const SDK_KEY = 'test-key';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
setupMockStreamingProcessor,
} from '@launchdarkly/private-js-mocks';

import LDClientImpl from '../src/LDClientImpl';
import { Flags } from '../src/types';
import * as mockResponseJson from './evaluation/mockResponse.json';
import LDClientImpl from './LDClientImpl';
import { Flags } from './types';

type InputCustomEvent = internal.InputCustomEvent;
type InputIdentifyEvent = internal.InputIdentifyEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
setupMockStreamingProcessor,
} from '@launchdarkly/private-js-mocks';

import { toMulti } from './context/addAutoEnv';
import { toMulti } from '../src/context/addAutoEnv';
import LDClientImpl from '../src/LDClientImpl';
import LDEmitter from '../src/LDEmitter';
import { DeleteFlag, Flags, PatchFlag } from '../src/types';
import * as mockResponseJson from './evaluation/mockResponse.json';
import LDClientImpl from './LDClientImpl';
import LDEmitter from './LDEmitter';
import { DeleteFlag, Flags, PatchFlag } from './types';

let mockPlatform: ReturnType<typeof createBasicPlatform>;
let logger: ReturnType<typeof createLogger>;
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('sdk-client storage', () => {
test('not emitting change event when changed keys is empty', async () => {
let LDClientImplTestNoChange;
jest.isolateModules(async () => {
LDClientImplTestNoChange = jest.requireActual('./LDClientImpl').default;
LDClientImplTestNoChange = jest.requireActual('../src/LDClientImpl').default;
ldc = new LDClientImplTestNoChange(testSdkKey, AutoEnvAttributes.Enabled, mockPlatform, {
logger,
sendEvents: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
setupMockStreamingProcessor,
} from '@launchdarkly/private-js-mocks';

import LDClientImpl from '../src/LDClientImpl';
import { Flags } from '../src/types';
import * as mockResponseJson from './evaluation/mockResponse.json';
import LDClientImpl from './LDClientImpl';
import { Flags } from './types';

jest.mock('@launchdarkly/js-sdk-common', () => {
const actual = jest.requireActual('@launchdarkly/js-sdk-common');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
setupMockStreamingProcessor,
} from '@launchdarkly/private-js-mocks';

import { toMulti } from './context/addAutoEnv';
import { toMulti } from '../src/context/addAutoEnv';
import LDClientImpl from '../src/LDClientImpl';
import { Flags } from '../src/types';
import * as mockResponseJson from './evaluation/mockResponse.json';
import LDClientImpl from './LDClientImpl';
import { Flags } from './types';

let mockPlatform: ReturnType<typeof createBasicPlatform>;
let logger: ReturnType<typeof createLogger>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
setupMockStreamingProcessor,
} from '@launchdarkly/private-js-mocks';

import LDClientImpl from '../src/LDClientImpl';
import { Flags } from '../src/types';
import * as mockResponseJson from './evaluation/mockResponse.json';
import LDClientImpl from './LDClientImpl';
import { Flags } from './types';

let mockPlatform: ReturnType<typeof createBasicPlatform>;
let logger: ReturnType<typeof createLogger>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LDContext, LDLogger } from '@launchdarkly/js-sdk-common';

import LDEmitter from './LDEmitter';
import LDEmitter from '../src/LDEmitter';

describe('LDEmitter', () => {
const error = { type: 'network', message: 'unreachable' };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
import Configuration from './Configuration';
import Configuration from '../../src/configuration/Configuration';

describe('Configuration', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import {
} from '@launchdarkly/js-sdk-common';
import { createBasicPlatform, createLogger } from '@launchdarkly/private-js-mocks';

import Configuration from '../configuration';
import { addApplicationInfo, addAutoEnv, addDeviceInfo, toMulti } from './addAutoEnv';
import Configuration from '../../src/configuration';
import {
addApplicationInfo,
addAutoEnv,
addDeviceInfo,
toMulti,
} from '../../src/context/addAutoEnv';

let mockPlatform: ReturnType<typeof createBasicPlatform>;
let logger: ReturnType<typeof createLogger>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
} from '@launchdarkly/js-sdk-common';
import { createBasicPlatform } from '@launchdarkly/private-js-mocks';

import { ensureKey } from './ensureKey';
import { ensureKey } from '../../src/context/ensureKey';

let mockPlatform: ReturnType<typeof createBasicPlatform>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { secondsToMillis } from '@launchdarkly/js-sdk-common';

import Configuration from '../configuration';
import Configuration from '../../src/configuration';
import createDiagnosticsInitConfig, {
type DiagnosticsInitConfig,
} from './createDiagnosticsInitConfig';
} from '../../src/diagnostics/createDiagnosticsInitConfig';

describe('createDiagnosticsInitConfig', () => {
let initConfig: DiagnosticsInitConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ContextIndex from './ContextIndex';
import ContextIndex from '../../src/flag-manager/ContextIndex';

describe('ContextIndex tests', () => {
test('notice adds to index', async () => {
Expand Down
Loading
Loading