-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [RUMF-1084] ignore init if a RUM instance is or will be injected by…
… synthetics (#1170) * 🚚 [RUMF-1084] move synthetics context getter in its own module * 🚚✅ [RUMF-1084] move synthetics context tests in its own spec * ✨ [RUMF-1084] implement synthetics injection check * 👌 move check at the beginning of `init` To avoid any side effect like warning message, let's bail out earlier. * 👌 fix typo in tests titles * 👌 move synthetics context module in the domain folder * 👌 move contextHistory module in the tools folder
- Loading branch information
1 parent
f47f945
commit 0abacc5
Showing
13 changed files
with
204 additions
and
121 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { mockSyntheticsWorkerValues, cleanupSyntheticsWorkerValues } from '../../test/specHelper' | ||
import { getSyntheticsContext, willSyntheticsInjectRum } from './syntheticsContext' | ||
|
||
describe('getSyntheticsContext', () => { | ||
afterEach(() => { | ||
cleanupSyntheticsWorkerValues() | ||
}) | ||
|
||
it('sets the synthetics context defined by global variables', () => { | ||
mockSyntheticsWorkerValues({ publicId: 'foo', resultId: 'bar' }, 'globals') | ||
|
||
expect(getSyntheticsContext()).toEqual({ | ||
test_id: 'foo', | ||
result_id: 'bar', | ||
}) | ||
}) | ||
|
||
it('sets the synthetics context defined by global cookie', () => { | ||
mockSyntheticsWorkerValues({ publicId: 'foo', resultId: 'bar' }, 'cookies') | ||
|
||
expect(getSyntheticsContext()).toEqual({ | ||
test_id: 'foo', | ||
result_id: 'bar', | ||
}) | ||
}) | ||
|
||
it('does not set synthetics context if one global variable is undefined', () => { | ||
mockSyntheticsWorkerValues({ publicId: 'foo' }, 'globals') | ||
|
||
expect(getSyntheticsContext()).toBeUndefined() | ||
}) | ||
|
||
it('does not set synthetics context if global variables are not strings', () => { | ||
mockSyntheticsWorkerValues({ publicId: 1, resultId: 2 }, 'globals') | ||
|
||
expect(getSyntheticsContext()).toBeUndefined() | ||
}) | ||
|
||
it('does not set synthetics context if one cookie is undefined', () => { | ||
mockSyntheticsWorkerValues({ publicId: 'foo' }, 'cookies') | ||
|
||
expect(getSyntheticsContext()).toBeUndefined() | ||
}) | ||
}) | ||
|
||
describe('willSyntheticsInjectRum', () => { | ||
afterEach(() => { | ||
cleanupSyntheticsWorkerValues() | ||
}) | ||
|
||
it('returns false if nothing is defined', () => { | ||
mockSyntheticsWorkerValues({}, 'globals') | ||
|
||
expect(willSyntheticsInjectRum()).toBeFalse() | ||
}) | ||
|
||
it('returns false if the INJECTS_RUM global variable is false', () => { | ||
mockSyntheticsWorkerValues({ injectsRum: false }, 'globals') | ||
|
||
expect(willSyntheticsInjectRum()).toBeFalse() | ||
}) | ||
|
||
it('returns true if the INJECTS_RUM global variable is truthy', () => { | ||
mockSyntheticsWorkerValues({ injectsRum: true }, 'globals') | ||
|
||
expect(willSyntheticsInjectRum()).toBeTrue() | ||
}) | ||
|
||
it('returns true if the INJECTS_RUM cookie is truthy', () => { | ||
mockSyntheticsWorkerValues({ injectsRum: true }, 'cookies') | ||
|
||
expect(willSyntheticsInjectRum()).toBeTrue() | ||
}) | ||
}) |
Oops, something went wrong.