Skip to content

Commit 9f4b4a3

Browse files
committed
wip
1 parent 3290eea commit 9f4b4a3

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { test, expect } from '@playwright/test'
2+
import { IndexPage } from './index-page'
3+
4+
const basicEdgeFn = `
5+
const processSignal = (signal) => {
6+
// test that constants are properly injected
7+
if (typeof EventType !== 'object') {
8+
throw new Error('EventType is missing?')
9+
}
10+
if (typeof SignalType !== 'object') {
11+
throw new Error('SignalType is missing?')
12+
}
13+
if (typeof NavigationAction !== 'object') {
14+
throw new Error('NavigationAction is missing?')
15+
}
16+
17+
if (signal.type === SignalType.Interaction) {
18+
const eventName = signal.data.eventType + ' ' + '[' + signal.type + ']'
19+
analytics.track(eventName, signal.data)
20+
}
21+
}`
22+
23+
let indexPage: IndexPage
24+
25+
test.beforeEach(async ({ page }) => {
26+
indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn)
27+
})
28+
29+
test('constants should be accessible in the runtime', async () => {
30+
/**
31+
* Make a button click, see if it:
32+
* - creates an interaction signal that sends to the signals endpoint
33+
* - creates an analytics event that sends to the tracking endpoint
34+
*/
35+
await Promise.all([
36+
indexPage.clickButton(),
37+
indexPage.waitForTrackingApiFlush(),
38+
])
39+
40+
const analyticsReqJSON = indexPage.trackingAPI.lastEvent()
41+
expect(analyticsReqJSON).toMatchObject({
42+
event: 'click [interaction]',
43+
})
44+
})

packages/signals/signals-runtime/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export { SignalsRuntime } from './shared/signals-runtime'
44
// web
55
export * from './web/web-signals-types'
66
export * from './shared/shared-types'
7-
export * as WebConstants from './web/web-constants'
7+
export * as WebRuntimeConstants from './web/web-constants'
88

99
// mobile
1010
export * as Mobile from './mobile/mobile-signals-types'
11-
export * as MobileConstants from './mobile/mobile-constants'
11+
export * as MobileRuntimeConstants from './mobile/mobile-constants'

packages/signals/signals/src/core/processor/sandbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { replaceBaseUrl } from '../../lib/replace-base-url'
66
import {
77
SignalsRuntime,
88
Signal,
9-
WebConstants,
9+
WebRuntimeConstants,
1010
} from '@segment/analytics-signals-runtime'
1111

1212
export type MethodName =
@@ -211,7 +211,7 @@ export class Sandbox {
211211
const analytics = new AnalyticsRuntime()
212212
const scope = {
213213
analytics,
214-
...WebConstants,
214+
...WebRuntimeConstants,
215215
}
216216
logger.debug('processing signal', { signal, scope, signals })
217217
const code = [

packages/signals/signals/src/types/process-signal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
ISignalsRuntime,
33
Signal,
4-
WebConstants,
4+
WebRuntimeConstants,
55
} from '@segment/analytics-signals-runtime'
66

77
/**
@@ -19,7 +19,7 @@ export interface AnalyticsRuntimePublicApi {
1919
export type ProcessSignalScope = {
2020
analytics: AnalyticsRuntimePublicApi
2121
signals: ISignalsRuntime<Signal>
22-
} & typeof WebConstants
22+
} & typeof WebRuntimeConstants
2323

2424
export interface ProcessSignal {
2525
(signal: Signal, ctx: ProcessSignalScope): void

0 commit comments

Comments
 (0)