tracker: testing tracker constructor options mapper

This commit is contained in:
nick-delirium 2024-10-21 17:41:39 +02:00
parent 41dce26281
commit 45d6aeb6c3
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
5 changed files with 62 additions and 3 deletions

View file

@ -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),
},
}),
]

View file

@ -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'

View file

@ -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]

View file

@ -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');
})
})