-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* ✨ [RUMF-867] stabilize the `manualSessionReplayRecordingStart` option * ✨ [RUMF-867] stabilize start/stop recording API * 🏷️ fix compatibility issue with TS3.0 * 🏷️ Export RumRecorder{PublicApi,UserConfiguration} types * 👌 rename a few variable to rumPublicApi / rumRecorderPublicApi For consistency.
- Loading branch information
1 parent
1e0244e
commit c5f8aa5
Showing
8 changed files
with
182 additions
and
175 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { defineGlobal, getGlobalObject } from '@datadog/browser-core' | ||
import { RumPublicApi, startRum } from '@datadog/browser-rum-core' | ||
import { startRum } from '@datadog/browser-rum-core' | ||
|
||
import { startRecording } from './recorder' | ||
import { makeRumRecorderPublicApi } from './rumRecorderPublicApi' | ||
import { RumRecorderPublicApi, makeRumRecorderPublicApi } from './rumRecorderPublicApi' | ||
|
||
export const datadogRum = makeRumRecorderPublicApi(startRum, startRecording) | ||
|
||
interface BrowserWindow extends Window { | ||
DD_RUM?: RumPublicApi | ||
DD_RUM?: RumRecorderPublicApi | ||
} | ||
defineGlobal(getGlobalObject<BrowserWindow>(), 'DD_RUM', datadogRum) |
122 changes: 51 additions & 71 deletions
122
packages/rum-recorder/src/boot/rumRecorderPublicApi.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,91 @@ | ||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
import { Configuration, noop } from '@datadog/browser-core' | ||
import { RumPublicApi, RumUserConfiguration, StartRum } from '@datadog/browser-rum-core' | ||
import { makeRumRecorderPublicApi, StartRecording } from './rumRecorderPublicApi' | ||
import { Configuration } from '@datadog/browser-core' | ||
import { StartRum } from '@datadog/browser-rum-core' | ||
import { makeRumRecorderPublicApi, RumRecorderPublicApi, StartRecording } from './rumRecorderPublicApi' | ||
|
||
const DEFAULT_INIT_CONFIGURATION = { applicationId: 'xxx', clientToken: 'xxx' } | ||
|
||
describe('makeRumRecorderPublicApi', () => { | ||
let rumGlobal: RumPublicApi & { | ||
// TODO postpone_start_recording: those types will be included in rum-recorder public API when | ||
// postpone_start_recording is stabilized. | ||
startSessionReplayRecording?(): void | ||
init(options: RumUserConfiguration & { manualSessionReplayRecordingStart?: boolean }): void | ||
} | ||
let rumRecorderPublicApi: RumRecorderPublicApi | ||
let startRecordingSpy: jasmine.Spy<StartRecording> | ||
let stopRecordingSpy: jasmine.Spy<() => void> | ||
let startRumSpy: jasmine.Spy<StartRum> | ||
let enabledFlags: string[] = [] | ||
|
||
beforeEach(() => { | ||
enabledFlags = [] | ||
stopRecordingSpy = jasmine.createSpy() | ||
startRecordingSpy = jasmine.createSpy().and.callFake(() => ({ | ||
stop: noop, | ||
stop: stopRecordingSpy, | ||
})) | ||
startRumSpy = jasmine.createSpy().and.callFake(() => { | ||
const configuration: Partial<Configuration> = { | ||
isEnabled(flag: string) { | ||
return enabledFlags.indexOf(flag) >= 0 | ||
}, | ||
} | ||
const configuration: Partial<Configuration> = {} | ||
return ({ configuration } as unknown) as ReturnType<StartRum> | ||
}) | ||
rumGlobal = makeRumRecorderPublicApi(startRumSpy, startRecordingSpy) | ||
rumRecorderPublicApi = makeRumRecorderPublicApi(startRumSpy, startRecordingSpy) | ||
}) | ||
|
||
function getCommonContext() { | ||
return startRumSpy.calls.first().args[1]() | ||
} | ||
|
||
describe('init', () => { | ||
it('should start RUM when init is called', () => { | ||
it('starts RUM when init is called', () => { | ||
expect(startRumSpy).not.toHaveBeenCalled() | ||
rumGlobal.init(DEFAULT_INIT_CONFIGURATION) | ||
rumRecorderPublicApi.init(DEFAULT_INIT_CONFIGURATION) | ||
expect(startRumSpy).toHaveBeenCalled() | ||
}) | ||
|
||
it('should start recording when init is called', () => { | ||
it('starts recording when init() is called', () => { | ||
expect(startRecordingSpy).not.toHaveBeenCalled() | ||
rumGlobal.init(DEFAULT_INIT_CONFIGURATION) | ||
rumRecorderPublicApi.init(DEFAULT_INIT_CONFIGURATION) | ||
expect(startRecordingSpy).toHaveBeenCalled() | ||
}) | ||
|
||
it('should set commonContext.hasReplay to true', () => { | ||
rumGlobal.init(DEFAULT_INIT_CONFIGURATION) | ||
expect(getCommonContext().hasReplay).toBe(true) | ||
it('does not start recording when calling init() with manualSessionReplayRecordingStart: true', () => { | ||
rumRecorderPublicApi.init({ ...DEFAULT_INIT_CONFIGURATION, manualSessionReplayRecordingStart: true }) | ||
expect(startRecordingSpy).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
describe('experimental flag postpone_start_recording', () => { | ||
describe('if disabled', () => { | ||
it('startSessionReplayRecording should not be defined', () => { | ||
expect(rumGlobal.startSessionReplayRecording).toBeUndefined() | ||
rumGlobal.init(DEFAULT_INIT_CONFIGURATION) | ||
expect(rumGlobal.startSessionReplayRecording).toBeUndefined() | ||
}) | ||
|
||
it('option manualSessionReplayRecordingStart should not be taken into account', () => { | ||
rumGlobal.init({ ...DEFAULT_INIT_CONFIGURATION, manualSessionReplayRecordingStart: true }) | ||
expect(startRecordingSpy).toHaveBeenCalled() | ||
}) | ||
describe('startSessionReplayRecording()', () => { | ||
it('ignores calls while recording is already started', () => { | ||
rumRecorderPublicApi.init(DEFAULT_INIT_CONFIGURATION) | ||
rumRecorderPublicApi.startSessionReplayRecording() | ||
rumRecorderPublicApi.startSessionReplayRecording() | ||
rumRecorderPublicApi.startSessionReplayRecording() | ||
expect(startRecordingSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
describe('if enabled', () => { | ||
beforeEach(() => { | ||
enabledFlags = ['postpone_start_recording'] | ||
}) | ||
|
||
it('recording should start when calling init() with default options', () => { | ||
rumGlobal.init(DEFAULT_INIT_CONFIGURATION) | ||
expect(startRecordingSpy).toHaveBeenCalled() | ||
}) | ||
|
||
it('startSessionReplayRecording should be defined', () => { | ||
expect(rumGlobal.startSessionReplayRecording).toBeUndefined() | ||
rumGlobal.init(DEFAULT_INIT_CONFIGURATION) | ||
expect(rumGlobal.startSessionReplayRecording).toEqual(jasmine.any(Function)) | ||
}) | ||
it('starts recording if called before init()', () => { | ||
rumRecorderPublicApi.startSessionReplayRecording() | ||
rumRecorderPublicApi.init({ ...DEFAULT_INIT_CONFIGURATION, manualSessionReplayRecordingStart: true }) | ||
expect(startRecordingSpy).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
it('calling startSessionReplayRecording while recording is already start should be ignored', () => { | ||
rumGlobal.init(DEFAULT_INIT_CONFIGURATION) | ||
rumGlobal.startSessionReplayRecording!() | ||
rumGlobal.startSessionReplayRecording!() | ||
rumGlobal.startSessionReplayRecording!() | ||
expect(startRecordingSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
describe('stopSessionReplayRecording()', () => { | ||
it('ignores calls while recording is already stopped', () => { | ||
rumRecorderPublicApi.init(DEFAULT_INIT_CONFIGURATION) | ||
rumRecorderPublicApi.stopSessionReplayRecording() | ||
rumRecorderPublicApi.stopSessionReplayRecording() | ||
rumRecorderPublicApi.stopSessionReplayRecording() | ||
expect(stopRecordingSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
describe('with manualSessionReplayRecordingStart: true option', () => { | ||
it('recording should not start when calling init() with option manualSessionReplayRecordingStart', () => { | ||
rumGlobal.init({ ...DEFAULT_INIT_CONFIGURATION, manualSessionReplayRecordingStart: true }) | ||
expect(startRecordingSpy).not.toHaveBeenCalled() | ||
}) | ||
it('does not start recording if called before init()', () => { | ||
rumRecorderPublicApi.stopSessionReplayRecording() | ||
rumRecorderPublicApi.init({ ...DEFAULT_INIT_CONFIGURATION }) | ||
expect(startRecordingSpy).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
it('commonContext.hasReplay should be true only if startSessionReplayRecording is called', () => { | ||
rumGlobal.init({ ...DEFAULT_INIT_CONFIGURATION, manualSessionReplayRecordingStart: true }) | ||
expect(getCommonContext().hasReplay).toBeUndefined() | ||
rumGlobal.startSessionReplayRecording!() | ||
expect(getCommonContext().hasReplay).toBe(true) | ||
}) | ||
}) | ||
describe('commonContext hasReplay', () => { | ||
it('is true only if recording', () => { | ||
rumRecorderPublicApi.init({ ...DEFAULT_INIT_CONFIGURATION, manualSessionReplayRecordingStart: true }) | ||
expect(getCommonContext().hasReplay).toBeUndefined() | ||
rumRecorderPublicApi.startSessionReplayRecording() | ||
expect(getCommonContext().hasReplay).toBe(true) | ||
rumRecorderPublicApi.stopSessionReplayRecording() | ||
expect(getCommonContext().hasReplay).toBeUndefined() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters