Skip to content

Commit d8bd0df

Browse files
committed
add sample rate option, clean up tests
1 parent d5ca99c commit d8bd0df

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

packages/signals/signals-integration-tests/src/helpers/base-page-object.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
SignalAPIRequestBuffer,
88
TrackingAPIRequestBuffer,
99
} from './network-utils'
10-
import { CDNSettings } from '@segment/analytics-next'
1110

1211
export class BasePage {
1312
protected page!: Page
@@ -42,14 +41,13 @@ export class BasePage {
4241
page: Page,
4342
edgeFn: string,
4443
signalSettings: Partial<SignalsPluginSettingsConfig> = {},
45-
options: { updateURL?: (url: string) => string } = {},
46-
cdnSettings?: Partial<CDNSettings>
44+
options: { updateURL?: (url: string) => string; sampleRate?: number } = {}
4745
) {
4846
logConsole(page)
4947
this.page = page
5048
this.network = new PageNetworkUtils(page)
5149
this.edgeFn = edgeFn
52-
await this.setupMockedRoutes(cdnSettings)
50+
await this.setupMockedRoutes(options.sampleRate)
5351
const url = options.updateURL ? options.updateURL(this.url) : this.url
5452
await this.page.goto(url, { waitUntil: 'domcontentloaded' })
5553
void this.invokeAnalyticsLoad({
@@ -94,15 +92,15 @@ export class BasePage {
9492
return this
9593
}
9694

97-
private async setupMockedRoutes(settings?: Partial<CDNSettings>) {
95+
private async setupMockedRoutes(sampleRate?: number) {
9896
// clear any existing saved requests
9997
this.trackingAPI.clear()
10098
this.signalsAPI.clear()
10199

102100
await Promise.all([
103101
this.mockSignalsApi(),
104102
this.mockTrackingApi(),
105-
this.mockCDNSettings(settings),
103+
this.mockCDNSettings(sampleRate),
106104
])
107105
}
108106

@@ -205,7 +203,7 @@ export class BasePage {
205203
})
206204
}
207205

208-
async mockCDNSettings(settings?: Partial<CDNSettings>) {
206+
async mockCDNSettings(sampleRate?: number) {
209207
await this.page.route(
210208
'https://cdn.segment.com/v1/projects/*/settings',
211209
(route, request) => {
@@ -215,11 +213,14 @@ export class BasePage {
215213

216214
const cdnSettings = new CDNSettingsBuilder({
217215
writeKey: '<SOME_WRITE_KEY>',
218-
baseCDNSettings: settings ?? {
216+
baseCDNSettings: {
219217
edgeFunction: {
220218
downloadURL: this.edgeFnDownloadURL,
221219
version: 1,
222220
},
221+
autoInstrumentationSettings: {
222+
sampleRate: sampleRate ?? 1,
223+
},
223224
},
224225
}).build()
225226

packages/signals/signals-integration-tests/src/tests/signals-vanilla/signals-ingestion.test.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,8 @@ test('never sends signal when sample rate is 0', async ({ page }) => {
3636
flushAt: 1,
3737
enableSignalsIngestion: false,
3838
},
39-
undefined,
4039
{
41-
edgeFunction: {
42-
downloadURL: 'https://cdn.edgefn.segment.com/MY-WRITEKEY/foo.js',
43-
version: 1,
44-
},
45-
autoInstrumentationSettings: {
46-
sampleRate: 0,
47-
},
40+
sampleRate: 0,
4841
}
4942
)
5043
await indexPage.fillNameInput('John Doe')
@@ -60,15 +53,8 @@ test('always sends signal when sample rate is 1', async ({ page }) => {
6053
flushAt: 1,
6154
enableSignalsIngestion: false,
6255
},
63-
undefined,
6456
{
65-
edgeFunction: {
66-
downloadURL: 'https://cdn.edgefn.segment.com/MY-WRITEKEY/foo.js',
67-
version: 1,
68-
},
69-
autoInstrumentationSettings: {
70-
sampleRate: 1,
71-
},
57+
sampleRate: 1,
7258
}
7359
)
7460
await indexPage.fillNameInput('John Doe')

0 commit comments

Comments
 (0)