From 4c7a90ca53c3af704e2f6a8cf8c1a8659562eaab Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 29 Nov 2023 16:34:27 -0500 Subject: [PATCH 1/8] Refactor test files for easier readability --- .gitignore | 3 +- package.json | 2 +- rollup.test.config.js | 2 +- src/mockBatchCreator.ts | 2 + src/sdkRuntimeModels.ts | 2 + .../rollup.CBT.config.js | 2 +- test/src/_index.ts | 31 ++++++++++ test/src/_test.setup.ts | 40 +++++++++++++ test/src/tests-main.js | 56 ------------------- test/test-index.js | 5 -- 10 files changed, 80 insertions(+), 65 deletions(-) create mode 100644 test/src/_index.ts create mode 100644 test/src/_test.setup.ts delete mode 100644 test/src/tests-main.js delete mode 100644 test/test-index.js diff --git a/.gitignore b/.gitignore index 6eb9c47c..adfe36ad 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ test/stub/test-stub-bundle.js test/integrations/requirejs/test-requirejs-bundle.js browserstack.err local.log -test/cross-browser-testing/CBT-tests-es5.js \ No newline at end of file +test/cross-browser-testing/CBT-tests-es5.js +test/cross-browser-testing/CBT-tests.js \ No newline at end of file diff --git a/package.json b/package.json index 9cd400f5..f45751d7 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "repository": "https://github.com/mParticle/mparticle-web-sdk", "scripts": { "build": "cross-env ENVIRONMENT=prod BUILDALL=true rollup --config rollup.config.js", - "build:cbt": "rollup --config test/cross-browser-testing/rollup.CBT.config.js && rm test/cross-browser-testing/CBT-tests.js", + "build:cbt": "rollup --config test/cross-browser-testing/rollup.CBT.config.js -w", "build:dev": "cross-env ENVIRONMENT=dev BUILD=iife rollup --config rollup.config.js", "build:iife": "cross-env ENVIRONMENT=prod BUILD=iife rollup --config rollup.config.js", "build:npm": "cross-env ENVIRONMENT=prod BUILD=cjs rollup --config rollup.config.js", diff --git a/rollup.test.config.js b/rollup.test.config.js index 380f1e3c..453e4766 100644 --- a/rollup.test.config.js +++ b/rollup.test.config.js @@ -10,7 +10,7 @@ const extensions = ['.js', '.ts']; const builds = { main: { - input: 'test/src/tests-main.js', + input: 'test/src/_index.ts', output: { file: 'test/test-bundle.js', format: 'iife', diff --git a/src/mockBatchCreator.ts b/src/mockBatchCreator.ts index f07bd2d4..7adc48b8 100644 --- a/src/mockBatchCreator.ts +++ b/src/mockBatchCreator.ts @@ -39,6 +39,8 @@ export default class _BatchValidator { _NativeSdkHelpers: null, _Persistence: null, _preInit: null, + _instances: {}, + _isTestEnv: true, Consent: null, _ServerModel: null, _SessionManager: null, diff --git a/src/sdkRuntimeModels.ts b/src/sdkRuntimeModels.ts index 083afb20..79d12397 100644 --- a/src/sdkRuntimeModels.ts +++ b/src/sdkRuntimeModels.ts @@ -151,6 +151,8 @@ export interface MParticleWebSDK { _NativeSdkHelpers: any; // TODO: Set up API _Persistence: IPersistence; _preInit: any; // TODO: Set up API + _instances: Dictionary; + _isTestEnv: boolean; _resetForTests( MPConfig?: SDKInitConfig, keepPersistence?: boolean, diff --git a/test/cross-browser-testing/rollup.CBT.config.js b/test/cross-browser-testing/rollup.CBT.config.js index 626f39a6..3dee13a7 100644 --- a/test/cross-browser-testing/rollup.CBT.config.js +++ b/test/cross-browser-testing/rollup.CBT.config.js @@ -8,7 +8,7 @@ import json from '@rollup/plugin-json'; export default [ { - input: 'test/src/tests-main.js', + input: 'test/src/_index.ts', output: { file: 'test/cross-browser-testing/CBT-tests.js', format: 'umd', diff --git a/test/src/_index.ts b/test/src/_index.ts new file mode 100644 index 00000000..e9942d05 --- /dev/null +++ b/test/src/_index.ts @@ -0,0 +1,31 @@ +// +import './_test.setup'; + +// +import './tests-core-sdk'; +import './tests-batchUploader'; +import './tests-beaconUpload'; +import './tests-kit-blocking'; +import './tests-persistence'; +import './tests-forwarders'; +import './tests-helpers'; +import './tests-identity'; +import './tests-event-logging'; +import './tests-eCommerce'; +import './tests-cookie-syncing'; +import './tests-identities-attributes'; +import './tests-native-sdk'; +import './tests-consent'; +import './tests-serverModel'; +import './tests-mockBatchCreator'; +import './tests-mParticleUser'; +import './tests-self-hosting-specific'; +import './tests-runtimeToBatchEventsDTO'; +import './tests-apiClient'; +import './tests-mparticle-instance-manager'; +import './tests-queue-public-methods'; +import './tests-validators'; +import './tests-utils'; +import './tests-session-manager'; +import './tests-store'; +import './tests-config-api-client'; diff --git a/test/src/_test.setup.ts b/test/src/_test.setup.ts new file mode 100644 index 00000000..2611ea48 --- /dev/null +++ b/test/src/_test.setup.ts @@ -0,0 +1,40 @@ +import { MPConfig, workspaceToken } from './config'; +import { MParticleWebSDK } from '../../src/sdkRuntimeModels'; + +declare global { + interface Window { + mParticle: MParticleWebSDK; + } +} + +var userApi = null; + +window.mParticle._isTestEnv = true; + +beforeEach(function() { + // mocha can't clean up after itself, so this lets + // tests mock the current user and restores in between runs. + if (!userApi) { + userApi = window.mParticle.getInstance().Identity.getCurrentUser; + } else { + window.mParticle.getInstance().Identity.getCurrentUser = userApi; + } + // @ts-ignore + window.mParticle = window.mParticle || {}; + // @ts-ignore + window.mParticle.config = { + workspaceToken: workspaceToken, + logLevel: 'none', + kitConfigs: [], + requestConfig: false, + isDevelopmentMode: false, + flags: { + eventBatchingIntervalMillis: 0, + } + }; + + // This is to tell the resetPersistence method that we are in a test environment + // It should probably be refactored to be included as an argument + window.mParticle._resetForTests(MPConfig); + delete window.mParticle._instances['default_instance']; +}); \ No newline at end of file diff --git a/test/src/tests-main.js b/test/src/tests-main.js deleted file mode 100644 index 6f0456f3..00000000 --- a/test/src/tests-main.js +++ /dev/null @@ -1,56 +0,0 @@ -import { MPConfig, workspaceToken } from './config'; - -var userApi = null; - -mParticle._isTestEnv = true; -beforeEach(function() { - //mocha can't clean up after itself, so this lets - //tests mock the current user and restores in between runs. - if (!userApi) { - userApi = window.mParticle.getInstance().Identity.getCurrentUser; - } else { - window.mParticle.getInstance().Identity.getCurrentUser = userApi; - } - window.mParticle = window.mParticle || {}; - window.mParticle.config = { - workspaceToken: workspaceToken, - logLevel: 'none', - kitConfigs: [], - requestConfig: false, - isDevelopmentMode: false, - flags: { - eventBatchingIntervalMillis: 0, - } - }; - - mParticle._resetForTests(MPConfig); - delete mParticle._instances['default_instance']; -}); - -import './tests-core-sdk'; -import './tests-batchUploader'; -import './tests-beaconUpload'; -import './tests-kit-blocking'; -import './tests-persistence'; -import './tests-forwarders'; -import './tests-helpers'; -import './tests-identity'; -import './tests-event-logging'; -import './tests-eCommerce'; -import './tests-cookie-syncing'; -import './tests-identities-attributes'; -import './tests-native-sdk'; -import './tests-consent'; -import './tests-serverModel'; -import './tests-mockBatchCreator.ts'; -import './tests-mParticleUser'; -import './tests-self-hosting-specific'; -import './tests-runtimeToBatchEventsDTO'; -import './tests-apiClient'; -import './tests-mparticle-instance-manager'; -import './tests-queue-public-methods'; -import './tests-validators'; -import './tests-utils'; -import './tests-session-manager'; -import './tests-store'; -import './tests-config-api-client'; diff --git a/test/test-index.js b/test/test-index.js deleted file mode 100644 index 1272ae6b..00000000 --- a/test/test-index.js +++ /dev/null @@ -1,5 +0,0 @@ -window.MockHttpServer = require('./mockhttprequest.js'); -window.Should = require('should'); -window.sinon = require('../node_modules/sinon/lib/sinon.js'); -require('./geomock.js'); -require('./src/tests-main.js'); From 652ca205e661675e016ea4ba716fecadd3dac47d Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 29 Nov 2023 16:36:12 -0500 Subject: [PATCH 2/8] add comments --- test/src/_index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/_index.ts b/test/src/_index.ts index e9942d05..65d06132 100644 --- a/test/src/_index.ts +++ b/test/src/_index.ts @@ -1,7 +1,7 @@ -// +// Import set up logic import './_test.setup'; -// +// Import each test module import './tests-core-sdk'; import './tests-batchUploader'; import './tests-beaconUpload'; From d83d7e7f860c4e4573eef5792587b2c0df6e5f66 Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 29 Nov 2023 16:56:12 -0500 Subject: [PATCH 3/8] Rename files --- rollup.test.config.js | 2 +- test/jest/sideloadedKit.spec.ts | 2 +- test/src/{_index.ts => __test.index.ts} | 2 +- test/src/{config.ts => config/constants.ts} | 2 +- test/src/{_test.setup.ts => config/setup.ts} | 4 ++-- test/src/{ => config}/utils.js | 4 ++-- test/src/tests-apiClient.ts | 2 +- test/src/tests-batchUploader.ts | 6 +++--- test/src/tests-beaconUpload.ts | 4 ++-- test/src/tests-config-api-client.ts | 4 ++-- test/src/tests-consent.ts | 6 +++--- test/src/tests-cookie-syncing.js | 4 ++-- test/src/tests-core-sdk.js | 5 ++--- test/src/tests-eCommerce.js | 4 ++-- test/src/tests-event-logging.js | 4 ++-- test/src/tests-forwarders.js | 5 ++--- test/src/tests-helpers.js | 2 +- test/src/tests-identities-attributes.js | 4 ++-- test/src/tests-identity.js | 4 ++-- test/src/tests-kit-blocking.ts | 6 +++--- test/src/tests-mParticleUser.js | 4 ++-- test/src/tests-mparticle-instance-manager.js | 4 ++-- test/src/tests-native-sdk.js | 4 ++-- test/src/tests-persistence.ts | 4 ++-- test/src/tests-queue-public-methods.js | 2 +- test/src/tests-runtimeToBatchEventsDTO.ts | 4 ++-- test/src/tests-self-hosting-specific.js | 4 ++-- test/src/tests-serverModel.ts | 2 +- test/src/tests-session-manager.ts | 2 +- test/src/tests-store.ts | 4 ++-- 30 files changed, 54 insertions(+), 56 deletions(-) rename test/src/{_index.ts => __test.index.ts} (97%) rename test/src/{config.ts => config/constants.ts} (97%) rename test/src/{_test.setup.ts => config/setup.ts} (90%) rename test/src/{ => config}/utils.js (99%) diff --git a/rollup.test.config.js b/rollup.test.config.js index 453e4766..d5f11801 100644 --- a/rollup.test.config.js +++ b/rollup.test.config.js @@ -10,7 +10,7 @@ const extensions = ['.js', '.ts']; const builds = { main: { - input: 'test/src/_index.ts', + input: 'test/src/__test.index.ts', output: { file: 'test/test-bundle.js', format: 'iife', diff --git a/test/jest/sideloadedKit.spec.ts b/test/jest/sideloadedKit.spec.ts index 0bda032f..5086c70d 100644 --- a/test/jest/sideloadedKit.spec.ts +++ b/test/jest/sideloadedKit.spec.ts @@ -3,7 +3,7 @@ import { IMPSideloadedKitConstructor } from "../../src/sideloadedKit"; import { EventTypeEnum, IdentityType } from "../../src/types.interfaces"; import { UnregisteredKit } from '../../src/forwarders.interfaces'; import { IKitFilterSettings } from '../../src/configAPIClient'; -import { mParticle } from "../src/config"; +import { mParticle } from "../src/config/constants"; const mockKitInstance: UnregisteredKit = { register: function() {} diff --git a/test/src/_index.ts b/test/src/__test.index.ts similarity index 97% rename from test/src/_index.ts rename to test/src/__test.index.ts index 65d06132..d7134b5c 100644 --- a/test/src/_index.ts +++ b/test/src/__test.index.ts @@ -1,5 +1,5 @@ // Import set up logic -import './_test.setup'; +import './config/setup'; // Import each test module import './tests-core-sdk'; diff --git a/test/src/config.ts b/test/src/config/constants.ts similarity index 97% rename from test/src/config.ts rename to test/src/config/constants.ts index 7f4aade4..869e8fb9 100644 --- a/test/src/config.ts +++ b/test/src/config/constants.ts @@ -1,4 +1,4 @@ -import { SDKInitConfig } from "../../src/sdkRuntimeModels"; +import { SDKInitConfig } from "../../../src/sdkRuntimeModels"; export const urls = { events: 'https://jssdks.mparticle.com/v3/JS/test_key/events', diff --git a/test/src/_test.setup.ts b/test/src/config/setup.ts similarity index 90% rename from test/src/_test.setup.ts rename to test/src/config/setup.ts index 2611ea48..9d630d7f 100644 --- a/test/src/_test.setup.ts +++ b/test/src/config/setup.ts @@ -1,5 +1,5 @@ -import { MPConfig, workspaceToken } from './config'; -import { MParticleWebSDK } from '../../src/sdkRuntimeModels'; +import { MPConfig, workspaceToken } from './constants'; +import { MParticleWebSDK } from '../../../src/sdkRuntimeModels'; declare global { interface Window { diff --git a/test/src/utils.js b/test/src/config/utils.js similarity index 99% rename from test/src/utils.js rename to test/src/config/utils.js index 4dc27e89..e2183398 100644 --- a/test/src/utils.js +++ b/test/src/config/utils.js @@ -1,4 +1,4 @@ -import * as Utils from '../../src/utils'; +import * as Utils from '../../../src/utils'; import { apiKey, testMPID, @@ -8,7 +8,7 @@ import { workspaceToken, workspaceCookieName, das, -} from './config'; +} from './constants'; var pluses = /\+/g, getLocalStorageProducts = function getLocalStorageProducts() { diff --git a/test/src/tests-apiClient.ts b/test/src/tests-apiClient.ts index bf271027..af2bd57c 100644 --- a/test/src/tests-apiClient.ts +++ b/test/src/tests-apiClient.ts @@ -1,6 +1,6 @@ import Types from '../../src/types'; import Constants from '../../src/constants'; -import { apiKey, MPConfig } from './config'; +import { apiKey, MPConfig } from './config/constants'; import { MParticleWebSDK } from '../../src/sdkRuntimeModels'; import { expect } from 'chai'; diff --git a/test/src/tests-batchUploader.ts b/test/src/tests-batchUploader.ts index 5742bcab..43d2905a 100644 --- a/test/src/tests-batchUploader.ts +++ b/test/src/tests-batchUploader.ts @@ -1,6 +1,6 @@ import sinon from 'sinon'; -import { urls } from './config'; -import { apiKey, MPConfig, testMPID } from './config'; +import { urls } from './config/constants'; +import { apiKey, MPConfig, testMPID } from './config/constants'; import { BaseEvent, MParticleWebSDK, @@ -8,7 +8,7 @@ import { SDKProductActionType, } from '../../src/sdkRuntimeModels'; import { Batch, CustomEventData } from '@mparticle/event-models'; -import Utils from './utils'; +import Utils from './config/utils'; import { BatchUploader } from '../../src/batchUploader'; import { expect } from 'chai'; import _BatchValidator from '../../src/mockBatchCreator'; diff --git a/test/src/tests-beaconUpload.ts b/test/src/tests-beaconUpload.ts index 608adba8..3bb85484 100644 --- a/test/src/tests-beaconUpload.ts +++ b/test/src/tests-beaconUpload.ts @@ -1,8 +1,8 @@ import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; import { expect } from 'chai'; -import { urls } from './config'; -import { apiKey, MPConfig, testMPID } from './config'; +import { urls } from './config/constants'; +import { apiKey, MPConfig, testMPID } from './config/constants'; import { MParticleWebSDK } from '../../src/sdkRuntimeModels'; import { event0 } from '../fixtures/events'; import { batch1, batch2, batch3 } from '../fixtures/batches'; diff --git a/test/src/tests-config-api-client.ts b/test/src/tests-config-api-client.ts index 3141e364..f101e4df 100644 --- a/test/src/tests-config-api-client.ts +++ b/test/src/tests-config-api-client.ts @@ -1,6 +1,6 @@ import sinon from 'sinon'; -import { urls } from './config'; -import { apiKey, MPConfig } from './config'; +import { urls } from './config/constants'; +import { apiKey, MPConfig } from './config/constants'; import { expect } from 'chai'; import ConfigAPIClient, { IConfigAPIClient, diff --git a/test/src/tests-consent.ts b/test/src/tests-consent.ts index a28364ac..e76d7e2f 100644 --- a/test/src/tests-consent.ts +++ b/test/src/tests-consent.ts @@ -1,8 +1,8 @@ -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; -import { urls } from './config'; -import { apiKey, MPConfig, testMPID } from './config'; +import { urls } from './config/constants'; +import { apiKey, MPConfig, testMPID } from './config/constants'; import { MParticleWebSDK } from '../../src/sdkRuntimeModels'; import { expect } from 'chai'; import { GDPRConsentState, PrivacyConsentState } from '@mparticle/web-sdk'; diff --git a/test/src/tests-cookie-syncing.js b/test/src/tests-cookie-syncing.js index 6fea0cb7..39bcb878 100644 --- a/test/src/tests-cookie-syncing.js +++ b/test/src/tests-cookie-syncing.js @@ -1,7 +1,7 @@ -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; -import { urls, testMPID, MPConfig, v4LSKey, apiKey } from './config'; +import { urls, testMPID, MPConfig, v4LSKey, apiKey } from './config/constants'; const { setLocalStorage, MockForwarder, getLocalStorage } = Utils; diff --git a/test/src/tests-core-sdk.js b/test/src/tests-core-sdk.js index 5fc409dc..d7a4ec6f 100644 --- a/test/src/tests-core-sdk.js +++ b/test/src/tests-core-sdk.js @@ -1,10 +1,9 @@ -import Utils from './utils'; +import Utils from './config/utils'; import Store from '../../src/store'; import Constants from '../../src/constants'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; -import { urls } from './config'; -import { apiKey, das, MPConfig, testMPID, workspaceCookieName } from './config'; +import { urls, apiKey, das, MPConfig, testMPID, workspaceCookieName } from './config/constants'; const DefaultConfig = Constants.DefaultConfig, setLocalStorage = Utils.setLocalStorage, diff --git a/test/src/tests-eCommerce.js b/test/src/tests-eCommerce.js index 9082f213..19d3a248 100644 --- a/test/src/tests-eCommerce.js +++ b/test/src/tests-eCommerce.js @@ -1,7 +1,7 @@ -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; -import { urls, apiKey, workspaceToken, MPConfig, testMPID, ProductActionType, PromotionActionType } from './config'; +import { urls, apiKey, workspaceToken, MPConfig, testMPID, ProductActionType, PromotionActionType } from './config/constants'; const getLocalStorageProducts = Utils.getLocalStorageProducts, forwarderDefaultConfiguration = Utils.forwarderDefaultConfiguration, diff --git a/test/src/tests-event-logging.js b/test/src/tests-event-logging.js index 1aa54847..60a05f28 100644 --- a/test/src/tests-event-logging.js +++ b/test/src/tests-event-logging.js @@ -1,10 +1,10 @@ -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; import { urls, apiKey, testMPID, MPConfig, - MessageType } from './config'; + MessageType } from './config/constants'; const getIdentityEvent = Utils.getIdentityEvent, findEventFromRequest = Utils.findEventFromRequest, diff --git a/test/src/tests-forwarders.js b/test/src/tests-forwarders.js index d80f7ec3..633056c0 100644 --- a/test/src/tests-forwarders.js +++ b/test/src/tests-forwarders.js @@ -1,9 +1,8 @@ -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; -import { urls } from './config'; -import { apiKey, MPConfig, testMPID, MessageType } from './config'; +import { urls, apiKey, MPConfig, testMPID, MessageType } from './config/constants'; import { expect } from 'chai'; const findEventFromRequest = Utils.findEventFromRequest, diff --git a/test/src/tests-helpers.js b/test/src/tests-helpers.js index fe737b1b..bd09b39b 100644 --- a/test/src/tests-helpers.js +++ b/test/src/tests-helpers.js @@ -1,4 +1,4 @@ -import { apiKey } from './config'; +import { apiKey } from './config/constants'; import sinon from 'sinon'; describe('helpers', function() { diff --git a/test/src/tests-identities-attributes.js b/test/src/tests-identities-attributes.js index a1e98b84..60c8148d 100644 --- a/test/src/tests-identities-attributes.js +++ b/test/src/tests-identities-attributes.js @@ -1,9 +1,9 @@ -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; import { urls, apiKey, testMPID, - MPConfig } from './config'; + MPConfig } from './config/constants'; const findEventFromRequest = Utils.findEventFromRequest, findBatch = Utils.findBatch, diff --git a/test/src/tests-identity.js b/test/src/tests-identity.js index 91f54fe4..43af8746 100644 --- a/test/src/tests-identity.js +++ b/test/src/tests-identity.js @@ -1,11 +1,11 @@ import Constants from '../../src/constants'; -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; import { urls, apiKey, testMPID, MPConfig, - workspaceCookieName } from './config'; + workspaceCookieName } from './config/constants'; const getLocalStorage = Utils.getLocalStorage, setLocalStorage = Utils.setLocalStorage, diff --git a/test/src/tests-kit-blocking.ts b/test/src/tests-kit-blocking.ts index ded3721d..ed744ebf 100644 --- a/test/src/tests-kit-blocking.ts +++ b/test/src/tests-kit-blocking.ts @@ -1,9 +1,9 @@ import sinon from 'sinon'; -import { urls } from './config'; -import { apiKey, MPConfig, testMPID } from './config'; +import { urls } from './config/constants'; +import { apiKey, MPConfig, testMPID } from './config/constants'; import { MParticleWebSDK, SDKEvent, SDKProductActionType, DataPlanResult, KitBlockerDataPlan } from '../../src/sdkRuntimeModels'; import * as dataPlan from './dataPlan.json'; -import Utils from './utils'; +import Utils from './config/utils'; import KitBlocker from '../../src/kitBlocking'; import Types from '../../src/types'; import { DataPlanVersion } from '@mparticle/data-planning-models'; diff --git a/test/src/tests-mParticleUser.js b/test/src/tests-mParticleUser.js index cbd60f3b..4087cd8e 100644 --- a/test/src/tests-mParticleUser.js +++ b/test/src/tests-mParticleUser.js @@ -1,6 +1,6 @@ -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; -import { urls, apiKey, MPConfig } from './config'; +import { urls, apiKey, MPConfig } from './config/constants'; const forwarderDefaultConfiguration = Utils.forwarderDefaultConfiguration, MockForwarder = Utils.MockForwarder; diff --git a/test/src/tests-mparticle-instance-manager.js b/test/src/tests-mparticle-instance-manager.js index 55299dab..463cddb3 100644 --- a/test/src/tests-mparticle-instance-manager.js +++ b/test/src/tests-mparticle-instance-manager.js @@ -1,7 +1,7 @@ import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; -import { urls, MPConfig } from './config'; -import Utils from './utils'; +import { urls, MPConfig } from './config/constants'; +import Utils from './config/utils'; const findEventFromRequest = Utils.findEventFromRequest; let mockServer; diff --git a/test/src/tests-native-sdk.js b/test/src/tests-native-sdk.js index 72fa6d1e..8b98c87f 100644 --- a/test/src/tests-native-sdk.js +++ b/test/src/tests-native-sdk.js @@ -1,5 +1,5 @@ -import Utils from './utils'; -import { apiKey, MPConfig } from './config'; +import Utils from './config/utils'; +import { apiKey, MPConfig } from './config/constants'; import Constants from '../../src/constants'; const getLocalStorage = Utils.getLocalStorage, diff --git a/test/src/tests-persistence.ts b/test/src/tests-persistence.ts index a575845c..246df899 100644 --- a/test/src/tests-persistence.ts +++ b/test/src/tests-persistence.ts @@ -1,4 +1,4 @@ -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; @@ -12,7 +12,7 @@ import { LocalStorageProductsV4WithWorkSpaceName, workspaceCookieName, v4LSKey, -} from './config'; +} from './config/constants'; import { expect } from 'chai'; import { IGlobalStoreV2MinifiedKeys, diff --git a/test/src/tests-queue-public-methods.js b/test/src/tests-queue-public-methods.js index e2858897..442fda64 100644 --- a/test/src/tests-queue-public-methods.js +++ b/test/src/tests-queue-public-methods.js @@ -1,5 +1,5 @@ import sinon from 'sinon'; -import { apiKey, MPConfig, testMPID, urls } from './config'; +import { apiKey, MPConfig, testMPID, urls } from './config/constants'; import { SDKProductActionType } from '../../src/sdkRuntimeModels'; describe('Queue Public Methods', function () { diff --git a/test/src/tests-runtimeToBatchEventsDTO.ts b/test/src/tests-runtimeToBatchEventsDTO.ts index 2f6490f6..cbb32563 100644 --- a/test/src/tests-runtimeToBatchEventsDTO.ts +++ b/test/src/tests-runtimeToBatchEventsDTO.ts @@ -3,8 +3,8 @@ import { expect } from 'chai'; import Types from '../../src/types'; import { SDKEvent, MParticleWebSDK } from '../../src/sdkRuntimeModels'; import * as EventsApi from '@mparticle/event-models'; -import Utils from './utils'; -import { urls, MPConfig, apiKey } from './config'; +import Utils from './config/utils'; +import { urls, MPConfig, apiKey } from './config/constants'; declare global { interface Window { diff --git a/test/src/tests-self-hosting-specific.js b/test/src/tests-self-hosting-specific.js index 0262fc0d..a14e266a 100644 --- a/test/src/tests-self-hosting-specific.js +++ b/test/src/tests-self-hosting-specific.js @@ -1,7 +1,7 @@ -import Utils from './utils'; +import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; -import { urls, apiKey, MPConfig } from './config'; +import { urls, apiKey, MPConfig } from './config/constants'; const { findEventFromRequest, findBatch } = Utils; diff --git a/test/src/tests-serverModel.ts b/test/src/tests-serverModel.ts index bed7af09..bdbd2798 100644 --- a/test/src/tests-serverModel.ts +++ b/test/src/tests-serverModel.ts @@ -1,6 +1,6 @@ import Types from '../../src/types'; import sinon from 'sinon'; -import { urls, testMPID, apiKey } from './config'; +import { urls, testMPID, apiKey } from './config/constants'; import { expect } from 'chai'; import { IUploadObject } from '../../src/serverModel'; import { AllUserAttributes, IdentityApiData } from '@mparticle/web-sdk'; diff --git a/test/src/tests-session-manager.ts b/test/src/tests-session-manager.ts index 571fc693..56af5f4b 100644 --- a/test/src/tests-session-manager.ts +++ b/test/src/tests-session-manager.ts @@ -8,7 +8,7 @@ import { urls, MessageType, MILLISECONDS_IN_ONE_MINUTE, -} from './config'; +} from './config/constants'; import { IdentityApiData } from '@mparticle/web-sdk'; import Constants from '../../src/constants'; diff --git a/test/src/tests-store.ts b/test/src/tests-store.ts index b9a5d079..f81a5fd5 100644 --- a/test/src/tests-store.ts +++ b/test/src/tests-store.ts @@ -2,8 +2,8 @@ import { expect } from 'chai'; import sinon from 'sinon'; import { SDKInitConfig } from '../../src/sdkRuntimeModels'; import Store, { IStore } from '../../src/store'; -import { MPConfig, apiKey } from './config'; -import Utils from './utils'; +import { MPConfig, apiKey } from './config/constants'; +import Utils from './config/utils'; const MockSideloadedKit = Utils.MockSideloadedKit; describe('Store', () => { From 25d7f8b5a836535ecb22732c50418afe66ae7ebe Mon Sep 17 00:00:00 2001 From: Alexander Sapountzis Date: Thu, 30 Nov 2023 12:02:17 -0500 Subject: [PATCH 4/8] Revise setup to make it more typesafe --- src/sdkRuntimeModels.ts | 9 ++++++--- test/src/config/setup.ts | 4 +--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sdkRuntimeModels.ts b/src/sdkRuntimeModels.ts index 79d12397..eeb1eda0 100644 --- a/src/sdkRuntimeModels.ts +++ b/src/sdkRuntimeModels.ts @@ -207,15 +207,15 @@ export interface SDKInitConfig dataPlanOptions?: KitBlockerOptions; flags?: Dictionary; - aliasMaxWindow: number; + aliasMaxWindow?: number; deviceId?: string; forceHttps?: boolean; aliasUrl?: string; configUrl?: string; identityUrl?: string; - integrationDelayTimeout: number; + integrationDelayTimeout?: number; isIOS?: boolean; - maxProducts: number; + maxProducts?: number; requestConfig?: boolean; sessionTimeout?: number; useNativeSdk?: boolean; @@ -223,6 +223,9 @@ export interface SDKInitConfig v1SecureServiceUrl?: string; v2SecureServiceUrl?: string; v3SecureServiceUrl?: string; + + workspaceToken?: string; + isDevelopmentMode?: boolean; } export interface DataPlanConfig { diff --git a/test/src/config/setup.ts b/test/src/config/setup.ts index 9d630d7f..bd2915d4 100644 --- a/test/src/config/setup.ts +++ b/test/src/config/setup.ts @@ -19,9 +19,7 @@ beforeEach(function() { } else { window.mParticle.getInstance().Identity.getCurrentUser = userApi; } - // @ts-ignore - window.mParticle = window.mParticle || {}; - // @ts-ignore + window.mParticle.config = { workspaceToken: workspaceToken, logLevel: 'none', From a1d4845329fe2d4c604873e231f9e93729591099 Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Thu, 30 Nov 2023 13:13:17 -0500 Subject: [PATCH 5/8] Update src/sdkRuntimeModels.ts Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com> --- src/sdkRuntimeModels.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdkRuntimeModels.ts b/src/sdkRuntimeModels.ts index eeb1eda0..cf0dbcc0 100644 --- a/src/sdkRuntimeModels.ts +++ b/src/sdkRuntimeModels.ts @@ -151,8 +151,8 @@ export interface MParticleWebSDK { _NativeSdkHelpers: any; // TODO: Set up API _Persistence: IPersistence; _preInit: any; // TODO: Set up API - _instances: Dictionary; - _isTestEnv: boolean; + _instances?: Dictionary; + _isTestEnv?: boolean; _resetForTests( MPConfig?: SDKInitConfig, keepPersistence?: boolean, From 882d91bf647052be9180f50c5646a3e3cee89b89 Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Thu, 30 Nov 2023 13:15:23 -0500 Subject: [PATCH 6/8] Turn comments --- rollup.test.config.js | 2 +- src/mockBatchCreator.ts | 2 -- test/cross-browser-testing/rollup.CBT.config.js | 2 +- test/src/{__test.index.ts => _test.index.ts} | 0 4 files changed, 2 insertions(+), 4 deletions(-) rename test/src/{__test.index.ts => _test.index.ts} (100%) diff --git a/rollup.test.config.js b/rollup.test.config.js index d5f11801..9eeb28d9 100644 --- a/rollup.test.config.js +++ b/rollup.test.config.js @@ -10,7 +10,7 @@ const extensions = ['.js', '.ts']; const builds = { main: { - input: 'test/src/__test.index.ts', + input: 'test/src/_test.index.ts', output: { file: 'test/test-bundle.js', format: 'iife', diff --git a/src/mockBatchCreator.ts b/src/mockBatchCreator.ts index 7adc48b8..f07bd2d4 100644 --- a/src/mockBatchCreator.ts +++ b/src/mockBatchCreator.ts @@ -39,8 +39,6 @@ export default class _BatchValidator { _NativeSdkHelpers: null, _Persistence: null, _preInit: null, - _instances: {}, - _isTestEnv: true, Consent: null, _ServerModel: null, _SessionManager: null, diff --git a/test/cross-browser-testing/rollup.CBT.config.js b/test/cross-browser-testing/rollup.CBT.config.js index 3dee13a7..0f6d638a 100644 --- a/test/cross-browser-testing/rollup.CBT.config.js +++ b/test/cross-browser-testing/rollup.CBT.config.js @@ -8,7 +8,7 @@ import json from '@rollup/plugin-json'; export default [ { - input: 'test/src/_index.ts', + input: 'test/src/_test.index.ts', output: { file: 'test/cross-browser-testing/CBT-tests.js', format: 'umd', diff --git a/test/src/__test.index.ts b/test/src/_test.index.ts similarity index 100% rename from test/src/__test.index.ts rename to test/src/_test.index.ts From 1288b6fa905c7a762d8fdb8cca716c2b3cd18c79 Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Thu, 30 Nov 2023 15:34:15 -0500 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com> --- test/src/config/setup.ts | 2 +- test/src/tests-batchUploader.ts | 3 +-- test/src/tests-beaconUpload.ts | 3 +-- test/src/tests-config-api-client.ts | 3 +-- test/src/tests-consent.ts | 3 +-- test/src/tests-kit-blocking.ts | 3 +-- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/test/src/config/setup.ts b/test/src/config/setup.ts index bd2915d4..7f1b211b 100644 --- a/test/src/config/setup.ts +++ b/test/src/config/setup.ts @@ -7,7 +7,7 @@ declare global { } } -var userApi = null; +let userApi = null; window.mParticle._isTestEnv = true; diff --git a/test/src/tests-batchUploader.ts b/test/src/tests-batchUploader.ts index 43d2905a..8a3b071d 100644 --- a/test/src/tests-batchUploader.ts +++ b/test/src/tests-batchUploader.ts @@ -1,6 +1,5 @@ import sinon from 'sinon'; -import { urls } from './config/constants'; -import { apiKey, MPConfig, testMPID } from './config/constants'; +import { urls, apiKey, MPConfig, testMPID } from './config/constants'; import { BaseEvent, MParticleWebSDK, diff --git a/test/src/tests-beaconUpload.ts b/test/src/tests-beaconUpload.ts index 3bb85484..494b4803 100644 --- a/test/src/tests-beaconUpload.ts +++ b/test/src/tests-beaconUpload.ts @@ -1,8 +1,7 @@ import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; import { expect } from 'chai'; -import { urls } from './config/constants'; -import { apiKey, MPConfig, testMPID } from './config/constants'; +import { urls, apiKey, MPConfig, testMPID } from './config/constants'; import { MParticleWebSDK } from '../../src/sdkRuntimeModels'; import { event0 } from '../fixtures/events'; import { batch1, batch2, batch3 } from '../fixtures/batches'; diff --git a/test/src/tests-config-api-client.ts b/test/src/tests-config-api-client.ts index f101e4df..24839e59 100644 --- a/test/src/tests-config-api-client.ts +++ b/test/src/tests-config-api-client.ts @@ -1,6 +1,5 @@ import sinon from 'sinon'; -import { urls } from './config/constants'; -import { apiKey, MPConfig } from './config/constants'; +import { urls, apiKey, MPConfig } from './config/constants'; import { expect } from 'chai'; import ConfigAPIClient, { IConfigAPIClient, diff --git a/test/src/tests-consent.ts b/test/src/tests-consent.ts index e76d7e2f..07577cc3 100644 --- a/test/src/tests-consent.ts +++ b/test/src/tests-consent.ts @@ -1,8 +1,7 @@ import Utils from './config/utils'; import sinon from 'sinon'; import fetchMock from 'fetch-mock/esm/client'; -import { urls } from './config/constants'; -import { apiKey, MPConfig, testMPID } from './config/constants'; +import { urls, apiKey, MPConfig, testMPID } from './config/constants'; import { MParticleWebSDK } from '../../src/sdkRuntimeModels'; import { expect } from 'chai'; import { GDPRConsentState, PrivacyConsentState } from '@mparticle/web-sdk'; diff --git a/test/src/tests-kit-blocking.ts b/test/src/tests-kit-blocking.ts index ed744ebf..f822b958 100644 --- a/test/src/tests-kit-blocking.ts +++ b/test/src/tests-kit-blocking.ts @@ -1,6 +1,5 @@ import sinon from 'sinon'; -import { urls } from './config/constants'; -import { apiKey, MPConfig, testMPID } from './config/constants'; +import { urls, apiKey, MPConfig, testMPID } from './config/constants'; import { MParticleWebSDK, SDKEvent, SDKProductActionType, DataPlanResult, KitBlockerDataPlan } from '../../src/sdkRuntimeModels'; import * as dataPlan from './dataPlan.json'; import Utils from './config/utils'; From 30e89fdb7855e755f0beacd3ed0d439178c8bf97 Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Thu, 30 Nov 2023 16:37:11 -0500 Subject: [PATCH 8/8] Remove -w flag from build:cbt --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f45751d7..128f5217 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "repository": "https://github.com/mParticle/mparticle-web-sdk", "scripts": { "build": "cross-env ENVIRONMENT=prod BUILDALL=true rollup --config rollup.config.js", - "build:cbt": "rollup --config test/cross-browser-testing/rollup.CBT.config.js -w", + "build:cbt": "rollup --config test/cross-browser-testing/rollup.CBT.config.js", "build:dev": "cross-env ENVIRONMENT=dev BUILD=iife rollup --config rollup.config.js", "build:iife": "cross-env ENVIRONMENT=prod BUILD=iife rollup --config rollup.config.js", "build:npm": "cross-env ENVIRONMENT=prod BUILD=cjs rollup --config rollup.config.js",