@servicetitan/datadog-rum 40.2.1 → 40.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-impl.d.ts.map +1 -1
- package/dist/create-impl.js +3 -0
- package/dist/create-impl.js.map +1 -1
- package/dist/datadog-provider.d.ts +3 -1
- package/dist/datadog-provider.d.ts.map +1 -1
- package/dist/datadog-provider.js +3 -1
- package/dist/datadog-provider.js.map +1 -1
- package/dist/get-env.d.ts +7 -0
- package/dist/get-env.d.ts.map +1 -0
- package/dist/get-env.js +26 -0
- package/dist/get-env.js.map +1 -0
- package/dist/hash-routing.d.ts +5 -1
- package/dist/hash-routing.d.ts.map +1 -1
- package/dist/hash-routing.js +23 -8
- package/dist/hash-routing.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/sanitize-view-name.d.ts.map +1 -1
- package/dist/sanitize-view-name.js +10 -0
- package/dist/sanitize-view-name.js.map +1 -1
- package/dist/shared-impl.d.ts +1 -1
- package/dist/shared-impl.d.ts.map +1 -1
- package/dist/shared-impl.js.map +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +8 -3
- package/src/create-impl.ts +2 -0
- package/src/datadog-provider.tsx +7 -3
- package/src/get-env.ts +27 -0
- package/src/hash-routing.tsx +28 -9
- package/src/index.ts +1 -0
- package/src/sanitize-view-name.tsx +17 -0
- package/src/shared-impl.ts +1 -1
- package/src/types.ts +6 -2
- package/src/__mocks__/before-send-data.ts +0 -538
- package/src/__mocks__/index.ts +0 -7
- package/src/__mocks__/init-config.ts +0 -6
- package/src/__mocks__/mfe-host.ts +0 -7
- package/src/__mocks__/process-event.ts +0 -20
- package/src/__mocks__/reset-shared-impl.ts +0 -8
- package/src/__mocks__/tracing-urls.ts +0 -30
- package/src/__mocks__/types.ts +0 -1
- package/src/__tests__/before-send.test.ts +0 -76
- package/src/__tests__/build-allowed-tracing-urls.test.ts +0 -120
- package/src/__tests__/build-before-send.test.ts +0 -193
- package/src/__tests__/create-impl.test.ts +0 -427
- package/src/__tests__/datadog-provider.test.tsx +0 -145
- package/src/__tests__/dd-rum-guard.test.ts +0 -73
- package/src/__tests__/element-service-recorder.test.ts +0 -127
- package/src/__tests__/enrich-event.test.ts +0 -139
- package/src/__tests__/get-shared.test.ts +0 -56
- package/src/__tests__/handle-resource.test.ts +0 -76
- package/src/__tests__/hash-routing.test.tsx +0 -70
- package/src/__tests__/init.test.ts +0 -69
- package/src/__tests__/integration.test.ts +0 -147
- package/src/__tests__/resolve-path-service.test.ts +0 -130
- package/src/__tests__/sanitize-view-name.test.tsx +0 -92
- package/src/__tests__/set-user.test.ts +0 -61
- package/src/__tests__/use-rum-service.test.tsx +0 -82
- package/src/runtime-override/__tests__/dev-console.test.ts +0 -158
- package/src/runtime-override/__tests__/override.test.ts +0 -109
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { mfeHost } from '../__mocks__';
|
|
2
|
-
import { resolvePathService } from '../resolve-path-service';
|
|
3
|
-
|
|
4
|
-
describe(`[datadog-rum] ${resolvePathService.name}`, () => {
|
|
5
|
-
const outerName = 'servicetitan-dispatch-pro-console';
|
|
6
|
-
const innerName = 'servicetitan-task-hub';
|
|
7
|
-
const outerVersion = '1.2.3';
|
|
8
|
-
const innerVersion = '0.0.0-master.8e05d88';
|
|
9
|
-
|
|
10
|
-
const mfePortal = (name: string, owner?: HTMLElement) => {
|
|
11
|
-
const portal = document.body.appendChild(document.createElement('div'));
|
|
12
|
-
portal.setAttribute('data-mfe-portal-name', name);
|
|
13
|
-
const shadowRoot = portal.attachShadow({ mode: 'open' });
|
|
14
|
-
if (owner) {
|
|
15
|
-
Object.assign(owner, { portal: shadowRoot });
|
|
16
|
-
}
|
|
17
|
-
return portal;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
let outerHost: HTMLElement;
|
|
21
|
-
let innerHost: HTMLElement;
|
|
22
|
-
let target: HTMLElement;
|
|
23
|
-
let path: EventTarget[];
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
outerHost = document.body.appendChild(mfeHost(outerName, outerVersion));
|
|
27
|
-
innerHost = outerHost.shadowRoot!.appendChild(mfeHost(innerName, innerVersion));
|
|
28
|
-
target = innerHost.shadowRoot!.appendChild(document.createElement('button'));
|
|
29
|
-
path = [target, innerHost.shadowRoot!, innerHost, outerHost.shadowRoot!, outerHost];
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
afterEach(() => {
|
|
33
|
-
document.body.innerHTML = '';
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const subject = () => resolvePathService(path);
|
|
37
|
-
|
|
38
|
-
test('returns the innermost MFE on the path', () => {
|
|
39
|
-
expect(subject()).toEqual({ service: 'task-hub', version: innerVersion });
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('with no MFE element on the path', () => {
|
|
43
|
-
beforeEach(() => (path = [document.body, window]));
|
|
44
|
-
|
|
45
|
-
test('returns undefined', () => {
|
|
46
|
-
expect(subject()).toBeUndefined();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('with a host that has no version', () => {
|
|
51
|
-
beforeEach(() => innerHost.removeAttribute('data-mfe-version'));
|
|
52
|
-
|
|
53
|
-
test('returns an unknown version', () => {
|
|
54
|
-
expect(subject()?.version).toBe('unknown');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('with a target in a portal', () => {
|
|
59
|
-
let portal: HTMLElement;
|
|
60
|
-
|
|
61
|
-
beforeEach(() => {
|
|
62
|
-
portal = mfePortal(innerName, innerHost);
|
|
63
|
-
path = [portal];
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('reads the version from the owning host', () => {
|
|
67
|
-
expect(subject()).toEqual({ service: 'task-hub', version: innerVersion });
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe('with a version on the portal', () => {
|
|
71
|
-
const portalVersion = '9.9.9';
|
|
72
|
-
|
|
73
|
-
beforeEach(() => portal.setAttribute('data-mfe-version', portalVersion));
|
|
74
|
-
|
|
75
|
-
test('reads the version from the portal', () => {
|
|
76
|
-
expect(subject()).toEqual({ service: 'task-hub', version: portalVersion });
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('with two mounted builds of the same MFE', () => {
|
|
81
|
-
const secondVersion = '2.0.0';
|
|
82
|
-
|
|
83
|
-
beforeEach(() => {
|
|
84
|
-
const secondHost = document.body.appendChild(mfeHost(innerName, secondVersion));
|
|
85
|
-
portal = mfePortal(innerName, secondHost);
|
|
86
|
-
path = [portal];
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('reads the version from the build that owns the portal', () => {
|
|
90
|
-
expect(subject()).toEqual({ service: 'task-hub', version: secondVersion });
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe('with a host that does not keep its portal', () => {
|
|
95
|
-
beforeEach(() => {
|
|
96
|
-
portal = mfePortal(outerName);
|
|
97
|
-
path = [portal];
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('reads the version from a host with the same name', () => {
|
|
101
|
-
expect(subject()).toEqual({
|
|
102
|
-
service: 'dispatch-pro-console',
|
|
103
|
-
version: outerVersion,
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('without a matching host', () => {
|
|
109
|
-
beforeEach(() => {
|
|
110
|
-
portal = mfePortal('servicetitan-missing');
|
|
111
|
-
path = [portal];
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('returns an unknown version', () => {
|
|
115
|
-
expect(subject()).toEqual({ service: 'missing', version: 'unknown' });
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('when the portal was resolved before', () => {
|
|
120
|
-
beforeEach(() => {
|
|
121
|
-
subject();
|
|
122
|
-
innerHost.setAttribute('data-mfe-version', '3.0.0');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test('keeps the version it first resolved', () => {
|
|
126
|
-
expect(subject()).toEqual({ service: 'task-hub', version: innerVersion });
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { sanitizeViewName } from '../sanitize-view-name';
|
|
2
|
-
|
|
3
|
-
describe(`[datadog-rum] ${sanitizeViewName.name}`, () => {
|
|
4
|
-
const subject = (viewName: string) => {
|
|
5
|
-
return sanitizeViewName(viewName);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
describe('when view name contains IDs', () => {
|
|
9
|
-
test.each([
|
|
10
|
-
['/new/reports/123', '/new/reports/{id}'],
|
|
11
|
-
['/new/reports/123/summary', '/new/reports/{id}/summary'],
|
|
12
|
-
['/new/reports/123/summary/321', '/new/reports/{id}/summary/{id}'],
|
|
13
|
-
['/new/reports/123ab/summary/32100--r', '/new/reports/{id}/summary/{id}'],
|
|
14
|
-
['/new/reports/10-10-2022/summary/321', '/new/reports/{id}/summary/{id}'],
|
|
15
|
-
['/new/reports/null/summary/undefined', '/new/reports/{id}/summary/{id}'],
|
|
16
|
-
[
|
|
17
|
-
'/new/inventory/download-import-errors/Temp%2FDataExportResults%2Fb8ef44acd-d4ed-4d1a-9f9f-a6c21e80ce9e.xlsx/1',
|
|
18
|
-
'/new/inventory/download-import-errors/{id}/{id}',
|
|
19
|
-
],
|
|
20
|
-
[
|
|
21
|
-
'/new/inventory/download-import-errors/Temp%2FDataExportResults%2Fb8ef44acd-d4ed-4d1a-9f9f-a6c21e80ce9e.txt.xlsx/1',
|
|
22
|
-
'/new/inventory/download-import-errors/{id}/{id}',
|
|
23
|
-
],
|
|
24
|
-
[
|
|
25
|
-
'/new/inventory/download-import-errors/hello.txt',
|
|
26
|
-
'/new/inventory/download-import-errors/{id}',
|
|
27
|
-
],
|
|
28
|
-
['/AbandonedScorecard/1/2/%20Abandoned', '/abandonedscorecard/{id}/{id}/{id}'],
|
|
29
|
-
['/Calls/Caller/%2019104715121', '/calls/caller/{id}'],
|
|
30
|
-
[
|
|
31
|
-
'/dispatch/routes/coordinates=33.5365013%2C-111.944217&name=Richard+Nearhood&address=6767+North+63rd+Place%2C+Paradise+Valley%2C+AZ+85253+USA',
|
|
32
|
-
'/dispatch/routes/{id}',
|
|
33
|
-
],
|
|
34
|
-
[
|
|
35
|
-
'/new/marketing/re/reputationmanagement/id=4716512/hello',
|
|
36
|
-
'/new/marketing/re/reputationmanagement/{id}/hello',
|
|
37
|
-
],
|
|
38
|
-
['/KpiMatrix/Office%20Performance', '/kpimatrix/{id}'],
|
|
39
|
-
['/ChatCenter/+16193895593+1619-389-5593', '/chatcenter/{id}'],
|
|
40
|
-
])('replaces IDs with placeholders (%s -> %s)', (viewName, expected) => {
|
|
41
|
-
expect(subject(viewName)).toBe(expected);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('when view name contain IDs lookalikes', () => {
|
|
46
|
-
test.each([
|
|
47
|
-
['/new/reports/summary/uundefined', '/new/reports/summary/uundefined'],
|
|
48
|
-
['/new/reports/nulll/summary', '/new/reports/nulll/summary'],
|
|
49
|
-
['/new/reports/feature2.0/summary', '/new/reports/feature2.0/summary'],
|
|
50
|
-
])('does nothing (%s -> %s)', (viewName, expected) => {
|
|
51
|
-
expect(subject(viewName)).toBe(expected);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('when view name contains "#"', () => {
|
|
56
|
-
test('removes "#"', () => {
|
|
57
|
-
expect(subject('#/new/reports')).toBe('/new/reports');
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('when view name contains IDs and/or /proxy prefix', () => {
|
|
62
|
-
test.each([
|
|
63
|
-
['/proxyCalls/tenantName', '/calls'],
|
|
64
|
-
['/proxyCalls/chat/123/321/tenantName', '/calls/chat/{id}/{id}'],
|
|
65
|
-
])(
|
|
66
|
-
'replaces IDs with placeholders and removes /proxy and /tenantName (%s -> %s)',
|
|
67
|
-
(viewName, expected) => {
|
|
68
|
-
expect(subject(viewName)).toBe(expected);
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('when view name contains empty segments', () => {
|
|
74
|
-
test.each([
|
|
75
|
-
['/new/reports/123/', '/new/reports/{id}'],
|
|
76
|
-
['/new/reports/123//', '/new/reports/{id}'],
|
|
77
|
-
['/', '/'],
|
|
78
|
-
['///', '/'],
|
|
79
|
-
['//new///reports//123//', '/new/reports/{id}'],
|
|
80
|
-
])('removes duplicate "/" (%s -> %s)', (viewName, expected) => {
|
|
81
|
-
expect(subject(viewName)).toBe(expected);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('when view name is invalid', () => {
|
|
86
|
-
test("doesn't throw an error", () => {
|
|
87
|
-
jest.spyOn(console, 'error').mockImplementation(jest.fn()); // suppress error output
|
|
88
|
-
// @ts-expect-error because number is not a valid argument
|
|
89
|
-
expect(subject(1)).toBe(1);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { datadogRum } from '@datadog/browser-rum';
|
|
2
|
-
import { minimalApplication, resetSharedImpl } from '../__mocks__';
|
|
3
|
-
import { init } from '../init';
|
|
4
|
-
import { setUser, type RumUser } from '../set-user';
|
|
5
|
-
|
|
6
|
-
jest.mock('@datadog/browser-rum');
|
|
7
|
-
|
|
8
|
-
describe(`[datadog-rum] ${setUser.name}`, () => {
|
|
9
|
-
let user: RumUser;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
jest.clearAllMocks();
|
|
13
|
-
resetSharedImpl();
|
|
14
|
-
user = { id: '1' };
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const subject = () => setUser(user);
|
|
18
|
-
|
|
19
|
-
function itDoesNothing() {
|
|
20
|
-
test('does nothing', () => {
|
|
21
|
-
subject();
|
|
22
|
-
|
|
23
|
-
expect(datadogRum.setUser).not.toHaveBeenCalled();
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function itCallsDatadogRumSetUser() {
|
|
28
|
-
test('calls datadogRum.setUser', () => {
|
|
29
|
-
subject();
|
|
30
|
-
|
|
31
|
-
expect(datadogRum.setUser).toHaveBeenCalledWith(user);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
itDoesNothing();
|
|
36
|
-
|
|
37
|
-
describe('when caller initialized the SDK', () => {
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
init({ service: { name: 'desktop' }, application: minimalApplication });
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
itCallsDatadogRumSetUser();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('when datadogRum.init was called directly (legacy)', () => {
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
jest.mocked(datadogRum.getInitConfiguration).mockReturnValue({} as any);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
itCallsDatadogRumSetUser();
|
|
51
|
-
|
|
52
|
-
describe('when caller initialized the SDK', () => {
|
|
53
|
-
beforeEach(() => {
|
|
54
|
-
jest.spyOn(console, 'warn').mockImplementation(jest.fn()); // suppress console output
|
|
55
|
-
init({ service: { name: 'desktop' }, application: minimalApplication });
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
itDoesNothing();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { renderHook, RenderHookResult } from '@testing-library/react';
|
|
2
|
-
import { getOrCreateSharedImpl } from '../get-shared';
|
|
3
|
-
import { init, RumService, type ServiceConfig } from '../init';
|
|
4
|
-
import { useRumService } from '../use-rum-service';
|
|
5
|
-
|
|
6
|
-
jest.mock('../init');
|
|
7
|
-
jest.mock('../get-shared');
|
|
8
|
-
|
|
9
|
-
describe(`[datadog-rum] ${useRumService.name}`, () => {
|
|
10
|
-
const cleanup = jest.fn();
|
|
11
|
-
const setServiceContext = jest.fn();
|
|
12
|
-
const initSetServiceContext = jest.fn();
|
|
13
|
-
let config: ServiceConfig;
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
jest.clearAllMocks();
|
|
17
|
-
jest.mocked(init).mockReturnValue({ cleanup, setServiceContext: initSetServiceContext });
|
|
18
|
-
jest.mocked(getOrCreateSharedImpl).mockReturnValue({
|
|
19
|
-
setServiceContext,
|
|
20
|
-
} as unknown as ReturnType<typeof getOrCreateSharedImpl>);
|
|
21
|
-
|
|
22
|
-
config = { name: 'foo' };
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const subject = () =>
|
|
26
|
-
renderHook((cfg: ServiceConfig) => useRumService(cfg), { initialProps: config });
|
|
27
|
-
|
|
28
|
-
describe('on mount', () => {
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
subject();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('registers the service', () => {
|
|
34
|
-
expect(init).toHaveBeenCalledWith({ service: config });
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('on unmount', () => {
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
const { unmount } = subject();
|
|
41
|
-
unmount();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('runs cleanup', () => {
|
|
45
|
-
expect(cleanup).toHaveBeenCalled();
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('setServiceContext delegates to the shared implementation', () => {
|
|
50
|
-
const context = { foo: 'bar' };
|
|
51
|
-
|
|
52
|
-
subject().result.current.setServiceContext(context);
|
|
53
|
-
|
|
54
|
-
expect(setServiceContext).toHaveBeenCalledWith(config.name, context);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('when already rendered', () => {
|
|
58
|
-
let rerender: RenderHookResult<RumService, ServiceConfig>['rerender'];
|
|
59
|
-
let result: RenderHookResult<RumService, ServiceConfig>['result'];
|
|
60
|
-
|
|
61
|
-
beforeEach(() => {
|
|
62
|
-
const renderHookResult = subject();
|
|
63
|
-
rerender = renderHookResult.rerender;
|
|
64
|
-
result = renderHookResult.result;
|
|
65
|
-
jest.clearAllMocks();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('does not register the service again', () => {
|
|
69
|
-
rerender({ name: 'changed' });
|
|
70
|
-
|
|
71
|
-
expect(init).not.toHaveBeenCalled();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('returns same result', () => {
|
|
75
|
-
const initial = result.current;
|
|
76
|
-
|
|
77
|
-
rerender({ name: 'changed' });
|
|
78
|
-
|
|
79
|
-
expect(result.current).toBe(initial);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { datadogRum } from '@datadog/browser-rum';
|
|
2
|
-
import { DATADOG_RUM_FOR_DEV } from '../constants';
|
|
3
|
-
import { installDevConsole } from '../dev-console';
|
|
4
|
-
import { clearOverride, enableOverride } from '../override';
|
|
5
|
-
|
|
6
|
-
jest.mock('@datadog/browser-rum');
|
|
7
|
-
jest.mock('../override');
|
|
8
|
-
|
|
9
|
-
describe('[datadog-rum] runtime-override/dev-console', () => {
|
|
10
|
-
const originalLocation = window.location;
|
|
11
|
-
const reload = jest.fn();
|
|
12
|
-
const handle = () =>
|
|
13
|
-
(globalThis as { datadogRumForDev?: { start: () => void; stop: () => void } })
|
|
14
|
-
.datadogRumForDev!;
|
|
15
|
-
const storageCalls = () =>
|
|
16
|
-
jest.mocked(globalThis.addEventListener).mock.calls.filter(([type]) => type === 'storage');
|
|
17
|
-
let infoSpy: jest.SpyInstance;
|
|
18
|
-
|
|
19
|
-
beforeAll(() => {
|
|
20
|
-
delete (window as { location?: Location }).location;
|
|
21
|
-
(window as unknown as { location: { reload: jest.Mock } }).location = { reload };
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
afterAll(() => {
|
|
25
|
-
(window as unknown as { location: Location }).location = originalLocation;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
jest.restoreAllMocks();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
jest.clearAllMocks();
|
|
34
|
-
delete (globalThis as { datadogRumForDev?: unknown }).datadogRumForDev;
|
|
35
|
-
infoSpy = jest.spyOn(console, 'info').mockImplementation(() => {});
|
|
36
|
-
jest.spyOn(globalThis, 'addEventListener').mockImplementation(() => {});
|
|
37
|
-
installDevConsole();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('installs the global handle', () => {
|
|
41
|
-
expect(handle()).toEqual({ start: expect.any(Function), stop: expect.any(Function) });
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('registers a single storage listener', () => {
|
|
45
|
-
expect(storageCalls()).toHaveLength(1);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('when installed again', () => {
|
|
49
|
-
let previous: ReturnType<typeof handle>;
|
|
50
|
-
|
|
51
|
-
beforeEach(() => {
|
|
52
|
-
previous = handle();
|
|
53
|
-
installDevConsole();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('keeps the same handle', () => {
|
|
57
|
-
expect(handle()).toBe(previous);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('does not add another storage listener', () => {
|
|
61
|
-
expect(storageCalls()).toHaveLength(1);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('the storage listener', () => {
|
|
66
|
-
let event: { key: string };
|
|
67
|
-
|
|
68
|
-
const subject = () => (storageCalls()[0][1] as EventListener)(event as unknown as Event);
|
|
69
|
-
|
|
70
|
-
describe('when the override key changes', () => {
|
|
71
|
-
beforeEach(() => (event = { key: DATADOG_RUM_FOR_DEV }));
|
|
72
|
-
|
|
73
|
-
test('reloads sibling tabs', () => {
|
|
74
|
-
subject();
|
|
75
|
-
|
|
76
|
-
expect(reload).toHaveBeenCalled();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe('when an unrelated key changes', () => {
|
|
81
|
-
beforeEach(() => (event = { key: 'other' }));
|
|
82
|
-
|
|
83
|
-
test('does not reload', () => {
|
|
84
|
-
subject();
|
|
85
|
-
|
|
86
|
-
expect(reload).not.toHaveBeenCalled();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('start', () => {
|
|
92
|
-
const subject = () => handle().start();
|
|
93
|
-
|
|
94
|
-
test('enables the override', () => {
|
|
95
|
-
subject();
|
|
96
|
-
|
|
97
|
-
expect(enableOverride).toHaveBeenCalled();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('reloads the page', () => {
|
|
101
|
-
subject();
|
|
102
|
-
|
|
103
|
-
expect(reload).toHaveBeenCalled();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
test('logs to the console', () => {
|
|
107
|
-
subject();
|
|
108
|
-
|
|
109
|
-
expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('start()'));
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('stop', () => {
|
|
114
|
-
const subject = () => handle().stop();
|
|
115
|
-
|
|
116
|
-
test('ends the current Datadog session', () => {
|
|
117
|
-
subject();
|
|
118
|
-
|
|
119
|
-
expect(datadogRum.stopSession).toHaveBeenCalled();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('clears the override', () => {
|
|
123
|
-
subject();
|
|
124
|
-
|
|
125
|
-
expect(clearOverride).toHaveBeenCalled();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test('reloads the page', () => {
|
|
129
|
-
subject();
|
|
130
|
-
|
|
131
|
-
expect(reload).toHaveBeenCalled();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('logs to the console', () => {
|
|
135
|
-
subject();
|
|
136
|
-
|
|
137
|
-
expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('stop()'));
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
describe('when ending the session fails', () => {
|
|
141
|
-
beforeEach(() =>
|
|
142
|
-
jest.mocked(datadogRum.stopSession).mockImplementation(() => {
|
|
143
|
-
throw new Error('not initialized');
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
test('does not throw', () => {
|
|
148
|
-
expect(subject).not.toThrow();
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test('still clears the override', () => {
|
|
152
|
-
subject();
|
|
153
|
-
|
|
154
|
-
expect(clearOverride).toHaveBeenCalled();
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { DATADOG_RUM_FOR_DEV } from '../constants';
|
|
2
|
-
import { clearOverride, enableOverride, isForceEnabled } from '../override';
|
|
3
|
-
|
|
4
|
-
const TTL_MS = 12 * 60 * 60 * 1000;
|
|
5
|
-
const NOW = 1_700_000_000_000;
|
|
6
|
-
|
|
7
|
-
describe('[datadog-rum] runtime-override/override', () => {
|
|
8
|
-
const record = (exp: number) =>
|
|
9
|
-
localStorage.setItem(DATADOG_RUM_FOR_DEV, JSON.stringify({ exp }));
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
jest.restoreAllMocks();
|
|
13
|
-
localStorage.clear();
|
|
14
|
-
jest.spyOn(Date, 'now').mockReturnValue(NOW);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('isForceEnabled', () => {
|
|
18
|
-
const subject = () => isForceEnabled();
|
|
19
|
-
|
|
20
|
-
const itReturns = (value: boolean) =>
|
|
21
|
-
test(`is ${value}`, () => {
|
|
22
|
-
expect(subject()).toBe(value);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe('without an override', () => itReturns(false));
|
|
26
|
-
|
|
27
|
-
describe('with a non-expired override', () => {
|
|
28
|
-
beforeEach(() => record(NOW + 1000));
|
|
29
|
-
|
|
30
|
-
itReturns(true);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('with an expired override', () => {
|
|
34
|
-
beforeEach(() => record(NOW - 1));
|
|
35
|
-
|
|
36
|
-
itReturns(false);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('with a malformed override', () => {
|
|
40
|
-
beforeEach(() => localStorage.setItem(DATADOG_RUM_FOR_DEV, 'not json'));
|
|
41
|
-
|
|
42
|
-
itReturns(false);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('with a record missing an expiry', () => {
|
|
46
|
-
beforeEach(() => localStorage.setItem(DATADOG_RUM_FOR_DEV, JSON.stringify({})));
|
|
47
|
-
|
|
48
|
-
itReturns(false);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('when storage access throws', () => {
|
|
52
|
-
beforeEach(() =>
|
|
53
|
-
jest.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
|
|
54
|
-
throw new Error('blocked');
|
|
55
|
-
})
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
itReturns(false);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('enableOverride', () => {
|
|
63
|
-
const subject = () => enableOverride();
|
|
64
|
-
|
|
65
|
-
test('persists a 12h override window', () => {
|
|
66
|
-
subject();
|
|
67
|
-
|
|
68
|
-
expect(localStorage.getItem(DATADOG_RUM_FOR_DEV)).toBe(
|
|
69
|
-
JSON.stringify({ exp: NOW + TTL_MS })
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('when the storage write fails', () => {
|
|
74
|
-
beforeEach(() =>
|
|
75
|
-
jest.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
|
|
76
|
-
throw new Error('blocked');
|
|
77
|
-
})
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
test('does not throw', () => {
|
|
81
|
-
expect(subject).not.toThrow();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('clearOverride', () => {
|
|
87
|
-
const subject = () => clearOverride();
|
|
88
|
-
|
|
89
|
-
beforeEach(() => record(NOW + 1000));
|
|
90
|
-
|
|
91
|
-
test('removes the override', () => {
|
|
92
|
-
subject();
|
|
93
|
-
|
|
94
|
-
expect(localStorage.getItem(DATADOG_RUM_FOR_DEV)).toBeNull();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('when the storage removal fails', () => {
|
|
98
|
-
beforeEach(() =>
|
|
99
|
-
jest.spyOn(Storage.prototype, 'removeItem').mockImplementation(() => {
|
|
100
|
-
throw new Error('blocked');
|
|
101
|
-
})
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
test('does not throw', () => {
|
|
105
|
-
expect(subject).not.toThrow();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|