From b65d1e39e25f42d99857e3846f70dfef25b46d7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt?= Date: Tue, 28 Mar 2023 16:33:48 +0200 Subject: [PATCH 1/4] v4.37.0 (#2114) --- CHANGELOG.md | 10 ++++++++ developer-extension/package.json | 2 +- lerna.json | 2 +- packages/core/package.json | 2 +- packages/logs/package.json | 6 ++--- packages/rum-core/package.json | 4 +-- packages/rum-slim/package.json | 8 +++--- packages/rum/package.json | 8 +++--- performances/package.json | 2 +- test/app/yarn.lock | 44 ++++++++++++++++---------------- 10 files changed, 49 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79c89879a8..8f9ca4178b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,16 @@ --- +## v4.37.0 + +- ♻️[RUMF-1517] split rum-core specHelper ([#2106](https://github.com/DataDog/browser-sdk/pull/2106)) +- ♻️[RUMF-1517] split scripts utils ([#2102](https://github.com/DataDog/browser-sdk/pull/2102)) +- ✨[RUMF-1500] Remove some references to legacy bundles ([#2097](https://github.com/DataDog/browser-sdk/pull/2097)) +- 📝 RUMF-1497 Update logger API documentation ([#2098](https://github.com/DataDog/browser-sdk/pull/2098)) +- ✨ [RUMF-1518] implement a new API to stop the RUM session ([#2064](https://github.com/DataDog/browser-sdk/pull/2064)) +- 🐛 ♻️ [RUMF 1470] Fix serialization issues ([#1971](https://github.com/DataDog/browser-sdk/pull/1971)) +- ♻️ [RUMF-1505] introduce a safe `setInterval` helper function ([#2044](https://github.com/DataDog/browser-sdk/pull/2044)) + ## v4.36.0 - ✨ [RUMF-1497] Allow logger APIs to pass an Error parameter ([#2029](https://github.com/DataDog/browser-sdk/pull/2029)) diff --git a/developer-extension/package.json b/developer-extension/package.json index 6dfff48600..fbf0b14125 100644 --- a/developer-extension/package.json +++ b/developer-extension/package.json @@ -1,6 +1,6 @@ { "name": "@datadog/browser-sdk-developer-extension", - "version": "4.36.0", + "version": "4.37.0", "private": true, "scripts": { "build": "rm -rf dist && webpack --mode production", diff --git a/lerna.json b/lerna.json index 96138d0207..42d722094c 100644 --- a/lerna.json +++ b/lerna.json @@ -1,7 +1,7 @@ { "npmClient": "yarn", "useWorkspaces": true, - "version": "4.36.0", + "version": "4.37.0", "publishConfig": { "access": "public" } diff --git a/packages/core/package.json b/packages/core/package.json index c7194601c7..97248e3c7f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@datadog/browser-core", - "version": "4.36.0", + "version": "4.37.0", "license": "Apache-2.0", "main": "cjs/index.js", "module": "esm/index.js", diff --git a/packages/logs/package.json b/packages/logs/package.json index 99ac33f52f..c2243cb56f 100644 --- a/packages/logs/package.json +++ b/packages/logs/package.json @@ -1,6 +1,6 @@ { "name": "@datadog/browser-logs", - "version": "4.36.0", + "version": "4.37.0", "license": "Apache-2.0", "main": "cjs/entries/main.js", "module": "esm/entries/main.js", @@ -13,10 +13,10 @@ "replace-build-env": "node ../../scripts/build/replace-build-env.js" }, "dependencies": { - "@datadog/browser-core": "4.36.0" + "@datadog/browser-core": "4.37.0" }, "peerDependencies": { - "@datadog/browser-rum": "4.36.0" + "@datadog/browser-rum": "4.37.0" }, "peerDependenciesMeta": { "@datadog/browser-rum": { diff --git a/packages/rum-core/package.json b/packages/rum-core/package.json index 9480abde03..7d42a111d6 100644 --- a/packages/rum-core/package.json +++ b/packages/rum-core/package.json @@ -1,6 +1,6 @@ { "name": "@datadog/browser-rum-core", - "version": "4.36.0", + "version": "4.37.0", "license": "Apache-2.0", "main": "cjs/index.js", "module": "esm/index.js", @@ -12,7 +12,7 @@ "replace-build-env": "node ../../scripts/build/replace-build-env.js" }, "dependencies": { - "@datadog/browser-core": "4.36.0" + "@datadog/browser-core": "4.37.0" }, "devDependencies": { "ajv": "6.12.6" diff --git a/packages/rum-slim/package.json b/packages/rum-slim/package.json index 6c42a085c1..22d5a912a0 100644 --- a/packages/rum-slim/package.json +++ b/packages/rum-slim/package.json @@ -1,6 +1,6 @@ { "name": "@datadog/browser-rum-slim", - "version": "4.36.0", + "version": "4.37.0", "license": "Apache-2.0", "main": "cjs/entries/main.js", "module": "esm/entries/main.js", @@ -12,11 +12,11 @@ "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json" }, "dependencies": { - "@datadog/browser-core": "4.36.0", - "@datadog/browser-rum-core": "4.36.0" + "@datadog/browser-core": "4.37.0", + "@datadog/browser-rum-core": "4.37.0" }, "peerDependencies": { - "@datadog/browser-logs": "4.36.0" + "@datadog/browser-logs": "4.37.0" }, "peerDependenciesMeta": { "@datadog/browser-logs": { diff --git a/packages/rum/package.json b/packages/rum/package.json index cddb84944a..c7592ec564 100644 --- a/packages/rum/package.json +++ b/packages/rum/package.json @@ -1,6 +1,6 @@ { "name": "@datadog/browser-rum", - "version": "4.36.0", + "version": "4.37.0", "license": "Apache-2.0", "main": "cjs/entries/main.js", "module": "esm/entries/main.js", @@ -12,11 +12,11 @@ "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json" }, "dependencies": { - "@datadog/browser-core": "4.36.0", - "@datadog/browser-rum-core": "4.36.0" + "@datadog/browser-core": "4.37.0", + "@datadog/browser-rum-core": "4.37.0" }, "peerDependencies": { - "@datadog/browser-logs": "4.36.0" + "@datadog/browser-logs": "4.37.0" }, "peerDependenciesMeta": { "@datadog/browser-logs": { diff --git a/performances/package.json b/performances/package.json index c7806262aa..7b37cdafb5 100644 --- a/performances/package.json +++ b/performances/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "performances", - "version": "4.36.0", + "version": "4.37.0", "scripts": { "start": "ts-node ./src/main.ts" }, diff --git a/test/app/yarn.lock b/test/app/yarn.lock index 9ed3e0a7c9..010b688f5a 100644 --- a/test/app/yarn.lock +++ b/test/app/yarn.lock @@ -2,24 +2,24 @@ # yarn lockfile v1 -"@datadog/browser-core@4.36.0", "@datadog/browser-core@file:../../packages/core": - version "4.36.0" +"@datadog/browser-core@4.37.0", "@datadog/browser-core@file:../../packages/core": + version "4.37.0" "@datadog/browser-logs@file:../../packages/logs": - version "4.36.0" + version "4.37.0" dependencies: - "@datadog/browser-core" "4.36.0" + "@datadog/browser-core" "4.37.0" -"@datadog/browser-rum-core@4.36.0", "@datadog/browser-rum-core@file:../../packages/rum-core": - version "4.36.0" +"@datadog/browser-rum-core@4.37.0", "@datadog/browser-rum-core@file:../../packages/rum-core": + version "4.37.0" dependencies: - "@datadog/browser-core" "4.36.0" + "@datadog/browser-core" "4.37.0" "@datadog/browser-rum@file:../../packages/rum": - version "4.36.0" + version "4.37.0" dependencies: - "@datadog/browser-core" "4.36.0" - "@datadog/browser-rum-core" "4.36.0" + "@datadog/browser-core" "4.37.0" + "@datadog/browser-rum-core" "4.37.0" "@jridgewell/gen-mapping@^0.3.0": version "0.3.2" @@ -93,9 +93,9 @@ integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== "@types/node@*": - version "18.15.5" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.5.tgz#3af577099a99c61479149b716183e70b5239324a" - integrity sha512-Ark2WDjjZO7GmvsyFFf81MXuGTA/d6oP38anyxWOL6EREyBKAxKoFHwBhaZxCfLRLpO8JgVXwqOwSwa7jRcjew== + version "18.15.10" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.10.tgz#4ee2171c3306a185d1208dad5f44dae3dee4cfe3" + integrity sha512-9avDaQJczATcXgfmMAW3MIWArOO7A+m90vuCFLr8AotWf8igO/mRoYukrk2cqZVtv38tHs33retzHEilM7FpeQ== "@webassemblyjs/ast@1.11.1": version "1.11.1" @@ -288,9 +288,9 @@ buffer-from@^1.0.0: integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== caniuse-lite@^1.0.30001449: - version "1.0.30001469" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001469.tgz#3dd505430c8522fdc9f94b4a19518e330f5c945a" - integrity sha512-Rcp7221ScNqQPP3W+lVOYDyjdR6dC+neEQCttoNr5bAyz54AboB4iwpnWgyi8P4YUsPybVzT4LgWiBbI3drL4g== + version "1.0.30001472" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001472.tgz#3f484885f2a2986c019dc416e65d9d62798cdd64" + integrity sha512-xWC/0+hHHQgj3/vrKYY0AAzeIUgr7L9wlELIcAvZdDUHlhL/kNxMdnQLOSOQfP8R51ZzPhmHdyMkI0MMpmxCfg== chalk@^2.3.0: version "2.4.2" @@ -329,9 +329,9 @@ core-util-is@~1.0.0: integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ== electron-to-chromium@^1.4.284: - version "1.4.337" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.337.tgz#710168240b2dc5fe5eb5f8e4ef9c16d70aedc0ba" - integrity sha512-W8gdzXG86mVPoc56eM8YA+QiLxaAxJ8cmDjxZgfhLLWVvZQxyA918w5tX2JEWApZta45T1/sYcmFHTsTOUE3nw== + version "1.4.341" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.341.tgz#ab31e9e57ef7758a14c7a7977a1978d599514470" + integrity sha512-R4A8VfUBQY9WmAhuqY5tjHRf5fH2AAf6vqitBOE0y6u2PgHgqHSrhZmu78dIX3fVZtjqlwJNX1i2zwC3VpHtQQ== emojis-list@^3.0.0: version "3.0.0" @@ -679,9 +679,9 @@ terser-webpack-plugin@^5.1.3: terser "^5.16.5" terser@^5.16.5: - version "5.16.6" - resolved "https://registry.yarnpkg.com/terser/-/terser-5.16.6.tgz#f6c7a14a378ee0630fbe3ac8d1f41b4681109533" - integrity sha512-IBZ+ZQIA9sMaXmRZCUMDjNH0D5AQQfdn4WUjHL0+1lF4TP1IHRJbrhb6fNaXWikrYQTSkb7SLxkeXAiy1p7mbg== + version "5.16.8" + resolved "https://registry.yarnpkg.com/terser/-/terser-5.16.8.tgz#ccde583dabe71df3f4ed02b65eb6532e0fae15d5" + integrity sha512-QI5g1E/ef7d+PsDifb+a6nnVgC4F22Bg6T0xrBrz6iloVB4PUkkunp6V8nzoOOZJIzjWVdAGqCdlKlhLq/TbIA== dependencies: "@jridgewell/source-map" "^0.3.2" acorn "^8.5.0" From 74f1f60f541211990fcfa1f75d59b0216fcea828 Mon Sep 17 00:00:00 2001 From: Aymeric Date: Tue, 28 Mar 2023 17:21:45 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9C=A8=20[RUMF-1510]=20Warn=20the=20user?= =?UTF-8?q?=20when=20a=20heavy=20context=20is=20used=20(#2104)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/browser/timer.ts | 5 +- packages/core/src/index.ts | 2 + .../core/src/tools/contextManager.spec.ts | 87 +++++++++++++------ packages/core/src/tools/contextManager.ts | 38 ++++---- packages/core/src/tools/getGlobalObject.ts | 31 +++++++ .../core/src/tools/getZoneJsOriginalValue.ts | 4 +- .../tools/heavyCustomerDataWarning.spec.ts | 21 +++++ .../src/tools/heavyCustomerDataWarning.ts | 24 +++++ packages/core/src/tools/utils.ts | 31 ------- packages/core/src/transport/eventBridge.ts | 3 +- packages/logs/src/boot/logsPublicApi.ts | 5 +- packages/logs/src/domain/logger.ts | 4 +- packages/rum-core/src/boot/rumPublicApi.ts | 5 +- packages/rum-core/src/boot/startRum.spec.ts | 5 +- .../src/domain/contexts/commonContext.spec.ts | 6 +- .../contexts/featureFlagContext.spec.ts | 35 +++++--- .../src/domain/contexts/featureFlagContext.ts | 18 ++-- packages/rum-core/test/testSetupBuilder.ts | 6 +- 18 files changed, 222 insertions(+), 108 deletions(-) create mode 100644 packages/core/src/tools/getGlobalObject.ts create mode 100644 packages/core/src/tools/heavyCustomerDataWarning.spec.ts create mode 100644 packages/core/src/tools/heavyCustomerDataWarning.ts diff --git a/packages/core/src/browser/timer.ts b/packages/core/src/browser/timer.ts index 6874ac2b64..c68f2681d8 100644 --- a/packages/core/src/browser/timer.ts +++ b/packages/core/src/browser/timer.ts @@ -1,14 +1,15 @@ import { getZoneJsOriginalValue } from '../tools/getZoneJsOriginalValue' import { monitor } from '../tools/monitor' +import { getGlobalObject } from '../tools/getGlobalObject' export type TimeoutId = ReturnType export function setTimeout(callback: () => void, delay?: number): TimeoutId { - return getZoneJsOriginalValue(window, 'setTimeout')(monitor(callback), delay) + return getZoneJsOriginalValue(getGlobalObject(), 'setTimeout')(monitor(callback), delay) } export function clearTimeout(timeoutId: TimeoutId | undefined) { - getZoneJsOriginalValue(window, 'clearTimeout')(timeoutId) + getZoneJsOriginalValue(getGlobalObject(), 'clearTimeout')(timeoutId) } export function setInterval(callback: () => void, delay?: number): TimeoutId { diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c32a1d9dbe..64824239bb 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -56,6 +56,7 @@ export * from './tools/display' export * from './tools/urlPolyfill' export * from './tools/timeUtils' export * from './tools/utils' +export * from './tools/getGlobalObject' export * from './tools/sanitize' export * from './tools/createEventRateLimiter' export * from './tools/browserDetection' @@ -87,6 +88,7 @@ export { initConsoleObservable, ConsoleLog } from './domain/console/consoleObser export { BoundedBuffer } from './tools/boundedBuffer' export { catchUserErrors } from './tools/catchUserErrors' export { createContextManager, ContextManager } from './tools/contextManager' +export { warnIfCustomerDataLimitReached, CustomerDataType } from './tools/heavyCustomerDataWarning' export { limitModification } from './tools/limitModification' export { ContextHistory, ContextHistoryEntry, CLEAR_OLD_CONTEXTS_INTERVAL } from './tools/contextHistory' export { readBytesFromStream } from './tools/readBytesFromStream' diff --git a/packages/core/src/tools/contextManager.spec.ts b/packages/core/src/tools/contextManager.spec.ts index 08ec150525..02594067b5 100644 --- a/packages/core/src/tools/contextManager.spec.ts +++ b/packages/core/src/tools/contextManager.spec.ts @@ -1,26 +1,40 @@ -import { createContextManager } from './contextManager' +import type { Clock } from '../../test/specHelper' +import { mockClock } from '../../test/specHelper' +import { BYTES_COMPUTATION_THROTTLING_DELAY, createContextManager } from './contextManager' +import { CustomerDataType } from './heavyCustomerDataWarning' describe('createContextManager', () => { + let clock: Clock + + beforeEach(() => { + clock = mockClock() + }) + + afterEach(() => { + clock.cleanup() + }) + it('starts with an empty context', () => { - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) expect(manager.get()).toEqual({}) }) it('updates the context', () => { - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) manager.set({ bar: 'foo' }) + expect(manager.get()).toEqual({ bar: 'foo' }) }) it('updates the context without copy', () => { - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) const context = {} manager.set(context) expect(manager.get()).toBe(context) }) it('completely replaces the context', () => { - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) manager.set({ a: 'foo' }) expect(manager.get()).toEqual({ a: 'foo' }) manager.set({ b: 'foo' }) @@ -28,13 +42,13 @@ describe('createContextManager', () => { }) it('sets a context value', () => { - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) manager.add('foo', 'bar') expect(manager.get()).toEqual({ foo: 'bar' }) }) it('removes a context value', () => { - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) manager.set({ a: 'foo', b: 'bar' }) manager.remove('a') expect(manager.get()).toEqual({ b: 'bar' }) @@ -43,7 +57,7 @@ describe('createContextManager', () => { }) it('should get a clone of the context from getContext', () => { - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) expect(manager.getContext()).toEqual(manager.getContext()) expect(manager.getContext()).not.toBe(manager.getContext()) }) @@ -51,7 +65,7 @@ describe('createContextManager', () => { it('should set a clone of context via setContext', () => { const nestedObject = { foo: 'bar' } const context = { nested: nestedObject } - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) manager.setContext(context) expect(manager.getContext().nested).toEqual(nestedObject) expect(manager.getContext().nested).not.toBe(nestedObject) @@ -59,7 +73,7 @@ describe('createContextManager', () => { it('should set a clone of the property via setContextProperty', () => { const nestedObject = { foo: 'bar' } - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) manager.setContextProperty('nested', nestedObject) expect(manager.getContext().nested).toEqual(nestedObject) expect(manager.getContext().nested).not.toBe(nestedObject) @@ -67,36 +81,53 @@ describe('createContextManager', () => { it('should clear context object via clearContext', () => { const context = { foo: 'bar' } - const manager = createContextManager() + const manager = createContextManager(CustomerDataType.User) manager.setContext(context) expect(manager.getContext()).toEqual(context) manager.clearContext() expect(manager.getContext()).toEqual({}) }) - it('should compute the bytes count only if the context has been updated', () => { - const computeBytesCountStub = jasmine.createSpy('computeBytesCountStub').and.returnValue(1) - const manager = createContextManager(computeBytesCountStub) + describe('bytes count computation', () => { + it('should be done every time the context is updated', () => { + const computeBytesCountStub = jasmine.createSpy('computeBytesCountStub').and.returnValue(1) + const manager = createContextManager(CustomerDataType.User, computeBytesCountStub) - manager.getBytesCount() + manager.add('foo', 'bar') + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) - manager.remove('foo') - manager.getBytesCount() + manager.remove('foo') + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) - manager.set({ foo: 'bar' }) - manager.getBytesCount() + manager.set({ foo: 'bar' }) + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) - manager.removeContextProperty('foo') - manager.getBytesCount() + manager.setContextProperty('foo', 'bar') + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) - manager.setContext({ foo: 'bar' }) - manager.getBytesCount() + manager.removeContextProperty('foo') + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) - manager.clearContext() - manager.getBytesCount() - const bytesCount = manager.getBytesCount() + manager.setContext({ foo: 'bar' }) + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + + manager.clearContext() + const bytesCount = manager.getBytesCount() + + expect(bytesCount).toEqual(0) + expect(computeBytesCountStub).toHaveBeenCalledTimes(6) + }) + + it('should be throttled to minimize the impact on performance', () => { + const computeBytesCountStub = jasmine.createSpy('computeBytesCountStub').and.returnValue(1) + const manager = createContextManager(CustomerDataType.User, computeBytesCountStub) + + manager.setContextProperty('1', 'foo') // leading call executed synchronously + manager.setContextProperty('2', 'bar') // ignored + manager.setContextProperty('3', 'bar') // trailing call executed after BYTES_COMPUTATION_THROTTLING_DELAY + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) - expect(bytesCount).toEqual(1) - expect(computeBytesCountStub).toHaveBeenCalledTimes(6) + expect(computeBytesCountStub).toHaveBeenCalledTimes(2) + }) }) }) diff --git a/packages/core/src/tools/contextManager.ts b/packages/core/src/tools/contextManager.ts index 907977821a..8ffdda3011 100644 --- a/packages/core/src/tools/contextManager.ts +++ b/packages/core/src/tools/contextManager.ts @@ -1,62 +1,68 @@ import { isExperimentalFeatureEnabled } from '../domain/configuration' -import { computeBytesCount, deepClone, jsonStringify } from './utils' +import { computeBytesCount, deepClone, jsonStringify, throttle } from './utils' import type { Context, ContextValue } from './context' +import type { CustomerDataType } from './heavyCustomerDataWarning' +import { warnIfCustomerDataLimitReached } from './heavyCustomerDataWarning' import { sanitize } from './sanitize' +export const BYTES_COMPUTATION_THROTTLING_DELAY = 200 + export type ContextManager = ReturnType -export function createContextManager(computeBytesCountImpl = computeBytesCount) { +export function createContextManager(customerDataType: CustomerDataType, computeBytesCountImpl = computeBytesCount) { let context: Context = {} - let bytesCountCache: number | undefined + let bytesCountCache: number + + // Throttle the bytes computation to minimize the impact on performance. + // Especially usefull if the user call context APIs synchronously mutliple times in a row + const { throttled: computeBytesCountThrottled } = throttle((context: Context) => { + bytesCountCache = computeBytesCountImpl(jsonStringify(context)!) + warnIfCustomerDataLimitReached(bytesCountCache, customerDataType) + }, BYTES_COMPUTATION_THROTTLING_DELAY) return { - getBytesCount: () => { - if (bytesCountCache === undefined) { - bytesCountCache = computeBytesCountImpl(jsonStringify(context)!) - } - return bytesCountCache - }, + getBytesCount: () => bytesCountCache, /** @deprecated use getContext instead */ get: () => context, /** @deprecated use setContextProperty instead */ add: (key: string, value: any) => { context[key] = value as ContextValue - bytesCountCache = undefined + computeBytesCountThrottled(context) }, /** @deprecated renamed to removeContextProperty */ remove: (key: string) => { delete context[key] - bytesCountCache = undefined + computeBytesCountThrottled(context) }, /** @deprecated use setContext instead */ set: (newContext: object) => { context = newContext as Context - bytesCountCache = undefined + computeBytesCountThrottled(context) }, getContext: () => deepClone(context), setContext: (newContext: Context) => { context = isExperimentalFeatureEnabled('sanitize_inputs') ? sanitize(newContext) : deepClone(newContext) - bytesCountCache = undefined + computeBytesCountThrottled(context) }, setContextProperty: (key: string, property: any) => { context[key] = isExperimentalFeatureEnabled('sanitize_inputs') ? sanitize(property) : deepClone(property) - bytesCountCache = undefined + computeBytesCountThrottled(context) }, removeContextProperty: (key: string) => { delete context[key] - bytesCountCache = undefined + computeBytesCountThrottled(context) }, clearContext: () => { context = {} - bytesCountCache = undefined + bytesCountCache = 0 }, } } diff --git a/packages/core/src/tools/getGlobalObject.ts b/packages/core/src/tools/getGlobalObject.ts new file mode 100644 index 0000000000..755754c8dc --- /dev/null +++ b/packages/core/src/tools/getGlobalObject.ts @@ -0,0 +1,31 @@ +/** + * inspired by https://mathiasbynens.be/notes/globalthis + */ + +export function getGlobalObject(): T { + if (typeof globalThis === 'object') { + return globalThis as unknown as T + } + Object.defineProperty(Object.prototype, '_dd_temp_', { + get() { + return this as object + }, + configurable: true, + }) + // @ts-ignore _dd_temp is defined using defineProperty + let globalObject: unknown = _dd_temp_ + // @ts-ignore _dd_temp is defined using defineProperty + delete Object.prototype._dd_temp_ + if (typeof globalObject !== 'object') { + // on safari _dd_temp_ is available on window but not globally + // fallback on other browser globals check + if (typeof self === 'object') { + globalObject = self + } else if (typeof window === 'object') { + globalObject = window + } else { + globalObject = {} + } + } + return globalObject as T +} diff --git a/packages/core/src/tools/getZoneJsOriginalValue.ts b/packages/core/src/tools/getZoneJsOriginalValue.ts index a4b628b879..12d05e0719 100644 --- a/packages/core/src/tools/getZoneJsOriginalValue.ts +++ b/packages/core/src/tools/getZoneJsOriginalValue.ts @@ -1,3 +1,5 @@ +import { getGlobalObject } from './getGlobalObject' + export interface BrowserWindowWithZoneJs extends Window { Zone?: { // All Zone.js versions expose the __symbol__ method, but we observed that some website have a @@ -24,7 +26,7 @@ export function getZoneJsOriginalValue() let original: Target[Name] | undefined if (browserWindow.Zone && typeof browserWindow.Zone.__symbol__ === 'function') { original = (target as any)[browserWindow.Zone.__symbol__(name)] diff --git a/packages/core/src/tools/heavyCustomerDataWarning.spec.ts b/packages/core/src/tools/heavyCustomerDataWarning.spec.ts new file mode 100644 index 0000000000..94f2f3589b --- /dev/null +++ b/packages/core/src/tools/heavyCustomerDataWarning.spec.ts @@ -0,0 +1,21 @@ +import { display } from './display' +import { CustomerDataType, CUSTOMER_DATA_BYTES_LIMIT, warnIfCustomerDataLimitReached } from './heavyCustomerDataWarning' + +describe('warnIfCustomerDataLimitReached', () => { + let displaySpy: jasmine.Spy + beforeEach(() => { + displaySpy = spyOn(display, 'warn') + }) + + it('should warn when the customer data reach the limit', () => { + warnIfCustomerDataLimitReached(CUSTOMER_DATA_BYTES_LIMIT + 1, CustomerDataType.User) + expect(displaySpy).toHaveBeenCalledWith( + "The user data is over 3KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth." + ) + }) + + it('should not warn when the customer data reach the limit', () => { + warnIfCustomerDataLimitReached(CUSTOMER_DATA_BYTES_LIMIT - 1, CustomerDataType.User) + expect(displaySpy).not.toHaveBeenCalled() + }) +}) diff --git a/packages/core/src/tools/heavyCustomerDataWarning.ts b/packages/core/src/tools/heavyCustomerDataWarning.ts new file mode 100644 index 0000000000..3dd852a55e --- /dev/null +++ b/packages/core/src/tools/heavyCustomerDataWarning.ts @@ -0,0 +1,24 @@ +import { display } from './display' +import { ONE_KIBI_BYTE } from './utils' + +// RUM and logs batch bytes limit is 16KB +// ensure that we leave room for other event attributes and maintain a decent amount of event per batch +// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB +export const CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE + +export const enum CustomerDataType { + FeatureFlag = 'feature flag evaluation', + User = 'user', + GlobalContext = 'global context', + LoggerContext = 'logger context', +} + +export function warnIfCustomerDataLimitReached(bytesCount: number, customerDataType: CustomerDataType) { + if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) { + display.warn( + `The ${customerDataType} data is over ${ + CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE + }KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.` + ) + } +} diff --git a/packages/core/src/tools/utils.ts b/packages/core/src/tools/utils.ts index e62ccabe72..44a828f323 100644 --- a/packages/core/src/tools/utils.ts +++ b/packages/core/src/tools/utils.ts @@ -272,37 +272,6 @@ export function endsWith(candidate: string, search: string) { return candidate.slice(-search.length) === search } -/** - * inspired by https://mathiasbynens.be/notes/globalthis - */ -export function getGlobalObject(): T { - if (typeof globalThis === 'object') { - return globalThis as unknown as T - } - Object.defineProperty(Object.prototype, '_dd_temp_', { - get() { - return this as object - }, - configurable: true, - }) - // @ts-ignore _dd_temp is defined using defineProperty - let globalObject: unknown = _dd_temp_ - // @ts-ignore _dd_temp is defined using defineProperty - delete Object.prototype._dd_temp_ - if (typeof globalObject !== 'object') { - // on safari _dd_temp_ is available on window but not globally - // fallback on other browser globals check - if (typeof self === 'object') { - globalObject = self - } else if (typeof window === 'object') { - globalObject = window - } else { - globalObject = {} - } - } - return globalObject as T -} - export function getLocationOrigin() { return getLinkElementOrigin(window.location) } diff --git a/packages/core/src/transport/eventBridge.ts b/packages/core/src/transport/eventBridge.ts index 17a72a7859..5d306b0d74 100644 --- a/packages/core/src/transport/eventBridge.ts +++ b/packages/core/src/transport/eventBridge.ts @@ -1,4 +1,5 @@ -import { endsWith, getGlobalObject } from '../tools/utils' +import { endsWith } from '../tools/utils' +import { getGlobalObject } from '../tools/getGlobalObject' export interface BrowserWindowWithEventBridge extends Window { DatadogEventBridge?: DatadogEventBridge diff --git a/packages/logs/src/boot/logsPublicApi.ts b/packages/logs/src/boot/logsPublicApi.ts index 315b491b87..210bb5ed2f 100644 --- a/packages/logs/src/boot/logsPublicApi.ts +++ b/packages/logs/src/boot/logsPublicApi.ts @@ -1,5 +1,6 @@ import type { Context, InitConfiguration, User } from '@datadog/browser-core' import { + CustomerDataType, isExperimentalFeatureEnabled, assign, BoundedBuffer, @@ -36,8 +37,8 @@ type StartLogsResult = ReturnType export function makeLogsPublicApi(startLogsImpl: StartLogs) { let isAlreadyInitialized = false - const globalContextManager = createContextManager() - const userContextManager = createContextManager() + const globalContextManager = createContextManager(CustomerDataType.GlobalContext) + const userContextManager = createContextManager(CustomerDataType.User) const customLoggers: { [name: string]: Logger | undefined } = {} let getInternalContextStrategy: StartLogsResult['getInternalContext'] = () => undefined diff --git a/packages/logs/src/domain/logger.ts b/packages/logs/src/domain/logger.ts index d4cc43fbaa..2ae2ca4a92 100644 --- a/packages/logs/src/domain/logger.ts +++ b/packages/logs/src/domain/logger.ts @@ -1,5 +1,6 @@ import type { Context } from '@datadog/browser-core' import { + CustomerDataType, isExperimentalFeatureEnabled, clocksNow, computeRawError, @@ -14,6 +15,7 @@ import { monitored, sanitize, } from '@datadog/browser-core' + import type { LogsEvent } from '../logsEvent.types' export interface LogsMessage { @@ -41,7 +43,7 @@ export type HandlerType = (typeof HandlerType)[keyof typeof HandlerType] export const STATUSES = Object.keys(StatusType) as StatusType[] export class Logger { - private contextManager = createContextManager() + private contextManager = createContextManager(CustomerDataType.LoggerContext) constructor( private handleLogStrategy: (logsMessage: LogsMessage, logger: Logger) => void, diff --git a/packages/rum-core/src/boot/rumPublicApi.ts b/packages/rum-core/src/boot/rumPublicApi.ts index 7801ece31e..50584bf635 100644 --- a/packages/rum-core/src/boot/rumPublicApi.ts +++ b/packages/rum-core/src/boot/rumPublicApi.ts @@ -1,5 +1,6 @@ import type { Context, InitConfiguration, TimeStamp, RelativeTime, User } from '@datadog/browser-core' import { + CustomerDataType, noop, isExperimentalFeatureEnabled, willSyntheticsInjectRum, @@ -61,8 +62,8 @@ export function makeRumPublicApi( ) { let isAlreadyInitialized = false - const globalContextManager = createContextManager() - const userContextManager = createContextManager() + const globalContextManager = createContextManager(CustomerDataType.GlobalContext) + const userContextManager = createContextManager(CustomerDataType.User) let getInternalContextStrategy: StartRumResult['getInternalContext'] = () => undefined let getInitConfigurationStrategy = (): InitConfiguration | undefined => undefined diff --git a/packages/rum-core/src/boot/startRum.spec.ts b/packages/rum-core/src/boot/startRum.spec.ts index 829146c6c3..a06b6268e7 100644 --- a/packages/rum-core/src/boot/startRum.spec.ts +++ b/packages/rum-core/src/boot/startRum.spec.ts @@ -1,5 +1,6 @@ import type { RelativeTime, Observable, RawError, Duration } from '@datadog/browser-core' import { + CustomerDataType, createContextManager, stopSessionManager, toServerDuration, @@ -305,8 +306,8 @@ describe('view events', () => { {} as RumInitConfiguration, configuration, noopRecorderApi, - createContextManager(), - createContextManager() + createContextManager(CustomerDataType.GlobalContext), + createContextManager(CustomerDataType.User) ) }) interceptor = interceptRequests() diff --git a/packages/rum-core/src/domain/contexts/commonContext.spec.ts b/packages/rum-core/src/domain/contexts/commonContext.spec.ts index 1552bb27f2..6ea91755d0 100644 --- a/packages/rum-core/src/domain/contexts/commonContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/commonContext.spec.ts @@ -1,5 +1,5 @@ import type { Context, ContextManager } from '@datadog/browser-core' -import { createContextManager } from '@datadog/browser-core' +import { CustomerDataType, createContextManager } from '@datadog/browser-core' import type { RecorderApi } from '../../boot/rumPublicApi' import { noopRecorderApi } from '../../../test/noopRecorderApi' import type { CommonContext } from './commonContext' @@ -13,8 +13,8 @@ describe('commonContext', () => { beforeEach(() => { isRecording = false fakeContext = { foo: 'bar' } - const globalContextManager: ContextManager = createContextManager() - const userContextManager: ContextManager = createContextManager() + const globalContextManager: ContextManager = createContextManager(CustomerDataType.GlobalContext) + const userContextManager: ContextManager = createContextManager(CustomerDataType.User) spyOn(globalContextManager, 'getContext').and.callFake(() => fakeContext) spyOn(userContextManager, 'getContext').and.callFake(() => fakeContext) diff --git a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts index 1f20b5816e..e1f5ea31ef 100644 --- a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts @@ -1,11 +1,13 @@ import type { RelativeTime } from '@datadog/browser-core' import { resetExperimentalFeatures, updateExperimentalFeatures, relativeToClocks } from '@datadog/browser-core' +import type { Clock } from '../../../../core/test/specHelper' +import type { LifeCycle } from '../lifeCycle' import type { TestSetupBuilder } from '../../../test/testSetupBuilder' import { setup } from '../../../test/testSetupBuilder' import { LifeCycleEventType } from '../lifeCycle' import type { ViewCreatedEvent, ViewEndedEvent } from '../rumEventsCollection/view/trackViews' import type { FeatureFlagContexts } from './featureFlagContext' -import { startFeatureFlagContexts } from './featureFlagContext' +import { BYTES_COMPUTATION_THROTTLING_DELAY, startFeatureFlagContexts } from './featureFlagContext' describe('featureFlagContexts', () => { let setupBuilder: TestSetupBuilder @@ -147,28 +149,41 @@ describe('featureFlagContexts', () => { }) }) - describe('getFeatureFlagBytesCount', () => { - it('should compute the bytes count only if the context has been updated', () => { - updateExperimentalFeatures(['feature_flags']) - const { lifeCycle } = setupBuilder.withFakeClock().build() + describe('bytes count computation', () => { + let clock: Clock + let lifeCycle: LifeCycle + beforeEach(() => { + updateExperimentalFeatures(['feature_flags']) + ;({ clock, lifeCycle } = setupBuilder.withFakeClock().build()) lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, { startClocks: relativeToClocks(0 as RelativeTime), } as ViewCreatedEvent) + }) + + it('should be done each time the context is updated', () => { featureFlagContexts.addFeatureFlagEvaluation('feature1', 'foo') - featureFlagContexts.getFeatureFlagBytesCount() + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) featureFlagContexts.addFeatureFlagEvaluation('feature2', 'bar') - featureFlagContexts.getFeatureFlagBytesCount() + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) // feature flags are cleared when a view is created lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, { startClocks: relativeToClocks(10 as RelativeTime), } as ViewCreatedEvent) - featureFlagContexts.getFeatureFlagBytesCount() const bytesCount = featureFlagContexts.getFeatureFlagBytesCount() - expect(bytesCount).toEqual(1) - expect(computeBytesCountStub).toHaveBeenCalledTimes(3) + expect(bytesCount).toEqual(0) + expect(computeBytesCountStub).toHaveBeenCalledTimes(2) + }) + + it('should be throttled to minimize the impact on performance', () => { + featureFlagContexts.addFeatureFlagEvaluation('feature1', 'foo') // leading call executed synchronously + featureFlagContexts.addFeatureFlagEvaluation('feature2', 'bar') // ignored + featureFlagContexts.addFeatureFlagEvaluation('feature3', 'baz') // trailing call executed after BYTES_COMPUTATION_THROTTLING_DELAY + clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + + expect(computeBytesCountStub).toHaveBeenCalledTimes(2) }) }) }) diff --git a/packages/rum-core/src/domain/contexts/featureFlagContext.ts b/packages/rum-core/src/domain/contexts/featureFlagContext.ts index 27cf8575fa..00a2c6bbfd 100644 --- a/packages/rum-core/src/domain/contexts/featureFlagContext.ts +++ b/packages/rum-core/src/domain/contexts/featureFlagContext.ts @@ -1,5 +1,8 @@ import type { RelativeTime, ContextValue, Context } from '@datadog/browser-core' import { + CustomerDataType, + warnIfCustomerDataLimitReached, + throttle, jsonStringify, computeBytesCount, noop, @@ -11,6 +14,7 @@ import type { LifeCycle } from '../lifeCycle' import { LifeCycleEventType } from '../lifeCycle' export const FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY +export const BYTES_COMPUTATION_THROTTLING_DELAY = 200 export type FeatureFlagContext = Context @@ -41,7 +45,7 @@ export function startFeatureFlagContexts( } const featureFlagContexts = new ContextHistory(FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY) - let bytesCountCache: number | undefined + let bytesCountCache = 0 lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, ({ endClocks }) => { featureFlagContexts.closeActive(endClocks.relative) @@ -49,9 +53,14 @@ export function startFeatureFlagContexts( lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, ({ startClocks }) => { featureFlagContexts.add({}, startClocks.relative) - bytesCountCache = undefined + bytesCountCache = 0 }) + const { throttled: computeBytesCountThrottled } = throttle((context: Context) => { + bytesCountCache = computeBytesCountImpl(jsonStringify(context)!) + warnIfCustomerDataLimitReached(bytesCountCache, CustomerDataType.FeatureFlag) + }, BYTES_COMPUTATION_THROTTLING_DELAY) + return { findFeatureFlagEvaluations: (startTime?: RelativeTime) => featureFlagContexts.find(startTime), getFeatureFlagBytesCount: () => { @@ -60,16 +69,13 @@ export function startFeatureFlagContexts( return 0 } - if (bytesCountCache === undefined) { - bytesCountCache = computeBytesCountImpl(jsonStringify(currentContext)!) - } return bytesCountCache }, addFeatureFlagEvaluation: (key: string, value: ContextValue) => { const currentContext = featureFlagContexts.find() if (currentContext) { currentContext[key] = value - bytesCountCache = undefined + computeBytesCountThrottled(currentContext) } }, } diff --git a/packages/rum-core/test/testSetupBuilder.ts b/packages/rum-core/test/testSetupBuilder.ts index f46454280a..e4535b794a 100644 --- a/packages/rum-core/test/testSetupBuilder.ts +++ b/packages/rum-core/test/testSetupBuilder.ts @@ -1,5 +1,5 @@ import type { Context, ContextManager, TimeStamp } from '@datadog/browser-core' -import { assign, combine, createContextManager, noop, Observable } from '@datadog/browser-core' +import { CustomerDataType, createContextManager, combine, Observable, noop, assign } from '@datadog/browser-core' import type { Clock } from '../../core/test/specHelper' import { buildLocation, mockClock, SPEC_ENDPOINTS } from '../../core/test/specHelper' import type { LocationChange } from '../src/browser/locationChangeObservable' @@ -98,8 +98,8 @@ export function setup(): TestSetupBuilder { selectInForegroundPeriodsFor: () => undefined, stop: noop, } - const globalContextManager = createContextManager() - const userContextManager = createContextManager() + const globalContextManager = createContextManager(CustomerDataType.GlobalContext) + const userContextManager = createContextManager(CustomerDataType.User) const pageStateHistory: PageStateHistory = { findAll: () => undefined, stop: noop, From 30f3154bfa9a0ee23a077aa377516596f1a7f240 Mon Sep 17 00:00:00 2001 From: Aymeric Date: Tue, 28 Mar 2023 18:23:08 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Revert=20"=E2=9C=A8=20[RUMF-1510]=20Warn=20?= =?UTF-8?q?the=20user=20when=20a=20heavy=20context=20is=20used=20(#2104)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 74f1f60f541211990fcfa1f75d59b0216fcea828. --- packages/core/src/browser/timer.ts | 5 +- packages/core/src/index.ts | 2 - .../core/src/tools/contextManager.spec.ts | 87 ++++++------------- packages/core/src/tools/contextManager.ts | 38 ++++---- packages/core/src/tools/getGlobalObject.ts | 31 ------- .../core/src/tools/getZoneJsOriginalValue.ts | 4 +- .../tools/heavyCustomerDataWarning.spec.ts | 21 ----- .../src/tools/heavyCustomerDataWarning.ts | 24 ----- packages/core/src/tools/utils.ts | 31 +++++++ packages/core/src/transport/eventBridge.ts | 3 +- packages/logs/src/boot/logsPublicApi.ts | 5 +- packages/logs/src/domain/logger.ts | 4 +- packages/rum-core/src/boot/rumPublicApi.ts | 5 +- packages/rum-core/src/boot/startRum.spec.ts | 5 +- .../src/domain/contexts/commonContext.spec.ts | 6 +- .../contexts/featureFlagContext.spec.ts | 35 +++----- .../src/domain/contexts/featureFlagContext.ts | 18 ++-- packages/rum-core/test/testSetupBuilder.ts | 6 +- 18 files changed, 108 insertions(+), 222 deletions(-) delete mode 100644 packages/core/src/tools/getGlobalObject.ts delete mode 100644 packages/core/src/tools/heavyCustomerDataWarning.spec.ts delete mode 100644 packages/core/src/tools/heavyCustomerDataWarning.ts diff --git a/packages/core/src/browser/timer.ts b/packages/core/src/browser/timer.ts index c68f2681d8..6874ac2b64 100644 --- a/packages/core/src/browser/timer.ts +++ b/packages/core/src/browser/timer.ts @@ -1,15 +1,14 @@ import { getZoneJsOriginalValue } from '../tools/getZoneJsOriginalValue' import { monitor } from '../tools/monitor' -import { getGlobalObject } from '../tools/getGlobalObject' export type TimeoutId = ReturnType export function setTimeout(callback: () => void, delay?: number): TimeoutId { - return getZoneJsOriginalValue(getGlobalObject(), 'setTimeout')(monitor(callback), delay) + return getZoneJsOriginalValue(window, 'setTimeout')(monitor(callback), delay) } export function clearTimeout(timeoutId: TimeoutId | undefined) { - getZoneJsOriginalValue(getGlobalObject(), 'clearTimeout')(timeoutId) + getZoneJsOriginalValue(window, 'clearTimeout')(timeoutId) } export function setInterval(callback: () => void, delay?: number): TimeoutId { diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 64824239bb..c32a1d9dbe 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -56,7 +56,6 @@ export * from './tools/display' export * from './tools/urlPolyfill' export * from './tools/timeUtils' export * from './tools/utils' -export * from './tools/getGlobalObject' export * from './tools/sanitize' export * from './tools/createEventRateLimiter' export * from './tools/browserDetection' @@ -88,7 +87,6 @@ export { initConsoleObservable, ConsoleLog } from './domain/console/consoleObser export { BoundedBuffer } from './tools/boundedBuffer' export { catchUserErrors } from './tools/catchUserErrors' export { createContextManager, ContextManager } from './tools/contextManager' -export { warnIfCustomerDataLimitReached, CustomerDataType } from './tools/heavyCustomerDataWarning' export { limitModification } from './tools/limitModification' export { ContextHistory, ContextHistoryEntry, CLEAR_OLD_CONTEXTS_INTERVAL } from './tools/contextHistory' export { readBytesFromStream } from './tools/readBytesFromStream' diff --git a/packages/core/src/tools/contextManager.spec.ts b/packages/core/src/tools/contextManager.spec.ts index 02594067b5..08ec150525 100644 --- a/packages/core/src/tools/contextManager.spec.ts +++ b/packages/core/src/tools/contextManager.spec.ts @@ -1,40 +1,26 @@ -import type { Clock } from '../../test/specHelper' -import { mockClock } from '../../test/specHelper' -import { BYTES_COMPUTATION_THROTTLING_DELAY, createContextManager } from './contextManager' -import { CustomerDataType } from './heavyCustomerDataWarning' +import { createContextManager } from './contextManager' describe('createContextManager', () => { - let clock: Clock - - beforeEach(() => { - clock = mockClock() - }) - - afterEach(() => { - clock.cleanup() - }) - it('starts with an empty context', () => { - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() expect(manager.get()).toEqual({}) }) it('updates the context', () => { - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() manager.set({ bar: 'foo' }) - expect(manager.get()).toEqual({ bar: 'foo' }) }) it('updates the context without copy', () => { - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() const context = {} manager.set(context) expect(manager.get()).toBe(context) }) it('completely replaces the context', () => { - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() manager.set({ a: 'foo' }) expect(manager.get()).toEqual({ a: 'foo' }) manager.set({ b: 'foo' }) @@ -42,13 +28,13 @@ describe('createContextManager', () => { }) it('sets a context value', () => { - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() manager.add('foo', 'bar') expect(manager.get()).toEqual({ foo: 'bar' }) }) it('removes a context value', () => { - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() manager.set({ a: 'foo', b: 'bar' }) manager.remove('a') expect(manager.get()).toEqual({ b: 'bar' }) @@ -57,7 +43,7 @@ describe('createContextManager', () => { }) it('should get a clone of the context from getContext', () => { - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() expect(manager.getContext()).toEqual(manager.getContext()) expect(manager.getContext()).not.toBe(manager.getContext()) }) @@ -65,7 +51,7 @@ describe('createContextManager', () => { it('should set a clone of context via setContext', () => { const nestedObject = { foo: 'bar' } const context = { nested: nestedObject } - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() manager.setContext(context) expect(manager.getContext().nested).toEqual(nestedObject) expect(manager.getContext().nested).not.toBe(nestedObject) @@ -73,7 +59,7 @@ describe('createContextManager', () => { it('should set a clone of the property via setContextProperty', () => { const nestedObject = { foo: 'bar' } - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() manager.setContextProperty('nested', nestedObject) expect(manager.getContext().nested).toEqual(nestedObject) expect(manager.getContext().nested).not.toBe(nestedObject) @@ -81,53 +67,36 @@ describe('createContextManager', () => { it('should clear context object via clearContext', () => { const context = { foo: 'bar' } - const manager = createContextManager(CustomerDataType.User) + const manager = createContextManager() manager.setContext(context) expect(manager.getContext()).toEqual(context) manager.clearContext() expect(manager.getContext()).toEqual({}) }) - describe('bytes count computation', () => { - it('should be done every time the context is updated', () => { - const computeBytesCountStub = jasmine.createSpy('computeBytesCountStub').and.returnValue(1) - const manager = createContextManager(CustomerDataType.User, computeBytesCountStub) + it('should compute the bytes count only if the context has been updated', () => { + const computeBytesCountStub = jasmine.createSpy('computeBytesCountStub').and.returnValue(1) + const manager = createContextManager(computeBytesCountStub) - manager.add('foo', 'bar') - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + manager.getBytesCount() - manager.remove('foo') - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + manager.remove('foo') + manager.getBytesCount() - manager.set({ foo: 'bar' }) - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + manager.set({ foo: 'bar' }) + manager.getBytesCount() - manager.setContextProperty('foo', 'bar') - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + manager.removeContextProperty('foo') + manager.getBytesCount() - manager.removeContextProperty('foo') - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + manager.setContext({ foo: 'bar' }) + manager.getBytesCount() - manager.setContext({ foo: 'bar' }) - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) - - manager.clearContext() - const bytesCount = manager.getBytesCount() - - expect(bytesCount).toEqual(0) - expect(computeBytesCountStub).toHaveBeenCalledTimes(6) - }) - - it('should be throttled to minimize the impact on performance', () => { - const computeBytesCountStub = jasmine.createSpy('computeBytesCountStub').and.returnValue(1) - const manager = createContextManager(CustomerDataType.User, computeBytesCountStub) - - manager.setContextProperty('1', 'foo') // leading call executed synchronously - manager.setContextProperty('2', 'bar') // ignored - manager.setContextProperty('3', 'bar') // trailing call executed after BYTES_COMPUTATION_THROTTLING_DELAY - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + manager.clearContext() + manager.getBytesCount() + const bytesCount = manager.getBytesCount() - expect(computeBytesCountStub).toHaveBeenCalledTimes(2) - }) + expect(bytesCount).toEqual(1) + expect(computeBytesCountStub).toHaveBeenCalledTimes(6) }) }) diff --git a/packages/core/src/tools/contextManager.ts b/packages/core/src/tools/contextManager.ts index 8ffdda3011..907977821a 100644 --- a/packages/core/src/tools/contextManager.ts +++ b/packages/core/src/tools/contextManager.ts @@ -1,68 +1,62 @@ import { isExperimentalFeatureEnabled } from '../domain/configuration' -import { computeBytesCount, deepClone, jsonStringify, throttle } from './utils' +import { computeBytesCount, deepClone, jsonStringify } from './utils' import type { Context, ContextValue } from './context' -import type { CustomerDataType } from './heavyCustomerDataWarning' -import { warnIfCustomerDataLimitReached } from './heavyCustomerDataWarning' import { sanitize } from './sanitize' -export const BYTES_COMPUTATION_THROTTLING_DELAY = 200 - export type ContextManager = ReturnType -export function createContextManager(customerDataType: CustomerDataType, computeBytesCountImpl = computeBytesCount) { +export function createContextManager(computeBytesCountImpl = computeBytesCount) { let context: Context = {} - let bytesCountCache: number - - // Throttle the bytes computation to minimize the impact on performance. - // Especially usefull if the user call context APIs synchronously mutliple times in a row - const { throttled: computeBytesCountThrottled } = throttle((context: Context) => { - bytesCountCache = computeBytesCountImpl(jsonStringify(context)!) - warnIfCustomerDataLimitReached(bytesCountCache, customerDataType) - }, BYTES_COMPUTATION_THROTTLING_DELAY) + let bytesCountCache: number | undefined return { - getBytesCount: () => bytesCountCache, + getBytesCount: () => { + if (bytesCountCache === undefined) { + bytesCountCache = computeBytesCountImpl(jsonStringify(context)!) + } + return bytesCountCache + }, /** @deprecated use getContext instead */ get: () => context, /** @deprecated use setContextProperty instead */ add: (key: string, value: any) => { context[key] = value as ContextValue - computeBytesCountThrottled(context) + bytesCountCache = undefined }, /** @deprecated renamed to removeContextProperty */ remove: (key: string) => { delete context[key] - computeBytesCountThrottled(context) + bytesCountCache = undefined }, /** @deprecated use setContext instead */ set: (newContext: object) => { context = newContext as Context - computeBytesCountThrottled(context) + bytesCountCache = undefined }, getContext: () => deepClone(context), setContext: (newContext: Context) => { context = isExperimentalFeatureEnabled('sanitize_inputs') ? sanitize(newContext) : deepClone(newContext) - computeBytesCountThrottled(context) + bytesCountCache = undefined }, setContextProperty: (key: string, property: any) => { context[key] = isExperimentalFeatureEnabled('sanitize_inputs') ? sanitize(property) : deepClone(property) - computeBytesCountThrottled(context) + bytesCountCache = undefined }, removeContextProperty: (key: string) => { delete context[key] - computeBytesCountThrottled(context) + bytesCountCache = undefined }, clearContext: () => { context = {} - bytesCountCache = 0 + bytesCountCache = undefined }, } } diff --git a/packages/core/src/tools/getGlobalObject.ts b/packages/core/src/tools/getGlobalObject.ts deleted file mode 100644 index 755754c8dc..0000000000 --- a/packages/core/src/tools/getGlobalObject.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * inspired by https://mathiasbynens.be/notes/globalthis - */ - -export function getGlobalObject(): T { - if (typeof globalThis === 'object') { - return globalThis as unknown as T - } - Object.defineProperty(Object.prototype, '_dd_temp_', { - get() { - return this as object - }, - configurable: true, - }) - // @ts-ignore _dd_temp is defined using defineProperty - let globalObject: unknown = _dd_temp_ - // @ts-ignore _dd_temp is defined using defineProperty - delete Object.prototype._dd_temp_ - if (typeof globalObject !== 'object') { - // on safari _dd_temp_ is available on window but not globally - // fallback on other browser globals check - if (typeof self === 'object') { - globalObject = self - } else if (typeof window === 'object') { - globalObject = window - } else { - globalObject = {} - } - } - return globalObject as T -} diff --git a/packages/core/src/tools/getZoneJsOriginalValue.ts b/packages/core/src/tools/getZoneJsOriginalValue.ts index 12d05e0719..a4b628b879 100644 --- a/packages/core/src/tools/getZoneJsOriginalValue.ts +++ b/packages/core/src/tools/getZoneJsOriginalValue.ts @@ -1,5 +1,3 @@ -import { getGlobalObject } from './getGlobalObject' - export interface BrowserWindowWithZoneJs extends Window { Zone?: { // All Zone.js versions expose the __symbol__ method, but we observed that some website have a @@ -26,7 +24,7 @@ export function getZoneJsOriginalValue() + const browserWindow = window as BrowserWindowWithZoneJs let original: Target[Name] | undefined if (browserWindow.Zone && typeof browserWindow.Zone.__symbol__ === 'function') { original = (target as any)[browserWindow.Zone.__symbol__(name)] diff --git a/packages/core/src/tools/heavyCustomerDataWarning.spec.ts b/packages/core/src/tools/heavyCustomerDataWarning.spec.ts deleted file mode 100644 index 94f2f3589b..0000000000 --- a/packages/core/src/tools/heavyCustomerDataWarning.spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { display } from './display' -import { CustomerDataType, CUSTOMER_DATA_BYTES_LIMIT, warnIfCustomerDataLimitReached } from './heavyCustomerDataWarning' - -describe('warnIfCustomerDataLimitReached', () => { - let displaySpy: jasmine.Spy - beforeEach(() => { - displaySpy = spyOn(display, 'warn') - }) - - it('should warn when the customer data reach the limit', () => { - warnIfCustomerDataLimitReached(CUSTOMER_DATA_BYTES_LIMIT + 1, CustomerDataType.User) - expect(displaySpy).toHaveBeenCalledWith( - "The user data is over 3KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth." - ) - }) - - it('should not warn when the customer data reach the limit', () => { - warnIfCustomerDataLimitReached(CUSTOMER_DATA_BYTES_LIMIT - 1, CustomerDataType.User) - expect(displaySpy).not.toHaveBeenCalled() - }) -}) diff --git a/packages/core/src/tools/heavyCustomerDataWarning.ts b/packages/core/src/tools/heavyCustomerDataWarning.ts deleted file mode 100644 index 3dd852a55e..0000000000 --- a/packages/core/src/tools/heavyCustomerDataWarning.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { display } from './display' -import { ONE_KIBI_BYTE } from './utils' - -// RUM and logs batch bytes limit is 16KB -// ensure that we leave room for other event attributes and maintain a decent amount of event per batch -// (3KB (customer data) + 1KB (other attributes)) * 4 (events per batch) = 16KB -export const CUSTOMER_DATA_BYTES_LIMIT = 3 * ONE_KIBI_BYTE - -export const enum CustomerDataType { - FeatureFlag = 'feature flag evaluation', - User = 'user', - GlobalContext = 'global context', - LoggerContext = 'logger context', -} - -export function warnIfCustomerDataLimitReached(bytesCount: number, customerDataType: CustomerDataType) { - if (bytesCount > CUSTOMER_DATA_BYTES_LIMIT) { - display.warn( - `The ${customerDataType} data is over ${ - CUSTOMER_DATA_BYTES_LIMIT / ONE_KIBI_BYTE - }KiB. On low connectivity, the SDK has the potential to exhaust the user's upload bandwidth.` - ) - } -} diff --git a/packages/core/src/tools/utils.ts b/packages/core/src/tools/utils.ts index 44a828f323..e62ccabe72 100644 --- a/packages/core/src/tools/utils.ts +++ b/packages/core/src/tools/utils.ts @@ -272,6 +272,37 @@ export function endsWith(candidate: string, search: string) { return candidate.slice(-search.length) === search } +/** + * inspired by https://mathiasbynens.be/notes/globalthis + */ +export function getGlobalObject(): T { + if (typeof globalThis === 'object') { + return globalThis as unknown as T + } + Object.defineProperty(Object.prototype, '_dd_temp_', { + get() { + return this as object + }, + configurable: true, + }) + // @ts-ignore _dd_temp is defined using defineProperty + let globalObject: unknown = _dd_temp_ + // @ts-ignore _dd_temp is defined using defineProperty + delete Object.prototype._dd_temp_ + if (typeof globalObject !== 'object') { + // on safari _dd_temp_ is available on window but not globally + // fallback on other browser globals check + if (typeof self === 'object') { + globalObject = self + } else if (typeof window === 'object') { + globalObject = window + } else { + globalObject = {} + } + } + return globalObject as T +} + export function getLocationOrigin() { return getLinkElementOrigin(window.location) } diff --git a/packages/core/src/transport/eventBridge.ts b/packages/core/src/transport/eventBridge.ts index 5d306b0d74..17a72a7859 100644 --- a/packages/core/src/transport/eventBridge.ts +++ b/packages/core/src/transport/eventBridge.ts @@ -1,5 +1,4 @@ -import { endsWith } from '../tools/utils' -import { getGlobalObject } from '../tools/getGlobalObject' +import { endsWith, getGlobalObject } from '../tools/utils' export interface BrowserWindowWithEventBridge extends Window { DatadogEventBridge?: DatadogEventBridge diff --git a/packages/logs/src/boot/logsPublicApi.ts b/packages/logs/src/boot/logsPublicApi.ts index 210bb5ed2f..315b491b87 100644 --- a/packages/logs/src/boot/logsPublicApi.ts +++ b/packages/logs/src/boot/logsPublicApi.ts @@ -1,6 +1,5 @@ import type { Context, InitConfiguration, User } from '@datadog/browser-core' import { - CustomerDataType, isExperimentalFeatureEnabled, assign, BoundedBuffer, @@ -37,8 +36,8 @@ type StartLogsResult = ReturnType export function makeLogsPublicApi(startLogsImpl: StartLogs) { let isAlreadyInitialized = false - const globalContextManager = createContextManager(CustomerDataType.GlobalContext) - const userContextManager = createContextManager(CustomerDataType.User) + const globalContextManager = createContextManager() + const userContextManager = createContextManager() const customLoggers: { [name: string]: Logger | undefined } = {} let getInternalContextStrategy: StartLogsResult['getInternalContext'] = () => undefined diff --git a/packages/logs/src/domain/logger.ts b/packages/logs/src/domain/logger.ts index 2ae2ca4a92..d4cc43fbaa 100644 --- a/packages/logs/src/domain/logger.ts +++ b/packages/logs/src/domain/logger.ts @@ -1,6 +1,5 @@ import type { Context } from '@datadog/browser-core' import { - CustomerDataType, isExperimentalFeatureEnabled, clocksNow, computeRawError, @@ -15,7 +14,6 @@ import { monitored, sanitize, } from '@datadog/browser-core' - import type { LogsEvent } from '../logsEvent.types' export interface LogsMessage { @@ -43,7 +41,7 @@ export type HandlerType = (typeof HandlerType)[keyof typeof HandlerType] export const STATUSES = Object.keys(StatusType) as StatusType[] export class Logger { - private contextManager = createContextManager(CustomerDataType.LoggerContext) + private contextManager = createContextManager() constructor( private handleLogStrategy: (logsMessage: LogsMessage, logger: Logger) => void, diff --git a/packages/rum-core/src/boot/rumPublicApi.ts b/packages/rum-core/src/boot/rumPublicApi.ts index 50584bf635..7801ece31e 100644 --- a/packages/rum-core/src/boot/rumPublicApi.ts +++ b/packages/rum-core/src/boot/rumPublicApi.ts @@ -1,6 +1,5 @@ import type { Context, InitConfiguration, TimeStamp, RelativeTime, User } from '@datadog/browser-core' import { - CustomerDataType, noop, isExperimentalFeatureEnabled, willSyntheticsInjectRum, @@ -62,8 +61,8 @@ export function makeRumPublicApi( ) { let isAlreadyInitialized = false - const globalContextManager = createContextManager(CustomerDataType.GlobalContext) - const userContextManager = createContextManager(CustomerDataType.User) + const globalContextManager = createContextManager() + const userContextManager = createContextManager() let getInternalContextStrategy: StartRumResult['getInternalContext'] = () => undefined let getInitConfigurationStrategy = (): InitConfiguration | undefined => undefined diff --git a/packages/rum-core/src/boot/startRum.spec.ts b/packages/rum-core/src/boot/startRum.spec.ts index a06b6268e7..829146c6c3 100644 --- a/packages/rum-core/src/boot/startRum.spec.ts +++ b/packages/rum-core/src/boot/startRum.spec.ts @@ -1,6 +1,5 @@ import type { RelativeTime, Observable, RawError, Duration } from '@datadog/browser-core' import { - CustomerDataType, createContextManager, stopSessionManager, toServerDuration, @@ -306,8 +305,8 @@ describe('view events', () => { {} as RumInitConfiguration, configuration, noopRecorderApi, - createContextManager(CustomerDataType.GlobalContext), - createContextManager(CustomerDataType.User) + createContextManager(), + createContextManager() ) }) interceptor = interceptRequests() diff --git a/packages/rum-core/src/domain/contexts/commonContext.spec.ts b/packages/rum-core/src/domain/contexts/commonContext.spec.ts index 6ea91755d0..1552bb27f2 100644 --- a/packages/rum-core/src/domain/contexts/commonContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/commonContext.spec.ts @@ -1,5 +1,5 @@ import type { Context, ContextManager } from '@datadog/browser-core' -import { CustomerDataType, createContextManager } from '@datadog/browser-core' +import { createContextManager } from '@datadog/browser-core' import type { RecorderApi } from '../../boot/rumPublicApi' import { noopRecorderApi } from '../../../test/noopRecorderApi' import type { CommonContext } from './commonContext' @@ -13,8 +13,8 @@ describe('commonContext', () => { beforeEach(() => { isRecording = false fakeContext = { foo: 'bar' } - const globalContextManager: ContextManager = createContextManager(CustomerDataType.GlobalContext) - const userContextManager: ContextManager = createContextManager(CustomerDataType.User) + const globalContextManager: ContextManager = createContextManager() + const userContextManager: ContextManager = createContextManager() spyOn(globalContextManager, 'getContext').and.callFake(() => fakeContext) spyOn(userContextManager, 'getContext').and.callFake(() => fakeContext) diff --git a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts index e1f5ea31ef..1f20b5816e 100644 --- a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts @@ -1,13 +1,11 @@ import type { RelativeTime } from '@datadog/browser-core' import { resetExperimentalFeatures, updateExperimentalFeatures, relativeToClocks } from '@datadog/browser-core' -import type { Clock } from '../../../../core/test/specHelper' -import type { LifeCycle } from '../lifeCycle' import type { TestSetupBuilder } from '../../../test/testSetupBuilder' import { setup } from '../../../test/testSetupBuilder' import { LifeCycleEventType } from '../lifeCycle' import type { ViewCreatedEvent, ViewEndedEvent } from '../rumEventsCollection/view/trackViews' import type { FeatureFlagContexts } from './featureFlagContext' -import { BYTES_COMPUTATION_THROTTLING_DELAY, startFeatureFlagContexts } from './featureFlagContext' +import { startFeatureFlagContexts } from './featureFlagContext' describe('featureFlagContexts', () => { let setupBuilder: TestSetupBuilder @@ -149,41 +147,28 @@ describe('featureFlagContexts', () => { }) }) - describe('bytes count computation', () => { - let clock: Clock - let lifeCycle: LifeCycle - - beforeEach(() => { + describe('getFeatureFlagBytesCount', () => { + it('should compute the bytes count only if the context has been updated', () => { updateExperimentalFeatures(['feature_flags']) - ;({ clock, lifeCycle } = setupBuilder.withFakeClock().build()) + const { lifeCycle } = setupBuilder.withFakeClock().build() + lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, { startClocks: relativeToClocks(0 as RelativeTime), } as ViewCreatedEvent) - }) - - it('should be done each time the context is updated', () => { featureFlagContexts.addFeatureFlagEvaluation('feature1', 'foo') - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + featureFlagContexts.getFeatureFlagBytesCount() featureFlagContexts.addFeatureFlagEvaluation('feature2', 'bar') - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) + featureFlagContexts.getFeatureFlagBytesCount() // feature flags are cleared when a view is created lifeCycle.notify(LifeCycleEventType.VIEW_CREATED, { startClocks: relativeToClocks(10 as RelativeTime), } as ViewCreatedEvent) + featureFlagContexts.getFeatureFlagBytesCount() const bytesCount = featureFlagContexts.getFeatureFlagBytesCount() - expect(bytesCount).toEqual(0) - expect(computeBytesCountStub).toHaveBeenCalledTimes(2) - }) - - it('should be throttled to minimize the impact on performance', () => { - featureFlagContexts.addFeatureFlagEvaluation('feature1', 'foo') // leading call executed synchronously - featureFlagContexts.addFeatureFlagEvaluation('feature2', 'bar') // ignored - featureFlagContexts.addFeatureFlagEvaluation('feature3', 'baz') // trailing call executed after BYTES_COMPUTATION_THROTTLING_DELAY - clock.tick(BYTES_COMPUTATION_THROTTLING_DELAY) - - expect(computeBytesCountStub).toHaveBeenCalledTimes(2) + expect(bytesCount).toEqual(1) + expect(computeBytesCountStub).toHaveBeenCalledTimes(3) }) }) }) diff --git a/packages/rum-core/src/domain/contexts/featureFlagContext.ts b/packages/rum-core/src/domain/contexts/featureFlagContext.ts index 00a2c6bbfd..27cf8575fa 100644 --- a/packages/rum-core/src/domain/contexts/featureFlagContext.ts +++ b/packages/rum-core/src/domain/contexts/featureFlagContext.ts @@ -1,8 +1,5 @@ import type { RelativeTime, ContextValue, Context } from '@datadog/browser-core' import { - CustomerDataType, - warnIfCustomerDataLimitReached, - throttle, jsonStringify, computeBytesCount, noop, @@ -14,7 +11,6 @@ import type { LifeCycle } from '../lifeCycle' import { LifeCycleEventType } from '../lifeCycle' export const FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY = SESSION_TIME_OUT_DELAY -export const BYTES_COMPUTATION_THROTTLING_DELAY = 200 export type FeatureFlagContext = Context @@ -45,7 +41,7 @@ export function startFeatureFlagContexts( } const featureFlagContexts = new ContextHistory(FEATURE_FLAG_CONTEXT_TIME_OUT_DELAY) - let bytesCountCache = 0 + let bytesCountCache: number | undefined lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, ({ endClocks }) => { featureFlagContexts.closeActive(endClocks.relative) @@ -53,14 +49,9 @@ export function startFeatureFlagContexts( lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, ({ startClocks }) => { featureFlagContexts.add({}, startClocks.relative) - bytesCountCache = 0 + bytesCountCache = undefined }) - const { throttled: computeBytesCountThrottled } = throttle((context: Context) => { - bytesCountCache = computeBytesCountImpl(jsonStringify(context)!) - warnIfCustomerDataLimitReached(bytesCountCache, CustomerDataType.FeatureFlag) - }, BYTES_COMPUTATION_THROTTLING_DELAY) - return { findFeatureFlagEvaluations: (startTime?: RelativeTime) => featureFlagContexts.find(startTime), getFeatureFlagBytesCount: () => { @@ -69,13 +60,16 @@ export function startFeatureFlagContexts( return 0 } + if (bytesCountCache === undefined) { + bytesCountCache = computeBytesCountImpl(jsonStringify(currentContext)!) + } return bytesCountCache }, addFeatureFlagEvaluation: (key: string, value: ContextValue) => { const currentContext = featureFlagContexts.find() if (currentContext) { currentContext[key] = value - computeBytesCountThrottled(currentContext) + bytesCountCache = undefined } }, } diff --git a/packages/rum-core/test/testSetupBuilder.ts b/packages/rum-core/test/testSetupBuilder.ts index e4535b794a..f46454280a 100644 --- a/packages/rum-core/test/testSetupBuilder.ts +++ b/packages/rum-core/test/testSetupBuilder.ts @@ -1,5 +1,5 @@ import type { Context, ContextManager, TimeStamp } from '@datadog/browser-core' -import { CustomerDataType, createContextManager, combine, Observable, noop, assign } from '@datadog/browser-core' +import { assign, combine, createContextManager, noop, Observable } from '@datadog/browser-core' import type { Clock } from '../../core/test/specHelper' import { buildLocation, mockClock, SPEC_ENDPOINTS } from '../../core/test/specHelper' import type { LocationChange } from '../src/browser/locationChangeObservable' @@ -98,8 +98,8 @@ export function setup(): TestSetupBuilder { selectInForegroundPeriodsFor: () => undefined, stop: noop, } - const globalContextManager = createContextManager(CustomerDataType.GlobalContext) - const userContextManager = createContextManager(CustomerDataType.User) + const globalContextManager = createContextManager() + const userContextManager = createContextManager() const pageStateHistory: PageStateHistory = { findAll: () => undefined, stop: noop, From 0b18707cc4e4d3c3c911c1078cbb55ae25fd7d8d Mon Sep 17 00:00:00 2001 From: Bastien Caudan <1331991+bcaudan@users.noreply.github.com> Date: Wed, 29 Mar 2023 10:05:07 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F[RUMF-1517]=20add=20test?= =?UTF-8?q?=20index=20files=20(#2115)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ♻️ add core/test/index * ♻️ add rum-core/test/index * ♻️ add rum/test/index --- .../core/src/browser/addEventListener.spec.ts | 2 +- .../core/src/browser/fetchObservable.spec.ts | 4 ++-- .../src/browser/pageExitObservable.spec.ts | 2 +- packages/core/src/browser/timer.spec.ts | 5 ++--- .../core/src/browser/xhrObservable.spec.ts | 2 +- .../configuration/endpointBuilder.spec.ts | 2 +- .../domain/report/reportObservable.spec.ts | 2 +- .../domain/session/sessionCookieStore.spec.ts | 2 +- .../src/domain/session/sessionManager.spec.ts | 4 ++-- .../src/domain/session/sessionStore.spec.ts | 4 ++-- .../synthetics/syntheticsWorkerValues.spec.ts | 2 +- .../domain/tracekit/computeStackTrace.spec.ts | 4 ++-- .../core/src/domain/tracekit/tracekit.spec.ts | 2 +- .../core/src/tools/contextHistory.spec.ts | 4 ++-- .../src/tools/createEventRateLimiter.spec.ts | 4 ++-- .../src/tools/getZoneJsOriginalValue.spec.ts | 2 +- .../core/src/tools/instrumentMethod.spec.ts | 5 ++--- packages/core/src/tools/urlPolyfill.spec.ts | 2 +- packages/core/src/tools/utils.spec.ts | 4 ++-- .../core/src/transport/eventBridge.spec.ts | 2 +- .../core/src/transport/httpRequest.spec.ts | 5 ++--- .../transport/sendWithRetryStrategy.spec.ts | 4 ++-- packages/core/test/index.ts | 6 ++++++ packages/logs/src/boot/logsPublicApi.spec.ts | 4 ++-- packages/logs/src/boot/startLogs.spec.ts | 13 ++++++------ packages/logs/src/domain/assembly.spec.ts | 5 ++--- .../logger/loggerCollection.spec.ts | 4 ++-- .../networkErrorCollection.spec.ts | 4 ++-- .../report/reportCollection.spec.ts | 2 +- .../src/domain/logsSessionManager.spec.ts | 4 ++-- .../rum-core/src/boot/rumPublicApi.spec.ts | 13 +++++++----- packages/rum-core/src/boot/startRum.spec.ts | 9 +++----- .../src/browser/domMutationObservable.spec.ts | 2 +- .../browser/locationChangeObservable.spec.ts | 2 +- .../src/browser/performanceCollection.spec.ts | 4 ++-- .../src/browser/viewportObservable.spec.ts | 4 ++-- packages/rum-core/src/domain/assembly.spec.ts | 21 ++++++++++++------- .../src/domain/contexts/ciTestContext.spec.ts | 5 +---- .../src/domain/contexts/commonContext.spec.ts | 2 +- .../contexts/featureFlagContext.spec.ts | 4 ++-- .../contexts/foregroundContexts.spec.ts | 6 +++--- .../domain/contexts/internalContext.spec.ts | 5 ++--- .../domain/contexts/pageStateHistory.spec.ts | 4 ++-- .../domain/contexts/syntheticsContext.spec.ts | 2 +- .../src/domain/contexts/urlContexts.spec.ts | 4 ++-- .../src/domain/contexts/viewContexts.spec.ts | 4 ++-- .../src/domain/requestCollection.spec.ts | 4 ++-- .../action/actionCollection.spec.ts | 6 +++--- .../action/clickChain.spec.ts | 6 +++--- .../action/computeFrustration.spec.ts | 10 ++++----- .../action/getActionNameFromElement.spec.ts | 4 ++-- .../action/getSelectorFromElement.spec.ts | 4 ++-- .../action/listenActionEvents.spec.ts | 2 +- .../action/trackClickActions.spec.ts | 7 +++---- .../error/errorCollection.spec.ts | 4 ++-- .../error/trackConsoleError.spec.ts | 4 ++-- .../error/trackReportError.spec.ts | 5 ++--- .../longTask/longTaskCollection.spec.ts | 6 ++---- .../resource/matchRequestTiming.spec.ts | 2 +- .../resource/resourceCollection.spec.ts | 6 ++---- .../resource/resourceUtils.spec.ts | 2 +- .../view/setupViewTest.specHelper.ts | 2 +- .../view/trackFirstHidden.spec.ts | 2 +- .../view/trackInitialViewTimings.spec.ts | 6 +++--- .../view/trackViewEventCounts.spec.ts | 4 ++-- .../view/trackViewMetrics.spec.ts | 4 ++-- .../view/trackViews.spec.ts | 4 ++-- .../view/viewCollection.spec.ts | 5 ++--- .../src/domain/rumSessionManager.spec.ts | 4 ++-- .../domain/startCustomerDataTelemetry.spec.ts | 4 ++-- .../src/domain/tracing/tracer.spec.ts | 6 ++---- .../src/domain/waitPageActivityEnd.spec.ts | 8 +++---- packages/rum-core/test/createFakeClick.ts | 2 +- packages/rum-core/test/index.ts | 8 +++++++ packages/rum-core/test/testSetupBuilder.ts | 4 ++-- packages/rum/src/boot/recorderApi.spec.ts | 8 +++---- packages/rum/src/boot/startRecording.spec.ts | 11 ++++------ .../src/domain/record/mutationBatch.spec.ts | 2 +- .../record/observers/inputObserver.spec.ts | 4 ++-- .../mouseInteractionObserver.spec.ts | 4 ++-- .../record/observers/moveObserver.spec.ts | 4 ++-- .../record/observers/mutationObserver.spec.ts | 4 ++-- .../observers/styleSheetObserver.spec.ts | 4 ++-- packages/rum/src/domain/record/record.spec.ts | 7 +++---- .../serialization/serializeNode.spec.ts | 6 +++--- .../serializeStyleSheets.spec.ts | 2 +- .../domain/segmentCollection/segment.spec.ts | 2 +- .../segmentCollection.spec.ts | 8 +++---- .../startDeflateWorker.spec.ts | 2 +- packages/rum/test/index.ts | 1 + .../scenario/recorder/recorder.scenario.ts | 2 +- .../scenario/recorder/shadowDom.scenario.ts | 8 +++---- .../scenario/recorder/viewports.scenario.ts | 2 +- 93 files changed, 208 insertions(+), 210 deletions(-) create mode 100644 packages/core/test/index.ts create mode 100644 packages/rum-core/test/index.ts create mode 100644 packages/rum/test/index.ts diff --git a/packages/core/src/browser/addEventListener.spec.ts b/packages/core/src/browser/addEventListener.spec.ts index ce4295ec56..1d94391955 100644 --- a/packages/core/src/browser/addEventListener.spec.ts +++ b/packages/core/src/browser/addEventListener.spec.ts @@ -1,4 +1,4 @@ -import { stubZoneJs } from '../../test/stubZoneJs' +import { stubZoneJs } from '../../test' import { noop } from '../tools/utils' import { addEventListener, DOM_EVENT } from './addEventListener' diff --git a/packages/core/src/browser/fetchObservable.spec.ts b/packages/core/src/browser/fetchObservable.spec.ts index 4c6f760ac2..18d61dafd0 100644 --- a/packages/core/src/browser/fetchObservable.spec.ts +++ b/packages/core/src/browser/fetchObservable.spec.ts @@ -1,5 +1,5 @@ -import type { FetchStub, FetchStubManager, FetchStubPromise } from '../../test/specHelper' -import { stubFetch } from '../../test/specHelper' +import type { FetchStub, FetchStubManager, FetchStubPromise } from '../../test' +import { stubFetch } from '../../test' import { isIE } from '../tools/browserDetection' import type { Subscription } from '../tools/observable' import type { FetchResolveContext, FetchContext } from './fetchObservable' diff --git a/packages/core/src/browser/pageExitObservable.spec.ts b/packages/core/src/browser/pageExitObservable.spec.ts index ec6274e686..aa534078b6 100644 --- a/packages/core/src/browser/pageExitObservable.spec.ts +++ b/packages/core/src/browser/pageExitObservable.spec.ts @@ -1,4 +1,4 @@ -import { createNewEvent, restorePageVisibility, setPageVisibility } from '../../test/specHelper' +import { createNewEvent, restorePageVisibility, setPageVisibility } from '../../test' import { resetExperimentalFeatures, updateExperimentalFeatures } from '../domain/configuration' import type { Subscription } from '../tools/observable' import type { PageExitEvent } from './pageExitObservable' diff --git a/packages/core/src/browser/timer.spec.ts b/packages/core/src/browser/timer.spec.ts index b66c84ddb2..c1f6ea8b94 100644 --- a/packages/core/src/browser/timer.spec.ts +++ b/packages/core/src/browser/timer.spec.ts @@ -1,6 +1,5 @@ -import { stubZoneJs } from '../../test/stubZoneJs' -import type { Clock } from '../../test/specHelper' -import { mockClock } from '../../test/specHelper' +import { mockClock, stubZoneJs } from '../../test' +import type { Clock } from '../../test' import { noop } from '../tools/utils' import { resetMonitor, startMonitorErrorCollection } from '../tools/monitor' import { setTimeout, clearTimeout, setInterval, clearInterval } from './timer' diff --git a/packages/core/src/browser/xhrObservable.spec.ts b/packages/core/src/browser/xhrObservable.spec.ts index fac252c625..1391c7d8d2 100644 --- a/packages/core/src/browser/xhrObservable.spec.ts +++ b/packages/core/src/browser/xhrObservable.spec.ts @@ -1,4 +1,4 @@ -import { stubXhr, withXhr } from '../../test/specHelper' +import { withXhr, stubXhr } from '../../test' import { isIE } from '../tools/browserDetection' import type { Subscription } from '../tools/observable' import type { XhrCompleteContext, XhrContext } from './xhrObservable' diff --git a/packages/core/src/domain/configuration/endpointBuilder.spec.ts b/packages/core/src/domain/configuration/endpointBuilder.spec.ts index f70cc6b78f..f5813cc319 100644 --- a/packages/core/src/domain/configuration/endpointBuilder.spec.ts +++ b/packages/core/src/domain/configuration/endpointBuilder.spec.ts @@ -1,4 +1,4 @@ -import type { BuildEnvWindow } from '../../../test/specHelper' +import type { BuildEnvWindow } from '../../../test' import { startsWith } from '../../tools/utils' import type { InitConfiguration } from './configuration' import { createEndpointBuilder } from './endpointBuilder' diff --git a/packages/core/src/domain/report/reportObservable.spec.ts b/packages/core/src/domain/report/reportObservable.spec.ts index 9866b09f6a..a6142382d5 100644 --- a/packages/core/src/domain/report/reportObservable.spec.ts +++ b/packages/core/src/domain/report/reportObservable.spec.ts @@ -1,5 +1,5 @@ +import { stubReportingObserver, stubCspEventListener } from '../../../test' import type { Subscription } from '../../tools/observable' -import { stubReportingObserver, stubCspEventListener } from '../../../test/stubReportApis' import { initReportObservable, RawReportType } from './reportObservable' describe('report observable', () => { diff --git a/packages/core/src/domain/session/sessionCookieStore.spec.ts b/packages/core/src/domain/session/sessionCookieStore.spec.ts index 8ec1a65b23..74d06b1deb 100644 --- a/packages/core/src/domain/session/sessionCookieStore.spec.ts +++ b/packages/core/src/domain/session/sessionCookieStore.spec.ts @@ -1,4 +1,4 @@ -import { stubCookie, mockClock } from '../../../test/specHelper' +import { mockClock, stubCookie } from '../../../test' import { isChromium } from '../../tools/browserDetection' import { SESSION_COOKIE_NAME, diff --git a/packages/core/src/domain/session/sessionManager.spec.ts b/packages/core/src/domain/session/sessionManager.spec.ts index 77b94e45b9..50f62249ba 100644 --- a/packages/core/src/domain/session/sessionManager.spec.ts +++ b/packages/core/src/domain/session/sessionManager.spec.ts @@ -1,7 +1,7 @@ +import { createNewEvent, mockClock, restorePageVisibility, setPageVisibility } from '../../../test' +import type { Clock } from '../../../test' import type { CookieOptions } from '../../browser/cookie' import { COOKIE_ACCESS_DELAY, getCookie, setCookie } from '../../browser/cookie' -import type { Clock } from '../../../test/specHelper' -import { mockClock, restorePageVisibility, setPageVisibility, createNewEvent } from '../../../test/specHelper' import { ONE_HOUR, ONE_SECOND } from '../../tools/utils' import type { RelativeTime } from '../../tools/timeUtils' import { isIE } from '../../tools/browserDetection' diff --git a/packages/core/src/domain/session/sessionStore.spec.ts b/packages/core/src/domain/session/sessionStore.spec.ts index b4c8b4e068..a4123e9b06 100644 --- a/packages/core/src/domain/session/sessionStore.spec.ts +++ b/packages/core/src/domain/session/sessionStore.spec.ts @@ -1,5 +1,5 @@ -import type { Clock } from '../../../test/specHelper' -import { mockClock } from '../../../test/specHelper' +import type { Clock } from '../../../test' +import { mockClock } from '../../../test' import type { CookieOptions } from '../../browser/cookie' import { getCookie, setCookie, COOKIE_ACCESS_DELAY } from '../../browser/cookie' import type { SessionStore } from './sessionStore' diff --git a/packages/core/src/domain/synthetics/syntheticsWorkerValues.spec.ts b/packages/core/src/domain/synthetics/syntheticsWorkerValues.spec.ts index 6689fcb71b..30a4d70abc 100644 --- a/packages/core/src/domain/synthetics/syntheticsWorkerValues.spec.ts +++ b/packages/core/src/domain/synthetics/syntheticsWorkerValues.spec.ts @@ -1,4 +1,4 @@ -import { mockSyntheticsWorkerValues, cleanupSyntheticsWorkerValues } from '../../../test/syntheticsWorkerValues' +import { mockSyntheticsWorkerValues, cleanupSyntheticsWorkerValues } from '../../../test' import { getSyntheticsResultId, getSyntheticsTestId, willSyntheticsInjectRum } from './syntheticsWorkerValues' describe('syntheticsWorkerValues', () => { diff --git a/packages/core/src/domain/tracekit/computeStackTrace.spec.ts b/packages/core/src/domain/tracekit/computeStackTrace.spec.ts index 84920d220a..2426ddeb2e 100644 --- a/packages/core/src/domain/tracekit/computeStackTrace.spec.ts +++ b/packages/core/src/domain/tracekit/computeStackTrace.spec.ts @@ -1,5 +1,5 @@ -import { isSafari } from '../../../test/specHelper' -import * as CapturedExceptions from '../../../test/capturedExceptions' +import * as CapturedExceptions from '../../../test' +import { isSafari } from '../../../test' import { computeStackTrace } from './computeStackTrace' describe('computeStackTrace', () => { diff --git a/packages/core/src/domain/tracekit/tracekit.spec.ts b/packages/core/src/domain/tracekit/tracekit.spec.ts index 1afb9d6c66..f0a3780c83 100644 --- a/packages/core/src/domain/tracekit/tracekit.spec.ts +++ b/packages/core/src/domain/tracekit/tracekit.spec.ts @@ -1,4 +1,4 @@ -import { disableJasmineUncaughtErrorHandler } from '../../../test/specHelper' +import { disableJasmineUncaughtErrorHandler } from '../../../test' import { startUnhandledErrorCollection } from './tracekit' import type { UnhandledErrorCallback } from './types' diff --git a/packages/core/src/tools/contextHistory.spec.ts b/packages/core/src/tools/contextHistory.spec.ts index 46d8e18a7c..957979213b 100644 --- a/packages/core/src/tools/contextHistory.spec.ts +++ b/packages/core/src/tools/contextHistory.spec.ts @@ -1,5 +1,5 @@ -import type { Clock } from '../../test/specHelper' -import { mockClock } from '../../test/specHelper' +import type { Clock } from '../../test' +import { mockClock } from '../../test' import type { Duration, RelativeTime } from './timeUtils' import { addDuration } from './timeUtils' import { ONE_MINUTE } from './utils' diff --git a/packages/core/src/tools/createEventRateLimiter.spec.ts b/packages/core/src/tools/createEventRateLimiter.spec.ts index 9c73d0171a..1620f86683 100644 --- a/packages/core/src/tools/createEventRateLimiter.spec.ts +++ b/packages/core/src/tools/createEventRateLimiter.spec.ts @@ -1,5 +1,5 @@ -import type { Clock } from '../../test/specHelper' -import { mockClock } from '../../test/specHelper' +import type { Clock } from '../../test' +import { mockClock } from '../../test' import type { RawError } from './error' import type { EventRateLimiter } from './createEventRateLimiter' import { createEventRateLimiter } from './createEventRateLimiter' diff --git a/packages/core/src/tools/getZoneJsOriginalValue.spec.ts b/packages/core/src/tools/getZoneJsOriginalValue.spec.ts index 88850387bc..dbfb5ecb8a 100644 --- a/packages/core/src/tools/getZoneJsOriginalValue.spec.ts +++ b/packages/core/src/tools/getZoneJsOriginalValue.spec.ts @@ -1,4 +1,4 @@ -import { stubZoneJs } from '../../test/stubZoneJs' +import { stubZoneJs } from '../../test' import type { BrowserWindowWithZoneJs } from './getZoneJsOriginalValue' import { getZoneJsOriginalValue } from './getZoneJsOriginalValue' diff --git a/packages/core/src/tools/instrumentMethod.spec.ts b/packages/core/src/tools/instrumentMethod.spec.ts index 47c02445f5..9130428521 100644 --- a/packages/core/src/tools/instrumentMethod.spec.ts +++ b/packages/core/src/tools/instrumentMethod.spec.ts @@ -1,6 +1,5 @@ -import { stubZoneJs } from '../../test/stubZoneJs' -import type { Clock } from '../../test/specHelper' -import { mockClock } from '../../test/specHelper' +import { mockClock, stubZoneJs } from '../../test' +import type { Clock } from '../../test' import { instrumentMethod, instrumentSetter } from './instrumentMethod' import { noop } from './utils' diff --git a/packages/core/src/tools/urlPolyfill.spec.ts b/packages/core/src/tools/urlPolyfill.spec.ts index 7ec669abba..8aca707c52 100644 --- a/packages/core/src/tools/urlPolyfill.spec.ts +++ b/packages/core/src/tools/urlPolyfill.spec.ts @@ -1,4 +1,4 @@ -import { isFirefox } from '../../test/specHelper' +import { isFirefox } from '../../test' import { getHash, getOrigin, getPathName, getSearch, isValidUrl, normalizeUrl } from './urlPolyfill' import { getLocationOrigin } from './utils' diff --git a/packages/core/src/tools/utils.spec.ts b/packages/core/src/tools/utils.spec.ts index 92d40dc874..5264ed648c 100644 --- a/packages/core/src/tools/utils.spec.ts +++ b/packages/core/src/tools/utils.spec.ts @@ -1,5 +1,5 @@ -import type { Clock } from '../../test/specHelper' -import { mockClock } from '../../test/specHelper' +import type { Clock } from '../../test' +import { mockClock } from '../../test' import { display } from './display' import { arrayFrom, diff --git a/packages/core/src/transport/eventBridge.spec.ts b/packages/core/src/transport/eventBridge.spec.ts index 13e6260a3f..a9d3e2bfdb 100644 --- a/packages/core/src/transport/eventBridge.spec.ts +++ b/packages/core/src/transport/eventBridge.spec.ts @@ -1,4 +1,4 @@ -import { deleteEventBridgeStub, initEventBridgeStub } from '../../test/specHelper' +import { deleteEventBridgeStub, initEventBridgeStub } from '../../test' import { getEventBridge, canUseEventBridge } from './eventBridge' describe('canUseEventBridge', () => { diff --git a/packages/core/src/transport/httpRequest.spec.ts b/packages/core/src/transport/httpRequest.spec.ts index f3551e538f..354608ad46 100644 --- a/packages/core/src/transport/httpRequest.spec.ts +++ b/packages/core/src/transport/httpRequest.spec.ts @@ -1,9 +1,8 @@ -import { stubEndpointBuilder, interceptRequests } from '../../test/specHelper' -import type { Request } from '../../test/specHelper' +import { collectAsyncCalls, stubEndpointBuilder, interceptRequests } from '../../test' +import type { Request } from '../../test' import type { EndpointBuilder } from '../domain/configuration' import { createEndpointBuilder } from '../domain/configuration' import { noop } from '../tools/utils' -import { collectAsyncCalls } from '../../test/collectAsyncCalls' import { createHttpRequest, fetchKeepAliveStrategy, sendXHR } from './httpRequest' import type { HttpRequest } from './httpRequest' diff --git a/packages/core/src/transport/sendWithRetryStrategy.spec.ts b/packages/core/src/transport/sendWithRetryStrategy.spec.ts index 80978d4f0a..a4e62641e7 100644 --- a/packages/core/src/transport/sendWithRetryStrategy.spec.ts +++ b/packages/core/src/transport/sendWithRetryStrategy.spec.ts @@ -1,5 +1,5 @@ -import { mockClock, restoreNavigatorOnLine, setNavigatorOnLine } from '../../test/specHelper' -import type { Clock } from '../../test/specHelper' +import { mockClock, restoreNavigatorOnLine, setNavigatorOnLine } from '../../test' +import type { Clock } from '../../test' import { ErrorSource } from '../tools/error' import type { RetryState } from './sendWithRetryStrategy' import { diff --git a/packages/core/test/index.ts b/packages/core/test/index.ts new file mode 100644 index 0000000000..38a780b548 --- /dev/null +++ b/packages/core/test/index.ts @@ -0,0 +1,6 @@ +export * from './capturedExceptions' +export * from './collectAsyncCalls' +export * from './stubReportApis' +export * from './stubZoneJs' +export * from './syntheticsWorkerValues' +export * from './specHelper' diff --git a/packages/logs/src/boot/logsPublicApi.spec.ts b/packages/logs/src/boot/logsPublicApi.spec.ts index 86b29ee22f..b383e68f98 100644 --- a/packages/logs/src/boot/logsPublicApi.spec.ts +++ b/packages/logs/src/boot/logsPublicApi.spec.ts @@ -1,7 +1,7 @@ import type { TimeStamp } from '@datadog/browser-core' import { monitor, ONE_SECOND, display } from '@datadog/browser-core' -import type { Clock } from '../../../core/test/specHelper' -import { deleteEventBridgeStub, initEventBridgeStub, mockClock } from '../../../core/test/specHelper' +import type { Clock } from '@datadog/browser-core/test' +import { deleteEventBridgeStub, initEventBridgeStub, mockClock } from '@datadog/browser-core/test' import type { HybridInitConfiguration, LogsInitConfiguration } from '../domain/configuration' import type { Logger, LogsMessage } from '../domain/logger' import { HandlerType, StatusType } from '../domain/logger' diff --git a/packages/logs/src/boot/startLogs.spec.ts b/packages/logs/src/boot/startLogs.spec.ts index ba93f2d582..3c0b482007 100644 --- a/packages/logs/src/boot/startLogs.spec.ts +++ b/packages/logs/src/boot/startLogs.spec.ts @@ -1,15 +1,16 @@ import { ErrorSource, display, stopSessionManager, getCookie, SESSION_COOKIE_NAME } from '@datadog/browser-core' -import { cleanupSyntheticsWorkerValues, mockSyntheticsWorkerValues } from '../../../core/test/syntheticsWorkerValues' +import type { Request } from '@datadog/browser-core/test' import { + interceptRequests, + stubEndpointBuilder, deleteEventBridgeStub, initEventBridgeStub, - stubEndpointBuilder, - interceptRequests, -} from '../../../core/test/specHelper' -import type { Request } from '../../../core/test/specHelper' + cleanupSyntheticsWorkerValues, + mockSyntheticsWorkerValues, +} from '@datadog/browser-core/test' + import type { LogsConfiguration } from '../domain/configuration' import { validateAndBuildLogsConfiguration } from '../domain/configuration' - import { HandlerType, Logger, StatusType } from '../domain/logger' import type { startLoggerCollection } from '../domain/logsCollection/logger/loggerCollection' import type { LogsEvent } from '../logsEvent.types' diff --git a/packages/logs/src/domain/assembly.spec.ts b/packages/logs/src/domain/assembly.spec.ts index dc11fd543e..89784aa38b 100644 --- a/packages/logs/src/domain/assembly.spec.ts +++ b/packages/logs/src/domain/assembly.spec.ts @@ -1,9 +1,8 @@ import type { Context, RelativeTime, TelemetryEvent, TimeStamp } from '@datadog/browser-core' import { TelemetryService, startTelemetry, ErrorSource, ONE_MINUTE, getTimeStamp, noop } from '@datadog/browser-core' -import { cleanupSyntheticsWorkerValues, mockSyntheticsWorkerValues } from '../../../core/test/syntheticsWorkerValues' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock, cleanupSyntheticsWorkerValues, mockSyntheticsWorkerValues } from '@datadog/browser-core/test' import type { LogsEvent } from '../logsEvent.types' -import type { Clock } from '../../../core/test/specHelper' -import { mockClock } from '../../../core/test/specHelper' import type { CommonContext } from '../rawLogsEvent.types' import { getRUMInternalContext, resetRUMInternalContext, startLogsAssembly } from './assembly' import { validateAndBuildLogsConfiguration } from './configuration' diff --git a/packages/logs/src/domain/logsCollection/logger/loggerCollection.spec.ts b/packages/logs/src/domain/logsCollection/logger/loggerCollection.spec.ts index 6023ceeb0a..b59d1f37c0 100644 --- a/packages/logs/src/domain/logsCollection/logger/loggerCollection.spec.ts +++ b/packages/logs/src/domain/logsCollection/logger/loggerCollection.spec.ts @@ -1,7 +1,7 @@ import type { TimeStamp } from '@datadog/browser-core' import { ConsoleApiName, timeStampNow, display, ErrorSource } from '@datadog/browser-core' -import type { Clock } from '@datadog/browser-core/test/specHelper' -import { mockClock } from '@datadog/browser-core/test/specHelper' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock } from '@datadog/browser-core/test' import type { CommonContext, RawLoggerLogsEvent } from '../../../rawLogsEvent.types' import type { RawLogsEventCollectedData } from '../../lifeCycle' import { LifeCycle, LifeCycleEventType } from '../../lifeCycle' diff --git a/packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.spec.ts b/packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.spec.ts index 3701746b11..44cfa550d5 100644 --- a/packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.spec.ts +++ b/packages/logs/src/domain/logsCollection/networkError/networkErrorCollection.spec.ts @@ -1,6 +1,6 @@ import { isIE, ErrorSource } from '@datadog/browser-core' -import type { FetchStub, FetchStubManager } from '@datadog/browser-core/test/specHelper' -import { SPEC_ENDPOINTS, ResponseStub, stubFetch } from '@datadog/browser-core/test/specHelper' +import type { FetchStub, FetchStubManager } from '@datadog/browser-core/test' +import { SPEC_ENDPOINTS, ResponseStub, stubFetch } from '@datadog/browser-core/test' import type { RawNetworkLogsEvent } from '../../../rawLogsEvent.types' import type { LogsConfiguration } from '../../configuration' import type { RawLogsEventCollectedData } from '../../lifeCycle' diff --git a/packages/logs/src/domain/logsCollection/report/reportCollection.spec.ts b/packages/logs/src/domain/logsCollection/report/reportCollection.spec.ts index 97463d2e50..5b5a4e0610 100644 --- a/packages/logs/src/domain/logsCollection/report/reportCollection.spec.ts +++ b/packages/logs/src/domain/logsCollection/report/reportCollection.spec.ts @@ -1,5 +1,5 @@ import { ErrorSource, noop } from '@datadog/browser-core' -import { stubReportingObserver } from '@datadog/browser-core/test/stubReportApis' +import { stubReportingObserver } from '@datadog/browser-core/test' import type { RawReportLogsEvent } from '../../../rawLogsEvent.types' import { validateAndBuildLogsConfiguration } from '../../configuration' import type { RawLogsEventCollectedData } from '../../lifeCycle' diff --git a/packages/logs/src/domain/logsSessionManager.spec.ts b/packages/logs/src/domain/logsSessionManager.spec.ts index 4d3f32f712..14d51be950 100644 --- a/packages/logs/src/domain/logsSessionManager.spec.ts +++ b/packages/logs/src/domain/logsSessionManager.spec.ts @@ -7,8 +7,8 @@ import { stopSessionManager, ONE_SECOND, } from '@datadog/browser-core' -import type { Clock } from '../../../core/test/specHelper' -import { mockClock } from '../../../core/test/specHelper' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock } from '@datadog/browser-core/test' import type { LogsConfiguration } from './configuration' import { diff --git a/packages/rum-core/src/boot/rumPublicApi.spec.ts b/packages/rum-core/src/boot/rumPublicApi.spec.ts index 64a62d3bf3..455f13fdd6 100644 --- a/packages/rum-core/src/boot/rumPublicApi.spec.ts +++ b/packages/rum-core/src/boot/rumPublicApi.spec.ts @@ -1,12 +1,15 @@ import type { RelativeTime, TimeStamp, Context } from '@datadog/browser-core' import { ONE_SECOND, getTimeStamp, display, DefaultPrivacyLevel } from '@datadog/browser-core' -import { cleanupSyntheticsWorkerValues, mockSyntheticsWorkerValues } from '../../../core/test/syntheticsWorkerValues' -import { initEventBridgeStub, deleteEventBridgeStub } from '../../../core/test/specHelper' -import type { TestSetupBuilder } from '../../test/testSetupBuilder' -import { setup } from '../../test/testSetupBuilder' +import { + initEventBridgeStub, + deleteEventBridgeStub, + cleanupSyntheticsWorkerValues, + mockSyntheticsWorkerValues, +} from '@datadog/browser-core/test' +import type { TestSetupBuilder } from '../../test' +import { setup, noopRecorderApi } from '../../test' import type { HybridInitConfiguration, RumInitConfiguration } from '../domain/configuration' import { ActionType } from '../rawRumEvent.types' -import { noopRecorderApi } from '../../test/noopRecorderApi' import type { RumPublicApi, StartRum, RecorderApi } from './rumPublicApi' import { makeRumPublicApi } from './rumPublicApi' diff --git a/packages/rum-core/src/boot/startRum.spec.ts b/packages/rum-core/src/boot/startRum.spec.ts index 829146c6c3..dd5dd2fdba 100644 --- a/packages/rum-core/src/boot/startRum.spec.ts +++ b/packages/rum-core/src/boot/startRum.spec.ts @@ -9,11 +9,9 @@ import { relativeNow, isIE, } from '@datadog/browser-core' -import { createNewEvent, interceptRequests } from '../../../core/test/specHelper' -import type { RumSessionManagerMock } from '../../test/mockRumSessionManager' -import { createRumSessionManagerMock } from '../../test/mockRumSessionManager' -import type { TestSetupBuilder } from '../../test/testSetupBuilder' -import { setup } from '../../test/testSetupBuilder' +import { createNewEvent, interceptRequests } from '@datadog/browser-core/test' +import type { RumSessionManagerMock, TestSetupBuilder } from '../../test' +import { createRumSessionManagerMock, noopRecorderApi, setup } from '../../test' import type { RumPerformanceNavigationTiming, RumPerformanceEntry } from '../browser/performanceCollection' import type { LifeCycle } from '../domain/lifeCycle' import { LifeCycleEventType } from '../domain/lifeCycle' @@ -26,7 +24,6 @@ import type { RumSessionManager } from '..' import type { RumConfiguration, RumInitConfiguration } from '../domain/configuration' import { RumEventType } from '../rawRumEvent.types' import { startFeatureFlagContexts } from '../domain/contexts/featureFlagContext' -import { noopRecorderApi } from '../../test/noopRecorderApi' import { startRum, startRumEventCollection } from './startRum' function collectServerEvents(lifeCycle: LifeCycle) { diff --git a/packages/rum-core/src/browser/domMutationObservable.spec.ts b/packages/rum-core/src/browser/domMutationObservable.spec.ts index a78973dd28..759c700836 100644 --- a/packages/rum-core/src/browser/domMutationObservable.spec.ts +++ b/packages/rum-core/src/browser/domMutationObservable.spec.ts @@ -1,5 +1,5 @@ import { isIE } from '@datadog/browser-core' -import { stubZoneJs } from '../../../core/test/stubZoneJs' +import { stubZoneJs } from '@datadog/browser-core/test' import { createDOMMutationObservable, getMutationObserverConstructor } from './domMutationObservable' // The MutationObserver invokes its callback in an event loop microtask, making this asynchronous. diff --git a/packages/rum-core/src/browser/locationChangeObservable.spec.ts b/packages/rum-core/src/browser/locationChangeObservable.spec.ts index ad03cdb6e2..3c3dbf6788 100644 --- a/packages/rum-core/src/browser/locationChangeObservable.spec.ts +++ b/packages/rum-core/src/browser/locationChangeObservable.spec.ts @@ -1,5 +1,5 @@ import type { Observable, Subscription } from '@datadog/browser-core' -import { mockLocation } from '../../../core/test/specHelper' +import { mockLocation } from '@datadog/browser-core/test' import type { LocationChange } from './locationChangeObservable' import { createLocationChangeObservable } from './locationChangeObservable' diff --git a/packages/rum-core/src/browser/performanceCollection.spec.ts b/packages/rum-core/src/browser/performanceCollection.spec.ts index 2b9360b330..af56a4029f 100644 --- a/packages/rum-core/src/browser/performanceCollection.spec.ts +++ b/packages/rum-core/src/browser/performanceCollection.spec.ts @@ -1,5 +1,5 @@ -import type { TestSetupBuilder } from '../../test/testSetupBuilder' -import { setup } from '../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../test' +import { setup } from '../../test' import { retrieveInitialDocumentResourceTiming, startPerformanceCollection } from './performanceCollection' describe('rum initial document resource', () => { diff --git a/packages/rum-core/src/browser/viewportObservable.spec.ts b/packages/rum-core/src/browser/viewportObservable.spec.ts index 02df2617f1..2ea15be26e 100644 --- a/packages/rum-core/src/browser/viewportObservable.spec.ts +++ b/packages/rum-core/src/browser/viewportObservable.spec.ts @@ -1,6 +1,6 @@ -import type { Clock } from '@datadog/browser-core/test/specHelper' -import { createNewEvent, mockClock } from '@datadog/browser-core/test/specHelper' import type { Subscription } from '@datadog/browser-core/src/tools/observable' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock, createNewEvent } from '@datadog/browser-core/test' import type { ViewportDimension } from './viewportObservable' import { getViewportDimension, initViewportObservable } from './viewportObservable' diff --git a/packages/rum-core/src/domain/assembly.spec.ts b/packages/rum-core/src/domain/assembly.spec.ts index dab6a5cf7a..db57c06a24 100644 --- a/packages/rum-core/src/domain/assembly.spec.ts +++ b/packages/rum-core/src/domain/assembly.spec.ts @@ -1,16 +1,23 @@ import type { RelativeTime } from '@datadog/browser-core' import { ErrorSource, ONE_MINUTE, display } from '@datadog/browser-core' -import { createRumSessionManagerMock } from '../../test/mockRumSessionManager' -import { createRawRumEvent } from '../../test/fixtures' -import type { TestSetupBuilder } from '../../test/testSetupBuilder' -import { setup } from '../../test/testSetupBuilder' +import { + initEventBridgeStub, + deleteEventBridgeStub, + cleanupSyntheticsWorkerValues, + mockSyntheticsWorkerValues, +} from '@datadog/browser-core/test' +import type { TestSetupBuilder } from '../../test' +import { + createRumSessionManagerMock, + mockCiVisibilityWindowValues, + setup, + createRawRumEvent, + cleanupCiVisibilityWindowValues, +} from '../../test' import type { RumEventDomainContext } from '../domainContext.types' import type { RawRumActionEvent, RawRumErrorEvent, RawRumEvent } from '../rawRumEvent.types' import { RumEventType } from '../rawRumEvent.types' import type { RumActionEvent, RumErrorEvent, RumEvent } from '../rumEvent.types' -import { initEventBridgeStub, deleteEventBridgeStub } from '../../../core/test/specHelper' -import { cleanupSyntheticsWorkerValues, mockSyntheticsWorkerValues } from '../../../core/test/syntheticsWorkerValues' -import { cleanupCiVisibilityWindowValues, mockCiVisibilityWindowValues } from '../../test/mockCiVisibilityWindowValues' import { startRumAssembly } from './assembly' import type { LifeCycle, RawRumEventCollectedData } from './lifeCycle' import { LifeCycleEventType } from './lifeCycle' diff --git a/packages/rum-core/src/domain/contexts/ciTestContext.spec.ts b/packages/rum-core/src/domain/contexts/ciTestContext.spec.ts index 4fac9fa668..8ee552533f 100644 --- a/packages/rum-core/src/domain/contexts/ciTestContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/ciTestContext.spec.ts @@ -1,7 +1,4 @@ -import { - cleanupCiVisibilityWindowValues, - mockCiVisibilityWindowValues, -} from '../../../test/mockCiVisibilityWindowValues' +import { cleanupCiVisibilityWindowValues, mockCiVisibilityWindowValues } from '../../../test' import { getCiTestContext } from './ciTestContext' describe('getCiTestContext', () => { diff --git a/packages/rum-core/src/domain/contexts/commonContext.spec.ts b/packages/rum-core/src/domain/contexts/commonContext.spec.ts index 1552bb27f2..210394ba7c 100644 --- a/packages/rum-core/src/domain/contexts/commonContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/commonContext.spec.ts @@ -1,7 +1,7 @@ import type { Context, ContextManager } from '@datadog/browser-core' import { createContextManager } from '@datadog/browser-core' import type { RecorderApi } from '../../boot/rumPublicApi' -import { noopRecorderApi } from '../../../test/noopRecorderApi' +import { noopRecorderApi } from '../../../test' import type { CommonContext } from './commonContext' import { buildCommonContext as buildCommonContextImpl } from './commonContext' diff --git a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts index 1f20b5816e..3f31e087d2 100644 --- a/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/featureFlagContext.spec.ts @@ -1,7 +1,7 @@ import type { RelativeTime } from '@datadog/browser-core' import { resetExperimentalFeatures, updateExperimentalFeatures, relativeToClocks } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../test/testSetupBuilder' -import { setup } from '../../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../../test' +import { setup } from '../../../test' import { LifeCycleEventType } from '../lifeCycle' import type { ViewCreatedEvent, ViewEndedEvent } from '../rumEventsCollection/view/trackViews' import type { FeatureFlagContexts } from './featureFlagContext' diff --git a/packages/rum-core/src/domain/contexts/foregroundContexts.spec.ts b/packages/rum-core/src/domain/contexts/foregroundContexts.spec.ts index 1f1bdae68e..1ee0b4be03 100644 --- a/packages/rum-core/src/domain/contexts/foregroundContexts.spec.ts +++ b/packages/rum-core/src/domain/contexts/foregroundContexts.spec.ts @@ -1,7 +1,7 @@ import type { RelativeTime, Duration, ServerDuration } from '@datadog/browser-core' import { relativeNow } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../test/testSetupBuilder' -import { setup } from '../../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../../test' +import { setup } from '../../../test' import type { ForegroundContexts } from './foregroundContexts' import { startForegroundContexts, @@ -58,7 +58,7 @@ describe('foreground context', () => { }) describe('with two closed focus period & one active one', () => { - /* + /* events F B F B F periods <------> <-------> <---- - - - time 0 5 10 15 20 25 30 35 40 45 diff --git a/packages/rum-core/src/domain/contexts/internalContext.spec.ts b/packages/rum-core/src/domain/contexts/internalContext.spec.ts index 578939bc64..209b253216 100644 --- a/packages/rum-core/src/domain/contexts/internalContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/internalContext.spec.ts @@ -1,7 +1,6 @@ import type { RelativeTime } from '@datadog/browser-core' -import { createRumSessionManagerMock } from '../../../test/mockRumSessionManager' -import type { TestSetupBuilder } from '../../../test/testSetupBuilder' -import { setup } from '../../../test/testSetupBuilder' +import { createRumSessionManagerMock, setup } from '../../../test' +import type { TestSetupBuilder } from '../../../test' import type { ActionContexts } from '../rumEventsCollection/action/actionCollection' import type { RumSessionManager } from '../rumSessionManager' import { startInternalContext } from './internalContext' diff --git a/packages/rum-core/src/domain/contexts/pageStateHistory.spec.ts b/packages/rum-core/src/domain/contexts/pageStateHistory.spec.ts index 2b67a55286..6a6cef4258 100644 --- a/packages/rum-core/src/domain/contexts/pageStateHistory.spec.ts +++ b/packages/rum-core/src/domain/contexts/pageStateHistory.spec.ts @@ -1,7 +1,7 @@ import type { RelativeTime } from '@datadog/browser-core' import { resetExperimentalFeatures } from '@datadog/browser-core' -import type { TestSetupBuilder } from 'packages/rum-core/test/testSetupBuilder' -import { setup } from '../../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../../test' +import { setup } from '../../../test' import type { PageStateHistory } from './pageStateHistory' import { resetPageStates, startPageStateHistory, addPageState, PageState } from './pageStateHistory' diff --git a/packages/rum-core/src/domain/contexts/syntheticsContext.spec.ts b/packages/rum-core/src/domain/contexts/syntheticsContext.spec.ts index ccab69ecb8..d22065d5db 100644 --- a/packages/rum-core/src/domain/contexts/syntheticsContext.spec.ts +++ b/packages/rum-core/src/domain/contexts/syntheticsContext.spec.ts @@ -1,4 +1,4 @@ -import { cleanupSyntheticsWorkerValues, mockSyntheticsWorkerValues } from '../../../../core/test/syntheticsWorkerValues' +import { cleanupSyntheticsWorkerValues, mockSyntheticsWorkerValues } from '../../../../core/test' import { getSyntheticsContext } from './syntheticsContext' describe('getSyntheticsContext', () => { diff --git a/packages/rum-core/src/domain/contexts/urlContexts.spec.ts b/packages/rum-core/src/domain/contexts/urlContexts.spec.ts index ade00e7feb..33dc4de96d 100644 --- a/packages/rum-core/src/domain/contexts/urlContexts.spec.ts +++ b/packages/rum-core/src/domain/contexts/urlContexts.spec.ts @@ -1,7 +1,7 @@ import type { RelativeTime } from '@datadog/browser-core' import { relativeToClocks } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../test/testSetupBuilder' -import { setup } from '../../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../../test' +import { setup } from '../../../test' import { LifeCycleEventType } from '../lifeCycle' import type { ViewCreatedEvent, ViewEndedEvent } from '../rumEventsCollection/view/trackViews' import type { UrlContexts } from './urlContexts' diff --git a/packages/rum-core/src/domain/contexts/viewContexts.spec.ts b/packages/rum-core/src/domain/contexts/viewContexts.spec.ts index da44b77ac7..11a5279036 100644 --- a/packages/rum-core/src/domain/contexts/viewContexts.spec.ts +++ b/packages/rum-core/src/domain/contexts/viewContexts.spec.ts @@ -1,7 +1,7 @@ import type { RelativeTime } from '@datadog/browser-core' import { relativeToClocks, CLEAR_OLD_CONTEXTS_INTERVAL } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../test/testSetupBuilder' -import { setup } from '../../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../../test' +import { setup } from '../../../test' import { LifeCycleEventType } from '../lifeCycle' import type { ViewCreatedEvent } from '../rumEventsCollection/view/trackViews' import type { ViewContexts } from './viewContexts' diff --git a/packages/rum-core/src/domain/requestCollection.spec.ts b/packages/rum-core/src/domain/requestCollection.spec.ts index b8baf3b292..d3713f406c 100644 --- a/packages/rum-core/src/domain/requestCollection.spec.ts +++ b/packages/rum-core/src/domain/requestCollection.spec.ts @@ -1,6 +1,6 @@ import { isIE, RequestType } from '@datadog/browser-core' -import type { FetchStub, FetchStubManager } from '../../../core/test/specHelper' -import { SPEC_ENDPOINTS, stubFetch, stubXhr, withXhr } from '../../../core/test/specHelper' +import type { FetchStub, FetchStubManager } from '@datadog/browser-core/test' +import { SPEC_ENDPOINTS, stubFetch, stubXhr, withXhr } from '@datadog/browser-core/test' import type { RumConfiguration } from './configuration' import { validateAndBuildRumConfiguration } from './configuration' import { LifeCycle, LifeCycleEventType } from './lifeCycle' diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.spec.ts index 03b6e0113a..a6b2ca4c77 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/action/actionCollection.spec.ts @@ -1,7 +1,7 @@ import type { Duration, RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core' -import { createNewEvent } from '../../../../../core/test/specHelper' -import type { TestSetupBuilder } from '../../../../test/testSetupBuilder' -import { setup } from '../../../../test/testSetupBuilder' +import { createNewEvent } from '@datadog/browser-core/test' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' import { RumEventType, ActionType } from '../../../rawRumEvent.types' import { LifeCycleEventType } from '../../lifeCycle' import { startActionCollection } from './actionCollection' diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/clickChain.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/action/clickChain.spec.ts index 6fac9da09b..ea933adee0 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/clickChain.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/action/clickChain.spec.ts @@ -1,6 +1,6 @@ -import type { Clock } from '@datadog/browser-core/test/specHelper' -import { mockClock } from '@datadog/browser-core/test/specHelper' -import { createFakeClick } from '../../../../test/createFakeClick' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock } from '@datadog/browser-core/test' +import { createFakeClick } from '../../../../test' import type { ClickChain } from './clickChain' import { MAX_DISTANCE_BETWEEN_CLICKS, MAX_DURATION_BETWEEN_CLICKS, createClickChain } from './clickChain' diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.spec.ts index a44a52f151..b19c1f52cb 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/action/computeFrustration.spec.ts @@ -1,11 +1,9 @@ import { ONE_SECOND } from '@datadog/browser-core' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock } from '@datadog/browser-core/test' import { FrustrationType } from '../../../rawRumEvent.types' -import type { Clock } from '../../../../../core/test/specHelper' -import { mockClock } from '../../../../../core/test/specHelper' -import type { FakeClick } from '../../../../test/createFakeClick' -import { createFakeClick } from '../../../../test/createFakeClick' -import type { IsolatedDom } from '../../../../test/createIsolatedDom' -import { createIsolatedDom } from '../../../../test/createIsolatedDom' +import type { FakeClick, IsolatedDom } from '../../../../test' +import { createFakeClick, createIsolatedDom } from '../../../../test' import { computeFrustration, isRage, isDead } from './computeFrustration' describe('computeFrustration', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/getActionNameFromElement.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/action/getActionNameFromElement.spec.ts index d8b6a6259c..443683295e 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/getActionNameFromElement.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/action/getActionNameFromElement.spec.ts @@ -1,5 +1,5 @@ -import type { IsolatedDom } from '../../../../test/createIsolatedDom' -import { createIsolatedDom } from '../../../../test/createIsolatedDom' +import type { IsolatedDom } from '../../../../test' +import { createIsolatedDom } from '../../../../test' import { getActionNameFromElement } from './getActionNameFromElement' describe('getActionNameFromElement', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/getSelectorFromElement.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/action/getSelectorFromElement.spec.ts index c087b04120..f4af021cdd 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/getSelectorFromElement.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/action/getSelectorFromElement.spec.ts @@ -1,5 +1,5 @@ -import type { IsolatedDom } from '../../../../test/createIsolatedDom' -import { createIsolatedDom } from '../../../../test/createIsolatedDom' +import type { IsolatedDom } from '../../../../test' +import { createIsolatedDom } from '../../../../test' import { getSelectorFromElement, supportScopeSelector } from './getSelectorFromElement' describe('getSelectorFromElement', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.spec.ts index 5e2a53288b..232412ab42 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/action/listenActionEvents.spec.ts @@ -1,4 +1,4 @@ -import { createNewEvent } from '../../../../../core/test/specHelper' +import { createNewEvent } from '@datadog/browser-core/test' import type { ActionEventsHooks } from './listenActionEvents' import { listenActionEvents } from './listenActionEvents' diff --git a/packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.spec.ts index a4b95742d2..30283d20df 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/action/trackClickActions.spec.ts @@ -7,14 +7,13 @@ import { timeStampNow, relativeNow, } from '@datadog/browser-core' -import { createNewEvent } from '../../../../../core/test/specHelper' -import type { TestSetupBuilder } from '../../../../test/testSetupBuilder' -import { setup } from '../../../../test/testSetupBuilder' +import { createNewEvent } from '@datadog/browser-core/test' +import type { TestSetupBuilder } from '../../../../test' +import { setup, createFakeClick } from '../../../../test' import { RumEventType, ActionType, FrustrationType } from '../../../rawRumEvent.types' import type { RumEvent } from '../../../rumEvent.types' import { LifeCycleEventType } from '../../lifeCycle' import { PAGE_ACTIVITY_VALIDATION_DELAY } from '../../waitPageActivityEnd' -import { createFakeClick } from '../../../../test/createFakeClick' import type { ActionContexts } from './actionCollection' import type { ClickAction } from './trackClickActions' import { finalizeClicks, CLICK_ACTION_MAX_DURATION, trackClickActions } from './trackClickActions' diff --git a/packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.spec.ts index e1c83c2890..3b3770a2fd 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/error/errorCollection.spec.ts @@ -1,7 +1,7 @@ import type { RelativeTime, TimeStamp, ErrorWithCause } from '@datadog/browser-core' import { ErrorHandling, ErrorSource } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../../test/testSetupBuilder' -import { setup } from '../../../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' import type { RawRumErrorEvent } from '../../../rawRumEvent.types' import { RumEventType } from '../../../rawRumEvent.types' import { LifeCycleEventType } from '../../lifeCycle' diff --git a/packages/rum-core/src/domain/rumEventsCollection/error/trackConsoleError.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/error/trackConsoleError.spec.ts index 67bcd0d840..9cbf21ff3a 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/error/trackConsoleError.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/error/trackConsoleError.spec.ts @@ -1,7 +1,7 @@ import type { RawError, Subscription } from '@datadog/browser-core' import { ErrorHandling, ErrorSource, Observable, clocksNow } from '@datadog/browser-core' -import type { Clock } from '../../../../../core/test/specHelper' -import { mockClock } from '../../../../../core/test/specHelper' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock } from '@datadog/browser-core/test' import { trackConsoleError } from './trackConsoleError' describe('trackConsoleError', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.spec.ts index 2afe69681d..8e13ceafb0 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/error/trackReportError.spec.ts @@ -1,8 +1,7 @@ import type { RawError, Subscription } from '@datadog/browser-core' import { ErrorHandling, ErrorSource, Observable, clocksNow } from '@datadog/browser-core' -import type { Clock } from '../../../../../core/test/specHelper' -import { mockClock } from '../../../../../core/test/specHelper' -import { stubReportingObserver } from '../../../../../core/test/stubReportApis' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock, stubReportingObserver } from '@datadog/browser-core/test' import { trackReportError } from './trackReportError' describe('trackReportError', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.spec.ts index 272bf23c42..c700d934e7 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/longTask/longTaskCollection.spec.ts @@ -1,8 +1,6 @@ import type { Duration, RelativeTime, ServerDuration } from '@datadog/browser-core' -import type { RumSessionManagerMock } from '../../../../test/mockRumSessionManager' -import { createRumSessionManagerMock } from '../../../../test/mockRumSessionManager' -import type { TestSetupBuilder } from '../../../../test/testSetupBuilder' -import { setup } from '../../../../test/testSetupBuilder' +import type { RumSessionManagerMock, TestSetupBuilder } from '../../../../test' +import { createRumSessionManagerMock, setup } from '../../../../test' import type { RumPerformanceEntry, RumPerformanceLongTaskTiming } from '../../../browser/performanceCollection' import { RumEventType } from '../../../rawRumEvent.types' import { LifeCycleEventType } from '../../lifeCycle' diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.spec.ts index c428d6ab5a..90fc7ee3a1 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/matchRequestTiming.spec.ts @@ -1,6 +1,6 @@ import type { Duration, RelativeTime } from '@datadog/browser-core' import { isIE, relativeToClocks } from '@datadog/browser-core' -import { createResourceEntry } from '../../../../test/fixtures' +import { createResourceEntry } from '../../../../test' import type { RumPerformanceResourceTiming } from '../../../browser/performanceCollection' import type { RequestCompleteEvent } from '../../requestCollection' diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts index df7cb3517a..1c852f5ac4 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceCollection.spec.ts @@ -8,16 +8,14 @@ import { ResourceType, } from '@datadog/browser-core' import type { RumFetchResourceEventDomainContext } from '../../../domainContext.types' -import { createResourceEntry } from '../../../../test/fixtures' -import type { TestSetupBuilder } from '../../../../test/testSetupBuilder' -import { setup } from '../../../../test/testSetupBuilder' +import { createResourceEntry, setup, createRumSessionManagerMock } from '../../../../test' +import type { TestSetupBuilder } from '../../../../test' import type { RawRumResourceEvent } from '../../../rawRumEvent.types' import { RumEventType } from '../../../rawRumEvent.types' import { LifeCycleEventType } from '../../lifeCycle' import type { RequestCompleteEvent } from '../../requestCollection' import { TraceIdentifier } from '../../tracing/tracer' import { validateAndBuildRumConfiguration } from '../../configuration' -import { createRumSessionManagerMock } from '../../../../test/mockRumSessionManager' import { PageState } from '../../contexts/pageStateHistory' import { startResourceCollection } from './resourceCollection' diff --git a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.spec.ts index 31fcfed8da..e2f0e3dc59 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/resource/resourceUtils.spec.ts @@ -1,5 +1,5 @@ import type { Duration, RelativeTime, ServerDuration } from '@datadog/browser-core' -import { SPEC_ENDPOINTS } from '../../../../../core/test/specHelper' +import { SPEC_ENDPOINTS } from '@datadog/browser-core/test' import type { RumPerformanceResourceTiming } from '../../../browser/performanceCollection' import type { RumConfiguration } from '../../configuration' import { validateAndBuildRumConfiguration } from '../../configuration' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/setupViewTest.specHelper.ts b/packages/rum-core/src/domain/rumEventsCollection/view/setupViewTest.specHelper.ts index d9ddbc6242..f4fcc70b51 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/setupViewTest.specHelper.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/setupViewTest.specHelper.ts @@ -1,4 +1,4 @@ -import type { BuildContext } from '../../../../test/testSetupBuilder' +import type { BuildContext } from '../../../../test' import { LifeCycleEventType } from '../../lifeCycle' import type { ViewEvent, ViewOptions } from './trackViews' import { trackViews } from './trackViews' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackFirstHidden.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/view/trackFirstHidden.spec.ts index 88c0731a63..9e1b31e443 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackFirstHidden.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/trackFirstHidden.spec.ts @@ -1,6 +1,6 @@ import type { RelativeTime } from '@datadog/browser-core' import { DOM_EVENT } from '@datadog/browser-core' -import { createNewEvent, restorePageVisibility, setPageVisibility } from '../../../../../core/test/specHelper' +import { createNewEvent, restorePageVisibility, setPageVisibility } from '@datadog/browser-core/test' import { resetFirstHidden, trackFirstHidden } from './trackFirstHidden' describe('trackFirstHidden', () => { diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackInitialViewTimings.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/view/trackInitialViewTimings.spec.ts index e4249754e9..9ceb73cdea 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackInitialViewTimings.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/trackInitialViewTimings.spec.ts @@ -1,8 +1,8 @@ import type { Duration, RelativeTime } from '@datadog/browser-core' import { DOM_EVENT } from '@datadog/browser-core' -import { createNewEvent, restorePageVisibility, setPageVisibility } from '../../../../../core/test/specHelper' -import type { TestSetupBuilder } from '../../../../test/testSetupBuilder' -import { setup } from '../../../../test/testSetupBuilder' +import { restorePageVisibility, setPageVisibility, createNewEvent } from '@datadog/browser-core/test' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' import type { RumFirstInputTiming, RumLargestContentfulPaintTiming, diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.spec.ts index 54facc04f9..d12de22d51 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/trackViewEventCounts.spec.ts @@ -1,9 +1,9 @@ import type { Context } from '@datadog/browser-core' import { noop } from '@datadog/browser-core' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock } from '@datadog/browser-core/test' import type { RumResourceEvent } from '../../../rumEvent.types' import { RumEventType } from '../../../rawRumEvent.types' -import type { Clock } from '../../../../../core/test/specHelper' -import { mockClock } from '../../../../../core/test/specHelper' import { LifeCycle, LifeCycleEventType } from '../../lifeCycle' import { KEEP_TRACKING_EVENT_COUNTS_AFTER_VIEW_DELAY, trackViewEventCounts } from './trackViewEventCounts' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewMetrics.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/view/trackViewMetrics.spec.ts index 51034b3846..364a6bf672 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewMetrics.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/trackViewMetrics.spec.ts @@ -1,8 +1,8 @@ import type { Context, RelativeTime, Duration } from '@datadog/browser-core' import { addDuration, relativeNow } from '@datadog/browser-core' import type { RumEvent } from '../../../rumEvent.types' -import type { TestSetupBuilder } from '../../../../test/testSetupBuilder' -import { setup } from '../../../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' import type { RumPerformanceNavigationTiming } from '../../../browser/performanceCollection' import { FrustrationType, RumEventType } from '../../../rawRumEvent.types' import type { LifeCycle } from '../../lifeCycle' diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackViews.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/view/trackViews.spec.ts index 67d60f019c..99988faaea 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackViews.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/trackViews.spec.ts @@ -7,8 +7,8 @@ import { relativeNow, resetExperimentalFeatures, } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../../test/testSetupBuilder' -import { setup } from '../../../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../../../test' +import { setup } from '../../../../test' import type { RumLargestContentfulPaintTiming, RumPerformanceNavigationTiming, diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts index ba15263197..08370f2503 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts @@ -1,11 +1,10 @@ import type { Duration, RelativeTime, ServerDuration, TimeStamp } from '@datadog/browser-core' import type { RecorderApi } from '../../../boot/rumPublicApi' -import type { TestSetupBuilder } from '../../../../test/testSetupBuilder' -import { setup } from '../../../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../../../test' +import { setup, noopRecorderApi } from '../../../../test' import type { RawRumViewEvent } from '../../../rawRumEvent.types' import { RumEventType, ViewLoadingType } from '../../../rawRumEvent.types' import { LifeCycleEventType } from '../../lifeCycle' -import { noopRecorderApi } from '../../../../test/noopRecorderApi' import type { ViewEvent } from './trackViews' import { startViewCollection } from './viewCollection' diff --git a/packages/rum-core/src/domain/rumSessionManager.spec.ts b/packages/rum-core/src/domain/rumSessionManager.spec.ts index 2fa8531a70..c59eccbb84 100644 --- a/packages/rum-core/src/domain/rumSessionManager.spec.ts +++ b/packages/rum-core/src/domain/rumSessionManager.spec.ts @@ -8,8 +8,8 @@ import { stopSessionManager, ONE_SECOND, } from '@datadog/browser-core' -import type { Clock } from '../../../core/test/specHelper' -import { mockClock } from '../../../core/test/specHelper' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock } from '@datadog/browser-core/test' import type { RumConfiguration } from './configuration' import { validateAndBuildRumConfiguration } from './configuration' diff --git a/packages/rum-core/src/domain/startCustomerDataTelemetry.spec.ts b/packages/rum-core/src/domain/startCustomerDataTelemetry.spec.ts index b274d1023e..41ce3c1513 100644 --- a/packages/rum-core/src/domain/startCustomerDataTelemetry.spec.ts +++ b/packages/rum-core/src/domain/startCustomerDataTelemetry.spec.ts @@ -1,7 +1,7 @@ import type { BatchFlushEvent, Context, ContextManager, TelemetryEvent } from '@datadog/browser-core' import { resetExperimentalFeatures, TelemetryService, startTelemetry, Observable } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../test/testSetupBuilder' -import { setup } from '../../test/testSetupBuilder' +import type { TestSetupBuilder } from '../../test' +import { setup } from '../../test' import { RumEventType } from '../rawRumEvent.types' import type { RumEvent } from '../rumEvent.types' import type { FeatureFlagContexts } from './contexts/featureFlagContext' diff --git a/packages/rum-core/src/domain/tracing/tracer.spec.ts b/packages/rum-core/src/domain/tracing/tracer.spec.ts index eff8cf0f14..8f0aeee8b7 100644 --- a/packages/rum-core/src/domain/tracing/tracer.spec.ts +++ b/packages/rum-core/src/domain/tracing/tracer.spec.ts @@ -1,8 +1,6 @@ import { display, isIE, objectEntries } from '@datadog/browser-core' -import type { TestSetupBuilder } from '../../../test/testSetupBuilder' -import { setup } from '../../../test/testSetupBuilder' -import type { RumSessionManagerMock } from '../../../test/mockRumSessionManager' -import { createRumSessionManagerMock } from '../../../test/mockRumSessionManager' +import type { TestSetupBuilder, RumSessionManagerMock } from '../../../test' +import { setup, createRumSessionManagerMock } from '../../../test' import type { RumFetchResolveContext, RumFetchStartContext, RumXhrStartContext } from '../requestCollection' import type { RumConfiguration, RumInitConfiguration } from '../configuration' import { validateAndBuildRumConfiguration } from '../configuration' diff --git a/packages/rum-core/src/domain/waitPageActivityEnd.spec.ts b/packages/rum-core/src/domain/waitPageActivityEnd.spec.ts index 2827c3449c..05deee8d19 100644 --- a/packages/rum-core/src/domain/waitPageActivityEnd.spec.ts +++ b/packages/rum-core/src/domain/waitPageActivityEnd.spec.ts @@ -1,9 +1,9 @@ import type { RelativeTime, Subscription } from '@datadog/browser-core' import { Observable, ONE_SECOND, getTimeStamp } from '@datadog/browser-core' -import type { Clock } from '@datadog/browser-core/test/specHelper' -import { mockClock } from '@datadog/browser-core/test/specHelper' -import type { TestSetupBuilder } from '../../test/testSetupBuilder' -import { setup } from '../../test/testSetupBuilder' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock } from '@datadog/browser-core/test' +import type { TestSetupBuilder } from '../../test' +import { setup } from '../../test' import type { RumPerformanceNavigationTiming, RumPerformanceResourceTiming } from '../browser/performanceCollection' import { LifeCycleEventType } from './lifeCycle' import type { RequestCompleteEvent, RequestStartEvent } from './requestCollection' diff --git a/packages/rum-core/test/createFakeClick.ts b/packages/rum-core/test/createFakeClick.ts index 4fc7e4d766..c5eef7adcc 100644 --- a/packages/rum-core/test/createFakeClick.ts +++ b/packages/rum-core/test/createFakeClick.ts @@ -1,5 +1,5 @@ import { clocksNow, Observable, timeStampNow } from '@datadog/browser-core' -import { createNewEvent } from '../../core/test/specHelper' +import { createNewEvent } from '@datadog/browser-core/test' import type { Click } from '../src/domain/rumEventsCollection/action/trackClickActions' export type FakeClick = Readonly> diff --git a/packages/rum-core/test/index.ts b/packages/rum-core/test/index.ts new file mode 100644 index 0000000000..4c1e6ff93c --- /dev/null +++ b/packages/rum-core/test/index.ts @@ -0,0 +1,8 @@ +export * from './createFakeClick' +export * from './createIsolatedDom' +export * from './fixtures' +export * from './formatValidation' +export * from './mockCiVisibilityWindowValues' +export * from './mockRumSessionManager' +export * from './noopRecorderApi' +export * from './testSetupBuilder' diff --git a/packages/rum-core/test/testSetupBuilder.ts b/packages/rum-core/test/testSetupBuilder.ts index f46454280a..c7b499ef15 100644 --- a/packages/rum-core/test/testSetupBuilder.ts +++ b/packages/rum-core/test/testSetupBuilder.ts @@ -1,7 +1,7 @@ import type { Context, ContextManager, TimeStamp } from '@datadog/browser-core' import { assign, combine, createContextManager, noop, Observable } from '@datadog/browser-core' -import type { Clock } from '../../core/test/specHelper' -import { buildLocation, mockClock, SPEC_ENDPOINTS } from '../../core/test/specHelper' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock, buildLocation, SPEC_ENDPOINTS } from '@datadog/browser-core/test' import type { LocationChange } from '../src/browser/locationChangeObservable' import type { RumConfiguration } from '../src/domain/configuration' import { validateAndBuildRumConfiguration } from '../src/domain/configuration' diff --git a/packages/rum/src/boot/recorderApi.spec.ts b/packages/rum/src/boot/recorderApi.spec.ts index 2b7bbecbc7..77598cff30 100644 --- a/packages/rum/src/boot/recorderApi.spec.ts +++ b/packages/rum/src/boot/recorderApi.spec.ts @@ -1,11 +1,9 @@ import { isIE, noop } from '@datadog/browser-core' import type { RecorderApi, ViewContexts, LifeCycle, RumConfiguration } from '@datadog/browser-rum-core' import { LifeCycleEventType } from '@datadog/browser-rum-core' -import { createNewEvent, deleteEventBridgeStub, initEventBridgeStub } from '../../../core/test/specHelper' -import type { RumSessionManagerMock } from '../../../rum-core/test/mockRumSessionManager' -import { createRumSessionManagerMock } from '../../../rum-core/test/mockRumSessionManager' -import type { TestSetupBuilder } from '../../../rum-core/test/testSetupBuilder' -import { setup } from '../../../rum-core/test/testSetupBuilder' +import { deleteEventBridgeStub, initEventBridgeStub, createNewEvent } from '@datadog/browser-core/test' +import type { RumSessionManagerMock, TestSetupBuilder } from '../../../rum-core/test' +import { createRumSessionManagerMock, setup } from '../../../rum-core/test' import type { DeflateWorker, startDeflateWorker } from '../domain/segmentCollection' import type { StartRecording } from './recorderApi' import { makeRecorderApi } from './recorderApi' diff --git a/packages/rum/src/boot/startRecording.spec.ts b/packages/rum/src/boot/startRecording.spec.ts index a2fa925920..45760037e8 100644 --- a/packages/rum/src/boot/startRecording.spec.ts +++ b/packages/rum/src/boot/startRecording.spec.ts @@ -3,19 +3,16 @@ import { PageExitReason, DefaultPrivacyLevel, noop, isIE, timeStampNow } from '@ import type { LifeCycle, ViewCreatedEvent } from '@datadog/browser-rum-core' import { LifeCycleEventType } from '@datadog/browser-rum-core' import { inflate } from 'pako' -import type { RumSessionManagerMock } from '../../../rum-core/test/mockRumSessionManager' -import { createRumSessionManagerMock } from '../../../rum-core/test/mockRumSessionManager' -import { createNewEvent, mockClock } from '../../../core/test/specHelper' +import { collectAsyncCalls, createNewEvent, mockClock } from '@datadog/browser-core/test' +import type { RumSessionManagerMock, TestSetupBuilder } from '../../../rum-core/test' +import { createRumSessionManagerMock, setup } from '../../../rum-core/test' -import type { TestSetupBuilder } from '../../../rum-core/test/testSetupBuilder' -import { setup } from '../../../rum-core/test/testSetupBuilder' -import { recordsPerFullSnapshot } from '../../test/utils' +import { recordsPerFullSnapshot } from '../../test' import { setSegmentBytesLimit, startDeflateWorker } from '../domain/segmentCollection' import type { BrowserSegment } from '../types' import { RecordType } from '../types' import { resetReplayStats } from '../domain/replayStats' -import { collectAsyncCalls } from '../../../core/test/collectAsyncCalls' import { startRecording } from './startRecording' const VIEW_TIMESTAMP = 1 as TimeStamp diff --git a/packages/rum/src/domain/record/mutationBatch.spec.ts b/packages/rum/src/domain/record/mutationBatch.spec.ts index c49995995e..66240d14dc 100644 --- a/packages/rum/src/domain/record/mutationBatch.spec.ts +++ b/packages/rum/src/domain/record/mutationBatch.spec.ts @@ -1,4 +1,4 @@ -import { collectAsyncCalls } from '../../../../core/test/collectAsyncCalls' +import { collectAsyncCalls } from '@datadog/browser-core/test' import { createMutationBatch } from './mutationBatch' import type { RumMutationRecord } from './observers' diff --git a/packages/rum/src/domain/record/observers/inputObserver.spec.ts b/packages/rum/src/domain/record/observers/inputObserver.spec.ts index e1465c3d0d..5aeb317321 100644 --- a/packages/rum/src/domain/record/observers/inputObserver.spec.ts +++ b/packages/rum/src/domain/record/observers/inputObserver.spec.ts @@ -1,9 +1,9 @@ import { DefaultPrivacyLevel, isIE } from '@datadog/browser-core' -import { createNewEvent } from '@datadog/browser-core/test/specHelper' +import { createNewEvent } from '@datadog/browser-core/test' import { PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_MASK_USER_INPUT } from '../../../constants' import { serializeDocument, SerializationContextStatus } from '../serialization' import { createElementsScrollPositions } from '../elementsScrollPositions' -import { DEFAULT_CONFIGURATION, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test/utils' +import { DEFAULT_CONFIGURATION, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test' import type { InputCallback } from './inputObserver' import { initInputObserver } from './inputObserver' diff --git a/packages/rum/src/domain/record/observers/mouseInteractionObserver.spec.ts b/packages/rum/src/domain/record/observers/mouseInteractionObserver.spec.ts index 89827b4a22..f876387b7d 100644 --- a/packages/rum/src/domain/record/observers/mouseInteractionObserver.spec.ts +++ b/packages/rum/src/domain/record/observers/mouseInteractionObserver.spec.ts @@ -1,9 +1,9 @@ import { DefaultPrivacyLevel, isIE } from '@datadog/browser-core' -import { createNewEvent } from '@datadog/browser-core/test/specHelper' +import { createNewEvent } from '@datadog/browser-core/test' import { IncrementalSource, MouseInteractionType, RecordType } from '../../../types' import { serializeDocument, SerializationContextStatus } from '../serialization' import { createElementsScrollPositions } from '../elementsScrollPositions' -import { DEFAULT_CONFIGURATION, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test/utils' +import { DEFAULT_CONFIGURATION, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test' import type { MouseInteractionCallBack } from './mouseInteractionObserver' import { initMouseInteractionObserver } from './mouseInteractionObserver' import type { RecordIds } from './recordIds' diff --git a/packages/rum/src/domain/record/observers/moveObserver.spec.ts b/packages/rum/src/domain/record/observers/moveObserver.spec.ts index ffb23ddc23..18c463c634 100644 --- a/packages/rum/src/domain/record/observers/moveObserver.spec.ts +++ b/packages/rum/src/domain/record/observers/moveObserver.spec.ts @@ -1,9 +1,9 @@ import { isIE } from '@datadog/browser-core' -import { createNewEvent } from '@datadog/browser-core/test/specHelper' +import { createNewEvent } from '@datadog/browser-core/test' import { SerializationContextStatus, serializeDocument } from '../serialization' import { createElementsScrollPositions } from '../elementsScrollPositions' import { IncrementalSource } from '../../../types' -import { DEFAULT_CONFIGURATION, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test/utils' +import { DEFAULT_CONFIGURATION, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test' import type { MousemoveCallBack } from './moveObserver' import { initMoveObserver } from './moveObserver' diff --git a/packages/rum/src/domain/record/observers/mutationObserver.spec.ts b/packages/rum/src/domain/record/observers/mutationObserver.spec.ts index 1b831e435c..54026c8d05 100644 --- a/packages/rum/src/domain/record/observers/mutationObserver.spec.ts +++ b/packages/rum/src/domain/record/observers/mutationObserver.spec.ts @@ -1,7 +1,7 @@ import { DefaultPrivacyLevel, isIE } from '@datadog/browser-core' import type { RumConfiguration } from '@datadog/browser-rum-core' -import { collectAsyncCalls } from '@datadog/browser-core/test/collectAsyncCalls' -import { createMutationPayloadValidator, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test/utils' +import { collectAsyncCalls } from '@datadog/browser-core/test' +import { createMutationPayloadValidator, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test' import { NodePrivacyLevel, PRIVACY_ATTR_NAME, diff --git a/packages/rum/src/domain/record/observers/styleSheetObserver.spec.ts b/packages/rum/src/domain/record/observers/styleSheetObserver.spec.ts index cf6783ab66..751beeee34 100644 --- a/packages/rum/src/domain/record/observers/styleSheetObserver.spec.ts +++ b/packages/rum/src/domain/record/observers/styleSheetObserver.spec.ts @@ -1,6 +1,6 @@ import { isIE } from '@datadog/browser-core' -import { isFirefox } from '@datadog/browser-core/test/specHelper' -import { DEFAULT_CONFIGURATION, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test/utils' +import { isFirefox } from '@datadog/browser-core/test' +import { DEFAULT_CONFIGURATION, DEFAULT_SHADOW_ROOT_CONTROLLER } from '../../../../test' import { serializeDocument, SerializationContextStatus } from '../serialization' import { createElementsScrollPositions } from '../elementsScrollPositions' import type { StyleSheetCallback } from './styleSheetObserver' diff --git a/packages/rum/src/domain/record/record.spec.ts b/packages/rum/src/domain/record/record.spec.ts index 0a00483492..c43d8b6103 100644 --- a/packages/rum/src/domain/record/record.spec.ts +++ b/packages/rum/src/domain/record/record.spec.ts @@ -1,10 +1,9 @@ import { DefaultPrivacyLevel, findLast, isIE } from '@datadog/browser-core' import type { RumConfiguration } from '@datadog/browser-rum-core' import { LifeCycle } from '@datadog/browser-rum-core' -import { collectAsyncCalls } from '../../../../core/test/collectAsyncCalls' -import type { Clock } from '../../../../core/test/specHelper' -import { createNewEvent } from '../../../../core/test/specHelper' -import { findFullSnapshot, findNode, recordsPerFullSnapshot } from '../../../test/utils' +import type { Clock } from '@datadog/browser-core/test' +import { createNewEvent, collectAsyncCalls } from '@datadog/browser-core/test' +import { findFullSnapshot, findNode, recordsPerFullSnapshot } from '../../../test' import type { BrowserIncrementalSnapshotRecord, BrowserMutationData, diff --git a/packages/rum/src/domain/record/serialization/serializeNode.spec.ts b/packages/rum/src/domain/record/serialization/serializeNode.spec.ts index 563aa545a2..75444655ea 100644 --- a/packages/rum/src/domain/record/serialization/serializeNode.spec.ts +++ b/packages/rum/src/domain/record/serialization/serializeNode.spec.ts @@ -1,6 +1,7 @@ import { isIE, noop } from '@datadog/browser-core' import type { RumConfiguration } from '@datadog/browser-rum-core' +import { isAdoptedStyleSheetsSupported } from '@datadog/browser-core/test' import { NodePrivacyLevel, PRIVACY_ATTR_NAME, @@ -11,12 +12,11 @@ import { } from '../../../constants' import type { ElementNode, SerializedNodeWithId, TextNode } from '../../../types' import { NodeType } from '../../../types' -import type { IsolatedDom } from '../../../../../rum-core/test/createIsolatedDom' -import { createIsolatedDom } from '../../../../../rum-core/test/createIsolatedDom' +import type { IsolatedDom } from '../../../../../rum-core/test' +import { createIsolatedDom } from '../../../../../rum-core/test' import type { ElementsScrollPositions } from '../elementsScrollPositions' import { createElementsScrollPositions } from '../elementsScrollPositions' import type { ShadowRootCallBack, ShadowRootsController } from '../shadowRootsController' -import { isAdoptedStyleSheetsSupported } from '../../../../../core/test/specHelper' import { HTML, generateLeanSerializedDoc, diff --git a/packages/rum/src/domain/record/serialization/serializeStyleSheets.spec.ts b/packages/rum/src/domain/record/serialization/serializeStyleSheets.spec.ts index bded22814a..ae4f621bb0 100644 --- a/packages/rum/src/domain/record/serialization/serializeStyleSheets.spec.ts +++ b/packages/rum/src/domain/record/serialization/serializeStyleSheets.spec.ts @@ -1,4 +1,4 @@ -import { isAdoptedStyleSheetsSupported } from '@datadog/browser-core/test/specHelper' +import { isAdoptedStyleSheetsSupported } from '@datadog/browser-core/test' import { serializeStyleSheets } from './serializeStyleSheets' describe('serializeStyleSheets', () => { diff --git a/packages/rum/src/domain/segmentCollection/segment.spec.ts b/packages/rum/src/domain/segmentCollection/segment.spec.ts index 2beaaaa993..3a0656149b 100644 --- a/packages/rum/src/domain/segmentCollection/segment.spec.ts +++ b/packages/rum/src/domain/segmentCollection/segment.spec.ts @@ -1,6 +1,6 @@ import type { TimeStamp } from '@datadog/browser-core' import { noop, setDebugMode, display, isIE } from '@datadog/browser-core' -import { MockWorker, parseSegment } from '../../../test/utils' +import { MockWorker, parseSegment } from '../../../test' import type { CreationReason, BrowserRecord, SegmentContext } from '../../types' import { RecordType } from '../../types' import { getReplayStats, resetReplayStats } from '../replayStats' diff --git a/packages/rum/src/domain/segmentCollection/segmentCollection.spec.ts b/packages/rum/src/domain/segmentCollection/segmentCollection.spec.ts index dfce42507a..41ac91f9ab 100644 --- a/packages/rum/src/domain/segmentCollection/segmentCollection.spec.ts +++ b/packages/rum/src/domain/segmentCollection/segmentCollection.spec.ts @@ -2,12 +2,12 @@ import type { HttpRequest, TimeStamp } from '@datadog/browser-core' import { PageExitReason, isIE } from '@datadog/browser-core' import type { ViewContexts, ViewContext } from '@datadog/browser-rum-core' import { LifeCycle, LifeCycleEventType } from '@datadog/browser-rum-core' -import type { Clock } from '@datadog/browser-core/test/specHelper' -import { mockClock, restorePageVisibility } from '@datadog/browser-core/test/specHelper' -import { createRumSessionManagerMock } from '../../../../rum-core/test/mockRumSessionManager' +import type { Clock } from '@datadog/browser-core/test' +import { mockClock, restorePageVisibility } from '@datadog/browser-core/test' +import { createRumSessionManagerMock } from '../../../../rum-core/test' import type { BrowserRecord, SegmentContext } from '../../types' import { RecordType } from '../../types' -import { MockWorker } from '../../../test/utils' +import { MockWorker } from '../../../test' import { computeSegmentContext, doStartSegmentCollection, diff --git a/packages/rum/src/domain/segmentCollection/startDeflateWorker.spec.ts b/packages/rum/src/domain/segmentCollection/startDeflateWorker.spec.ts index c0dc857da0..b3e1ea8ea4 100644 --- a/packages/rum/src/domain/segmentCollection/startDeflateWorker.spec.ts +++ b/packages/rum/src/domain/segmentCollection/startDeflateWorker.spec.ts @@ -1,6 +1,6 @@ import type { RawTelemetryEvent } from '@datadog/browser-core' import { display, isIE, noop, resetTelemetry, startFakeTelemetry } from '@datadog/browser-core' -import { MockWorker } from '../../../test/utils' +import { MockWorker } from '../../../test' import type { createDeflateWorker } from './deflateWorker' import { startDeflateWorker, resetDeflateWorkerState } from './startDeflateWorker' diff --git a/packages/rum/test/index.ts b/packages/rum/test/index.ts new file mode 100644 index 0000000000..9c56149efa --- /dev/null +++ b/packages/rum/test/index.ts @@ -0,0 +1 @@ +export * from './utils' diff --git a/test/e2e/scenario/recorder/recorder.scenario.ts b/test/e2e/scenario/recorder/recorder.scenario.ts index 1ad26d4598..36768309f2 100644 --- a/test/e2e/scenario/recorder/recorder.scenario.ts +++ b/test/e2e/scenario/recorder/recorder.scenario.ts @@ -22,7 +22,7 @@ import { findAllFrustrationRecords, findMouseInteractionRecords, findElementWithTagName, -} from '@datadog/browser-rum/test/utils' +} from '@datadog/browser-rum/test' import { flushEvents, createTest, bundleSetup, html } from '../../lib/framework' import { browserExecute, browserExecuteAsync } from '../../lib/helpers/browser' import { getFirstSegment, getLastSegment, initRumAndStartRecording } from '../../lib/helpers/replay' diff --git a/test/e2e/scenario/recorder/shadowDom.scenario.ts b/test/e2e/scenario/recorder/shadowDom.scenario.ts index 222178b968..b01f4ed545 100644 --- a/test/e2e/scenario/recorder/shadowDom.scenario.ts +++ b/test/e2e/scenario/recorder/shadowDom.scenario.ts @@ -11,13 +11,13 @@ import { findNode, findTextContent, findTextNode, -} from '@datadog/browser-rum/test/utils' +} from '@datadog/browser-rum/test' import type { EventRegistry } from '../../lib/framework' import { flushEvents, createTest, bundleSetup, html } from '../../lib/framework' import { browserExecute } from '../../lib/helpers/browser' -/** Will generate the following HTML +/** Will generate the following HTML * ```html * * #shadow-root @@ -57,7 +57,7 @@ const inputShadowDom = ` ` -/** Will generate the following HTML +/** Will generate the following HTML * ```html * * #shadow-root @@ -82,7 +82,7 @@ const divShadowDom = ` ` -/** Will generate the following HTML +/** Will generate the following HTML * ```html * * #shadow-root diff --git a/test/e2e/scenario/recorder/viewports.scenario.ts b/test/e2e/scenario/recorder/viewports.scenario.ts index e4e333febb..be0caa5eee 100644 --- a/test/e2e/scenario/recorder/viewports.scenario.ts +++ b/test/e2e/scenario/recorder/viewports.scenario.ts @@ -2,7 +2,7 @@ import type { ViewportResizeData, ScrollData } from '@datadog/browser-rum/cjs/ty import { IncrementalSource } from '@datadog/browser-rum/cjs/types' import type { RumInitConfiguration } from '@datadog/browser-rum-core' -import { findAllIncrementalSnapshots, findAllVisualViewports } from '@datadog/browser-rum/test/utils' +import { findAllIncrementalSnapshots, findAllVisualViewports } from '@datadog/browser-rum/test' import type { EventRegistry } from '../../lib/framework' import { flushEvents, createTest, bundleSetup, html } from '../../lib/framework' import { browserExecute, getBrowserName, getPlatformName } from '../../lib/helpers/browser'