Skip to content

Commit 67e5142

Browse files
✅ fix flaky tests related to experimental features (#4207)
1 parent ff4b0a9 commit 67e5142

23 files changed

Lines changed: 54 additions & 119 deletions

packages/core/src/domain/configuration/configuration.spec.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import type { RumEvent } from '../../../../rum-core/src'
22
import { EXHAUSTIVE_INIT_CONFIGURATION, SERIALIZED_EXHAUSTIVE_INIT_CONFIGURATION } from '../../../test'
33
import type { ExtractTelemetryConfiguration, MapInitConfigurationKey } from '../../../test'
44
import { DOCS_ORIGIN, MORE_DETAILS, display } from '../../tools/display'
5-
import {
6-
ExperimentalFeature,
7-
isExperimentalFeatureEnabled,
8-
resetExperimentalFeatures,
9-
} from '../../tools/experimentalFeatures'
5+
import { ExperimentalFeature, isExperimentalFeatureEnabled } from '../../tools/experimentalFeatures'
106
import { SessionPersistence } from '../session/sessionConstants'
117
import { TrackingConsent } from '../trackingConsent'
128
import type { InitConfiguration } from './configuration'
@@ -21,10 +17,6 @@ describe('validateAndBuildConfiguration', () => {
2117
displaySpy = spyOn(display, 'error')
2218
})
2319

24-
afterEach(() => {
25-
resetExperimentalFeatures()
26-
})
27-
2820
describe('experimentalFeatures', () => {
2921
const TEST_FEATURE_FLAG = 'foo' as ExperimentalFeature
3022

packages/core/src/domain/telemetry/telemetry.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { TimeStamp } from '@datadog/browser-rum/internal'
22
import { NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/error'
33
import { callMonitored } from '../../tools/monitor'
44
import type { ExperimentalFeature } from '../../tools/experimentalFeatures'
5-
import { resetExperimentalFeatures, addExperimentalFeatures } from '../../tools/experimentalFeatures'
5+
import { addExperimentalFeatures } from '../../tools/experimentalFeatures'
66
import { validateAndBuildConfiguration, type Configuration } from '../configuration'
77
import { INTAKE_SITE_US1_FED, INTAKE_SITE_US1 } from '../intakeSites'
88
import {
@@ -87,10 +87,6 @@ describe('telemetry', () => {
8787
})
8888

8989
describe('addTelemetryConfiguration', () => {
90-
afterEach(() => {
91-
resetExperimentalFeatures()
92-
})
93-
9490
it('should collects configuration when sampled', async () => {
9591
const { getTelemetryEvents } = startAndSpyTelemetry({
9692
telemetrySampleRate: 100,

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export { TrackingConsent, createTrackingConsentState } from './domain/trackingCo
1414
export {
1515
isExperimentalFeatureEnabled,
1616
addExperimentalFeatures,
17-
resetExperimentalFeatures,
1817
getExperimentalFeatures,
1918
initFeatureFlags,
2019
ExperimentalFeature,

packages/core/src/tools/experimentalFeatures.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@ import {
33
addExperimentalFeatures,
44
initFeatureFlags,
55
isExperimentalFeatureEnabled,
6-
resetExperimentalFeatures,
76
} from './experimentalFeatures'
87

98
const TEST_FEATURE_FLAG_ONE = 'foo' as ExperimentalFeature
109
const TEST_FEATURE_FLAG_TWO = 'bar' as ExperimentalFeature
1110

1211
describe('experimentalFeatures', () => {
13-
afterEach(() => {
14-
resetExperimentalFeatures()
15-
})
16-
1712
it('initial state is empty', () => {
1813
expect(isExperimentalFeatureEnabled(TEST_FEATURE_FLAG_ONE)).toBeFalse()
1914
expect(isExperimentalFeatureEnabled(TEST_FEATURE_FLAG_TWO)).toBeFalse()
@@ -41,7 +36,6 @@ describe('initFeatureFlags', () => {
4136

4237
afterEach(() => {
4338
delete (ExperimentalFeature as any).FOO
44-
resetExperimentalFeatures()
4539
})
4640

4741
it('ignores unknown experimental features', () => {

packages/core/test/emulate/mockExperimentalFeatures.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/core/test/forEach.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { resetExperimentalFeatures } from '../src/tools/experimentalFeatures'
12
import { resetValueHistoryGlobals } from '../src/tools/valueHistory'
23
import { resetFetchObservable } from '../src/browser/fetchObservable'
34
import { resetConsoleObservable } from '../src/domain/console/consoleObservable'
@@ -35,6 +36,7 @@ afterEach(() => {
3536
resetMonitor()
3637
resetTelemetry()
3738
resetInteractionCountPolyfill()
39+
resetExperimentalFeatures()
3840
})
3941

4042
function clearAllCookies() {

packages/core/test/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export * from './emulate/mockVisibilityState'
1515
export * from './emulate/mockNavigator'
1616
export * from './emulate/mockEventBridge'
1717
export * from './emulate/mockFlushController'
18-
export * from './emulate/mockExperimentalFeatures'
1918
export * from './emulate/mockFetch'
2019
export * from './emulate/mockXhr'
2120
export * from './emulate/mockEventTarget'

packages/rum-core/src/boot/preStartRum.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
DefaultPrivacyLevel,
1111
ExperimentalFeature,
1212
startTelemetry,
13+
addExperimentalFeatures,
1314
} from '@datadog/browser-core'
1415
import type { Clock } from '@datadog/browser-core/test'
1516
import {
@@ -18,7 +19,6 @@ import {
1819
mockClock,
1920
mockEventBridge,
2021
mockSyntheticsWorkerValues,
21-
mockExperimentalFeatures,
2222
createFakeTelemetryObject,
2323
replaceMockableWithSpy,
2424
} from '@datadog/browser-core/test'
@@ -686,7 +686,7 @@ describe('preStartRum', () => {
686686
})
687687

688688
it('startAction / stopAction', () => {
689-
mockExperimentalFeatures([ExperimentalFeature.START_STOP_ACTION])
689+
addExperimentalFeatures([ExperimentalFeature.START_STOP_ACTION])
690690

691691
const startActionSpy = jasmine.createSpy()
692692
const stopActionSpy = jasmine.createSpy()

packages/rum-core/src/boot/rumPublicApi.spec.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ import {
77
ExperimentalFeature,
88
ResourceType,
99
startTelemetry,
10+
addExperimentalFeatures,
1011
} from '@datadog/browser-core'
1112
import type { Clock } from '@datadog/browser-core/test'
12-
import {
13-
createFakeTelemetryObject,
14-
mockClock,
15-
mockExperimentalFeatures,
16-
replaceMockableWithSpy,
17-
} from '@datadog/browser-core/test'
13+
import { createFakeTelemetryObject, mockClock, replaceMockableWithSpy } from '@datadog/browser-core/test'
1814
import { noopRecorderApi, noopProfilerApi } from '../../test'
1915
import { ActionType, VitalType } from '../rawRumEvent.types'
2016
import type { DurationVitalReference } from '../domain/vital/vitalCollection'
@@ -742,7 +738,7 @@ describe('rum public api', () => {
742738

743739
describe('startAction / stopAction', () => {
744740
it('should call startAction and stopAction on the strategy', () => {
745-
mockExperimentalFeatures([ExperimentalFeature.START_STOP_ACTION])
741+
addExperimentalFeatures([ExperimentalFeature.START_STOP_ACTION])
746742

747743
const startActionSpy = jasmine.createSpy()
748744
const stopActionSpy = jasmine.createSpy()
@@ -778,7 +774,7 @@ describe('rum public api', () => {
778774
})
779775

780776
it('should sanitize startAction and stopAction inputs', () => {
781-
mockExperimentalFeatures([ExperimentalFeature.START_STOP_ACTION])
777+
addExperimentalFeatures([ExperimentalFeature.START_STOP_ACTION])
782778

783779
const startActionSpy = jasmine.createSpy()
784780
const { rumPublicApi } = makeRumPublicApiWithDefaults({
@@ -824,7 +820,7 @@ describe('rum public api', () => {
824820

825821
describe('startResource / stopResource', () => {
826822
it('should call startResource and stopResource on the strategy', () => {
827-
mockExperimentalFeatures([ExperimentalFeature.START_STOP_RESOURCE])
823+
addExperimentalFeatures([ExperimentalFeature.START_STOP_RESOURCE])
828824

829825
const startResourceSpy = jasmine.createSpy()
830826
const stopResourceSpy = jasmine.createSpy()
@@ -864,7 +860,7 @@ describe('rum public api', () => {
864860
})
865861

866862
it('should sanitize startResource and stopResource inputs', () => {
867-
mockExperimentalFeatures([ExperimentalFeature.START_STOP_RESOURCE])
863+
addExperimentalFeatures([ExperimentalFeature.START_STOP_RESOURCE])
868864

869865
const startResourceSpy = jasmine.createSpy()
870866
const { rumPublicApi } = makeRumPublicApiWithDefaults({

packages/rum-core/src/domain/action/getActionNameFromElement.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ExperimentalFeature } from '@datadog/browser-core'
2-
import { mockExperimentalFeatures } from '../../../../core/test'
1+
import { addExperimentalFeatures, ExperimentalFeature } from '@datadog/browser-core'
32
import { appendElement, mockRumConfiguration } from '../../../test'
43
import { NodePrivacyLevel } from '../privacyConstants'
54
import { getNodeSelfPrivacyLevel } from '../privacy'
@@ -115,7 +114,7 @@ describe('getActionNameFromElement', () => {
115114
})
116115

117116
it('should introduce whitespace for block-level display values', () => {
118-
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
117+
addExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
119118
const testCases = [
120119
{ display: 'block', expected: 'space' },
121120
{ display: 'inline-block', expected: 'no-space' },
@@ -484,7 +483,7 @@ describe('getActionNameFromElement', () => {
484483
})
485484

486485
it('removes only the child with programmatic action name in textual content', () => {
487-
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
486+
addExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
488487
const { name, nameSource } = getActionNameFromElement(
489488
appendElement('<div>Foobar Baz<div data-dd-action-name="custom action">bar<div></div>'),
490489
defaultConfiguration
@@ -512,7 +511,7 @@ describe('getActionNameFromElement', () => {
512511
}
513512

514513
it('preserves privacy level of the element when defaultPrivacyLevel is mask-unless-allowlisted', () => {
515-
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
514+
addExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
516515
const { name, nameSource } = getActionNameFromElement(
517516
appendElement(`
518517
<div data-dd-privacy="mask">
@@ -666,7 +665,7 @@ describe('getActionNameFromElement', () => {
666665
},
667666
]
668667
testCases.forEach(({ html, defaultPrivacyLevel, allowlist, expectedName, expectedNameSource }) => {
669-
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
668+
addExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
670669
;(window as BrowserWindow).$DD_ALLOW = new Set(allowlist)
671670
const target = appendElement(html)
672671
const { name, nameSource } = getActionNameFromElement(
@@ -883,7 +882,7 @@ describe('getActionNameFromElement', () => {
883882
})
884883

885884
it('inherit privacy level and remove only the masked child', () => {
886-
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
885+
addExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
887886
expect(
888887
getActionNameFromElement(
889888
appendElement(`

0 commit comments

Comments
 (0)