diff --git a/common/test-utils/utils.ts b/common/test-utils/utils.ts new file mode 100644 index 000000000..8a0958c2f --- /dev/null +++ b/common/test-utils/utils.ts @@ -0,0 +1,23 @@ +import { + BrowserTracker, + SharedState, + TrackerConfiguration, + addTracker as addTrackerReal, +} from '../../libraries/browser-tracker-core'; + +const DEFAULT_CONFIG: Partial = { connectionTimeout: 0 }; +export function createTracker(configuration?: TrackerConfiguration) { + let id = 'sp-' + Math.random(); + return addTracker(id, id, '', '', new SharedState(), { ...DEFAULT_CONFIG, ...configuration }); +} + +export function addTracker( + trackerId: string, + namespace: string, + version: string, + endpoint: string, + sharedState: SharedState, + configuration?: TrackerConfiguration +): BrowserTracker | null { + return addTrackerReal(trackerId, namespace, version, endpoint, sharedState, { ...DEFAULT_CONFIG, ...configuration }); +} diff --git a/libraries/browser-tracker-core/test/helpers/index.ts b/libraries/browser-tracker-core/test/helpers/index.ts index e15a5c5db..797a731c2 100644 --- a/libraries/browser-tracker-core/test/helpers/index.ts +++ b/libraries/browser-tracker-core/test/helpers/index.ts @@ -1,35 +1,3 @@ -/* - * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import { TrackerConfiguration, addTracker, SharedState } from '../../src'; - // Default Domain alias is snowplow-js-tracker.local & configCookiepath is / const DEFAULT_DOMAIN_HASH = '7f01'; @@ -74,9 +42,3 @@ export function createTestSessionIdCookie(params?: CreateTestSessionIdCookie) { const domainHash = DEFAULT_DOMAIN_HASH || params?.domainHash; return `_sp_ses.${domainHash}=*; Expires=; Path=/; SameSite=None; Secure;`; } - -const DEFAULT_CONFIG: Partial = { connectionTimeout: 0 }; -export function createTracker(configuration?: TrackerConfiguration) { - let id = 'sp-' + Math.random(); - return addTracker(id, id, '', '', new SharedState(), { ...DEFAULT_CONFIG, ...configuration }); -} diff --git a/libraries/browser-tracker-core/test/tracker/session_data.test.ts b/libraries/browser-tracker-core/test/tracker/session_data.test.ts index bb0b3297a..c226c7949 100644 --- a/libraries/browser-tracker-core/test/tracker/session_data.test.ts +++ b/libraries/browser-tracker-core/test/tracker/session_data.test.ts @@ -33,10 +33,8 @@ jest.mock('uuid'); const MOCK_UUID = '123456789'; jest.spyOn(uuid, 'v4').mockReturnValue(MOCK_UUID); -import { createTestIdCookie, createTestSessionIdCookie, createTracker as baseCreateTracker } from '../helpers'; -import { TrackerConfiguration } from '../../src/tracker/types'; - -const createTracker = (config?: TrackerConfiguration) => baseCreateTracker({ ...config, connectionTimeout: 1 }); +import { createTestIdCookie, createTestSessionIdCookie } from '../helpers'; +import { createTracker } from '../../../../common/test-utils/utils'; jest.useFakeTimers('modern'); diff --git a/plugins/browser-plugin-consent/test/events.test.ts b/plugins/browser-plugin-consent/test/events.test.ts index 5353064cf..ecbd741ba 100644 --- a/plugins/browser-plugin-consent/test/events.test.ts +++ b/plugins/browser-plugin-consent/test/events.test.ts @@ -1,34 +1,6 @@ -/* - * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +import { SharedState } from '@snowplow/browser-tracker-core'; +import { addTracker } from '../../../common/test-utils/utils'; -import { addTracker, SharedState } from '@snowplow/browser-tracker-core'; import F from 'lodash/fp'; import { ConsentPlugin, trackConsentWithdrawn, trackConsentGranted, enableGdprContext } from '../src'; diff --git a/plugins/browser-plugin-enhanced-consent/test/events.test.ts b/plugins/browser-plugin-enhanced-consent/test/events.test.ts index 7c3e81074..16eab5db0 100644 --- a/plugins/browser-plugin-enhanced-consent/test/events.test.ts +++ b/plugins/browser-plugin-enhanced-consent/test/events.test.ts @@ -1,4 +1,6 @@ -import { addTracker, SharedState } from '@snowplow/browser-tracker-core'; +import { SharedState } from '@snowplow/browser-tracker-core'; +import { addTracker } from '../../../common/test-utils/utils'; + import { EnhancedConsentPlugin, trackCmpVisible, diff --git a/plugins/browser-plugin-enhanced-ecommerce/test/contexts.test.ts b/plugins/browser-plugin-enhanced-ecommerce/test/contexts.test.ts index 601872755..0ac068f92 100644 --- a/plugins/browser-plugin-enhanced-ecommerce/test/contexts.test.ts +++ b/plugins/browser-plugin-enhanced-ecommerce/test/contexts.test.ts @@ -1,34 +1,6 @@ -/* - * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +import { SharedState } from '@snowplow/browser-tracker-core'; +import { addTracker } from '../../../common/test-utils/utils'; -import { addTracker, SharedState } from '@snowplow/browser-tracker-core'; import F from 'lodash/fp'; import { EnhancedEcommercePlugin, diff --git a/plugins/browser-plugin-error-tracking/test/events.test.ts b/plugins/browser-plugin-error-tracking/test/events.test.ts index 602213abb..2168d72c7 100644 --- a/plugins/browser-plugin-error-tracking/test/events.test.ts +++ b/plugins/browser-plugin-error-tracking/test/events.test.ts @@ -1,34 +1,5 @@ -/* - * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import { addTracker, SharedState } from '@snowplow/browser-tracker-core'; +import { SharedState } from '@snowplow/browser-tracker-core'; +import { addTracker } from '../../../common/test-utils/utils'; import F from 'lodash/fp'; import { ErrorTrackingPlugin, trackError } from '../src'; diff --git a/plugins/browser-plugin-media/test/api.test.ts b/plugins/browser-plugin-media/test/api.test.ts index 68803bb12..dfa5fb90d 100644 --- a/plugins/browser-plugin-media/test/api.test.ts +++ b/plugins/browser-plugin-media/test/api.test.ts @@ -1,4 +1,5 @@ -import { addTracker, SharedState } from '@snowplow/browser-tracker-core'; +import { SharedState } from '@snowplow/browser-tracker-core'; +import { addTracker } from '../../../common/test-utils/utils'; import { PayloadBuilder, SelfDescribingJson } from '@snowplow/tracker-core'; import { endMediaTracking, diff --git a/trackers/browser-tracker/test/tracker.test.ts b/trackers/browser-tracker/test/tracker.test.ts index 085f3edc9..a55201bef 100644 --- a/trackers/browser-tracker/test/tracker.test.ts +++ b/trackers/browser-tracker/test/tracker.test.ts @@ -1,34 +1,6 @@ -/* - * Copyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import { SharedState, addTracker } from '@snowplow/browser-tracker-core'; +import { SharedState } from '@snowplow/browser-tracker-core'; +import { addTracker } from '../../../common/test-utils/utils'; + import F from 'lodash/fp'; jest.useFakeTimers('modern');