-
Notifications
You must be signed in to change notification settings - Fork 142
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
* ♻️ [RUM-2445] factorize displayAlreadyInitializedError * ♻️ [RUM-2445] split rumPublicApi * ✅♻️ [RUM-2445] move RUM public API tests * ♻️ [RUM-2445] split logsPublicApi * ✅♻️ [RUM-2445] move Logs public API tests * 👌 rename createActualStrategy in logs * 👌 change first startView call logic * 👌 refactor logic to remove an item from an array * 👌 fix comments
- Loading branch information
1 parent
39cf938
commit d1b8e72
Showing
19 changed files
with
1,182 additions
and
875 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/core/src/boot/displayAlreadyInitializedError.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { InitConfiguration } from '../domain/configuration' | ||
import { display } from '../tools/display' | ||
import { displayAlreadyInitializedError } from './displayAlreadyInitializedError' | ||
|
||
describe('displayAlreadyInitializedError', () => { | ||
it('should display an error', () => { | ||
const displayErrorSpy = spyOn(display, 'error') | ||
displayAlreadyInitializedError('DD_RUM', {} as InitConfiguration) | ||
expect(displayErrorSpy).toHaveBeenCalledTimes(1) | ||
expect(displayErrorSpy).toHaveBeenCalledWith('DD_RUM is already initialized.') | ||
}) | ||
|
||
it('should not display an error if the "silentMultipleInit" option is used', () => { | ||
const displayErrorSpy = spyOn(display, 'error') | ||
displayAlreadyInitializedError('DD_RUM', { silentMultipleInit: true } as InitConfiguration) | ||
expect(displayErrorSpy).not.toHaveBeenCalled() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { InitConfiguration } from '../domain/configuration' | ||
import { display } from '../tools/display' | ||
|
||
export function displayAlreadyInitializedError(sdkName: 'DD_RUM' | 'DD_LOGS', initConfiguration: InitConfiguration) { | ||
if (!initConfiguration.silentMultipleInit) { | ||
display.error(`${sdkName} is already initialized.`) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
import { removeItem } from './utils/arrayUtils' | ||
|
||
const BUFFER_LIMIT = 500 | ||
|
||
export class BoundedBuffer { | ||
private buffer: Array<() => void> = [] | ||
export class BoundedBuffer<T = void> { | ||
private buffer: Array<(arg: T) => void> = [] | ||
|
||
add(callback: () => void) { | ||
add(callback: (arg: T) => void) { | ||
const length = this.buffer.push(callback) | ||
if (length > BUFFER_LIMIT) { | ||
this.buffer.splice(0, 1) | ||
} | ||
} | ||
|
||
drain() { | ||
this.buffer.forEach((callback) => callback()) | ||
remove(callback: (arg: T) => void) { | ||
removeItem(this.buffer, callback) | ||
} | ||
|
||
drain(arg: T) { | ||
this.buffer.forEach((callback) => callback(arg)) | ||
this.buffer.length = 0 | ||
} | ||
} |
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
Oops, something went wrong.