diff --git a/tracker/tracker/.yarn/install-state.gz b/tracker/tracker/.yarn/install-state.gz index c37980d8e..cefab0ad0 100644 Binary files a/tracker/tracker/.yarn/install-state.gz and b/tracker/tracker/.yarn/install-state.gz differ diff --git a/tracker/tracker/rollup.config.js b/tracker/tracker/rollup.config.js index 2c1daebdc..cedc7d3c2 100644 --- a/tracker/tracker/rollup.config.js +++ b/tracker/tracker/rollup.config.js @@ -17,7 +17,7 @@ export default async () => { preventAssignment: true, values: { TRACKER_VERSION: packageConfig.version, - WEBWORKER_BODY: JSON.stringify(webworkerContent), + 'global.WEBWORKER_BODY': JSON.stringify(webworkerContent), }, }), ] diff --git a/tracker/tracker/src/main/app/index.ts b/tracker/tracker/src/main/app/index.ts index 0f58affe2..2851b51ca 100644 --- a/tracker/tracker/src/main/app/index.ts +++ b/tracker/tracker/src/main/app/index.ts @@ -71,7 +71,7 @@ interface OnStartInfo { * this value is injected during build time via rollup * */ // @ts-ignore -const workerBodyFn = WEBWORKER_BODY +const workerBodyFn = global.WEBWORKER_BODY const CANCELED = 'canceled' as const const uxtStorageKey = 'or_uxt_active' const bufferStorageKey = 'or_buffer_1' diff --git a/tracker/tracker/src/main/app/observer/observer.ts b/tracker/tracker/src/main/app/observer/observer.ts index ab07d017e..51eeb6d48 100644 --- a/tracker/tracker/src/main/app/observer/observer.ts +++ b/tracker/tracker/src/main/app/observer/observer.ts @@ -401,7 +401,7 @@ export default abstract class Observer { } private commitNode(id: number): boolean { const node = this.app.nodes.getNode(id) - if (node === undefined) { + if (!node) { return false } const cmt = this.commited[id] diff --git a/tracker/tracker/src/tests/main.test.ts b/tracker/tracker/src/tests/main.test.ts new file mode 100644 index 000000000..04bd406f2 --- /dev/null +++ b/tracker/tracker/src/tests/main.test.ts @@ -0,0 +1,59 @@ +// @ts-nocheck +import { describe, expect, test, jest, beforeAll, afterAll } from '@jest/globals' +import Tracker, { Options } from '../main/index.js' +const conditions: string[] = [ + 'Map', + 'Set', + 'MutationObserver', + 'performance', + 'timing', + 'startsWith', + 'Blob', + 'Worker', +] + +jest.mock('@medv/finder', () => ({ default: jest.fn(() => 'mocked network-proxy content') })); +jest.mock('@openreplay/network-proxy', () => ({ default: jest.fn(() => 'mocked network-proxy content') })); +// jest.mock('../main/modules/network', () => jest.fn(() => 'mocked network content')); + +describe('Constructor Tests', () => { + const options = { + projectKey: 'test-project-key', + ingestPoint: 'test-ingest-point', + respectDoNotTrack: false, + network: {}, + mouse: {}, + __DISABLE_SECURE_MODE: true + }; + beforeAll(() => { + // Mock the performance object and its timing property + Object.defineProperty(window, 'performance', { + value: { + timing: {}, + now: jest.fn(() => 1000), // Mock performance.now() if needed + }, + }); + Object.defineProperty(window, 'Worker', { + value: jest.fn(() => 'mocked worker content') + }) + global.IntersectionObserver = jest.fn(() => ({ + observe: jest.fn(), + unobserve: jest.fn(), + disconnect: jest.fn() + })); + }); + + afterAll(() => { + // Clean up the mock after tests if needed + delete window.performance; + delete window.Worker; + delete global.IntersectionObserver; + }); + + test('Takes options correctly', () => { + const tracker = new Tracker(options as unknown as Options); + expect(tracker.app.projectKey).toBe('test-project-key'); + expect(tracker.app.options.projectKey).toBe('test-project-key'); + expect(tracker.app.options.ingestPoint).toBe('test-ingest-point'); + }) +}) \ No newline at end of file