Skip to content

Commit c630e06

Browse files
committed
wip
1 parent 12bf705 commit c630e06

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

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

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ test('network signals fetch', async () => {
3535
(el) => el.properties!.data.action === 'response'
3636
)
3737
expect(responses).toHaveLength(1)
38-
const signalData = responses[0].properties!.data
39-
expect(signalData.data).toEqual({ someResponse: 'yep' })
40-
expect(signalData.anonymousId).toBe(responses[0].anonymousId)
41-
expect(signalData.timestamp).toMatch(isoDateRegEx)
38+
expect(responses[0].properties!.data.data).toEqual({ someResponse: 'yep' })
4239
})
4340

4441
test('network signals xhr', async () => {
@@ -64,8 +61,7 @@ test('network signals xhr', async () => {
6461
expect(responses[0].properties!.data.page).toEqual(commonSignalData.page)
6562
})
6663

67-
const isoDateRegEx = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
68-
test.only('instrumentation signals', async () => {
64+
test('instrumentation signals', async () => {
6965
/**
7066
* Make an analytics.page() call, see if it gets sent to the signals endpoint
7167
*/
@@ -74,20 +70,17 @@ test.only('instrumentation signals', async () => {
7470
indexPage.waitForSignalsApiFlush(),
7571
])
7672

73+
const isoDateRegEx = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
7774
const instrumentationEvents =
7875
indexPage.signalsAPI.getEvents('instrumentation')
7976
expect(instrumentationEvents).toHaveLength(1)
8077
const ev = instrumentationEvents[0]
8178
expect(ev.event).toBe('Segment Signal Generated')
8279
expect(ev.type).toBe('track')
8380
const rawEvent = ev.properties!.data.rawEvent
84-
expect(ev.properties!.type).toBe('instrumentation')
85-
expect(ev.properties!.timestamp).toMatch(isoDateRegEx)
86-
expect(ev.properties!.anonymousId).toBe(ev.anonymousId)
87-
expect(ev.properties)
8881
expect(rawEvent).toMatchObject({
8982
type: 'page',
90-
anonymousId: ev.anonymousId,
83+
anonymousId: expect.any(String),
9184
timestamp: expect.stringMatching(isoDateRegEx),
9285
})
9386
})
@@ -130,8 +123,6 @@ test('interaction signals', async () => {
130123
type: 'track',
131124
properties: {
132125
type: 'interaction',
133-
anonymousId: interactionSignals[0].anonymousId,
134-
timestamp: expect.stringMatching(isoDateRegEx),
135126
data,
136127
},
137128
})
@@ -163,8 +154,6 @@ test('navigation signals', async ({ page }) => {
163154
const ev = indexPage.signalsAPI.lastEvent('navigation')
164155
expect(ev.properties).toMatchObject({
165156
type: 'navigation',
166-
anonymousId: ev.anonymousId,
167-
timestamp: expect.stringMatching(isoDateRegEx),
168157
data: {
169158
action: 'pageLoad',
170159
url: indexPage.url,
@@ -187,8 +176,6 @@ test('navigation signals', async ({ page }) => {
187176
const ev = indexPage.signalsAPI.lastEvent('navigation')
188177
expect(ev.properties).toMatchObject({
189178
index: expect.any(Number),
190-
anonymousId: ev.anonymousId,
191-
timestamp: expect.stringMatching(isoDateRegEx),
192179
type: 'navigation',
193180
data: {
194181
action: 'urlChange',

packages/signals/signals-integration-tests/src/tests/signals-vanilla/top-level-metadata.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { test, expect } from '@playwright/test'
2+
import { waitForCondition } from '../../helpers/playwright-utils'
23
import { IndexPage } from './index-page'
34

45
const basicEdgeFn = `
56
// this is a process signal function
6-
const processSignal = (signal) => {}
7+
const processSignal = (signal) => {
8+
if (signal.type === 'interaction') {
9+
analytics.track('hello', { myAnonId: signal.anonymousId, myTimestamp: signal.timestamp })
10+
}
11+
}
712
`
813

914
let indexPage: IndexPage
@@ -49,4 +54,18 @@ test('Signals should have anonymousId and timestamp at top level', async () => {
4954
expect(event.properties).toMatchObject(expected)
5055
})
5156
})
57+
58+
const getCreatedEvent = () =>
59+
indexPage.trackingAPI
60+
.getEvents()
61+
.find((el) => el.type === 'track' && el.event === 'hello')
62+
63+
await waitForCondition(() => !!getCreatedEvent(), {
64+
errorMessage: 'No track events found, should have an event',
65+
})
66+
const event = getCreatedEvent()!
67+
expect(event.properties).toEqual({
68+
myAnonId: event.anonymousId,
69+
myTimestamp: expect.stringMatching(isoDateRegEx),
70+
})
5271
})

0 commit comments

Comments
 (0)