Skip to content

Commit 785242d

Browse files
committed
update package to use new spec
1 parent 25781af commit 785242d

File tree

5 files changed

+35
-29
lines changed

5 files changed

+35
-29
lines changed

.changeset/thick-cars-compete.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-signals': major
3+
---
4+
5+
Update package to use new spec

packages/signals/signals-integration-tests/src/tests/signals-vanilla/all-segment-events.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test('Should dispatch events from signals that occurred before analytics was ins
6666
}) => {
6767
const edgeFn = `
6868
globalThis.processSignal = (signal) => {
69-
if (signal.type === 'navigation' && signal.data.action === 'pageLoad') {
69+
if (signal.type === 'navigation') {
7070
analytics.page('dispatched from signals - navigation')
7171
}
7272
if (signal.type === 'userDefined') {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ test('navigation signals', async ({ page }) => {
155155
expect(ev.properties).toMatchObject({
156156
type: 'navigation',
157157
data: {
158-
action: 'pageLoad',
159-
url: indexPage.url,
158+
currentUrl: indexPage.url,
160159
path: expect.any(String),
161160
hash: '',
162161
search: '',
@@ -178,9 +177,8 @@ test('navigation signals', async ({ page }) => {
178177
index: expect.any(Number),
179178
type: 'navigation',
180179
data: {
181-
action: 'urlChange',
182-
url: indexPage.url + '#foo',
183-
prevUrl: indexPage.url,
180+
currentUrl: indexPage.url + '#foo',
181+
previousUrl: indexPage.url,
184182
path: expect.any(String),
185183
hash: '#foo',
186184
search: '',

packages/signals/signals-integration-tests/src/tests/signals-vanilla/network-signals-fetch.test.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { IndexPage } from './index-page'
44

55
const basicEdgeFn = `globalThis.processSignal = (signal) => {}`
66

7+
const NON_EMPTY_STRING = expect.stringMatching(/.+/)
8+
79
test.describe('network signals - fetch', () => {
810
let indexPage: IndexPage
911

@@ -30,7 +32,6 @@ test.describe('network signals - fetch', () => {
3032
expect(requests[0].properties!.data).toMatchObject({
3133
action: 'request',
3234
contentType: 'multipart/form-data',
33-
data: null,
3435
method: 'POST',
3536
url: 'http://localhost/upload',
3637
...commonSignalData,
@@ -62,7 +63,7 @@ test.describe('network signals - fetch', () => {
6263
expect(requests[0].properties!.data).toMatchObject({
6364
action: 'request',
6465
url: 'http://localhost/test',
65-
data: { key: 'value' },
66+
body: { key: 'value' },
6667
...commonSignalData,
6768
})
6869
})
@@ -92,7 +93,7 @@ test.describe('network signals - fetch', () => {
9293
expect(requests[0].properties!.data).toMatchObject({
9394
action: 'request',
9495
url: 'http://localhost/test',
95-
data: 'hello world',
96+
body: 'hello world',
9697
...commonSignalData,
9798
})
9899
})
@@ -123,26 +124,28 @@ test.describe('network signals - fetch', () => {
123124
(el) => el.properties!.data.action === 'request'
124125
)
125126
expect(requests).toHaveLength(1)
126-
expect(requests[0].properties!.data).toEqual({
127+
expect(requests[0].properties!.data).toMatchObject({
127128
action: 'request',
128129
contentType: 'application/json',
129130
url: 'http://localhost/test',
130131
method: 'POST',
131-
data: { key: 'value' },
132+
body: { key: 'value' },
133+
requestId: NON_EMPTY_STRING,
132134
...commonSignalData,
133135
})
134136

135137
const responses = networkEvents.filter(
136138
(el) => el.properties!.data.action === 'response'
137139
)
138140
expect(responses).toHaveLength(1)
139-
expect(responses[0].properties!.data).toEqual({
141+
expect(responses[0].properties!.data).toMatchObject({
140142
action: 'response',
141143
contentType: 'application/json',
142144
url: 'http://localhost/test',
143-
data: { foo: 'test' },
145+
body: { foo: 'test' },
144146
status: 200,
145147
ok: true,
148+
requestId: NON_EMPTY_STRING,
146149
...commonSignalData,
147150
})
148151
})
@@ -171,7 +174,7 @@ test.describe('network signals - fetch', () => {
171174
expect(requests[0].properties!.data).toMatchObject({
172175
action: 'request',
173176
url: `${indexPage.origin()}/test`,
174-
data: { key: 'value' },
177+
body: { key: 'value' },
175178
...commonSignalData,
176179
})
177180

@@ -182,7 +185,7 @@ test.describe('network signals - fetch', () => {
182185
expect(responses[0].properties!.data).toMatchObject({
183186
action: 'response',
184187
url: `${indexPage.origin()}/test`,
185-
data: { foo: 'test' },
188+
body: { foo: 'test' },
186189
...commonSignalData,
187190
})
188191
})
@@ -220,7 +223,7 @@ test.describe('network signals - fetch', () => {
220223
expect(responses[0].properties!.data).toMatchObject({
221224
action: 'response',
222225
url: 'http://localhost/test',
223-
data: { errorMsg: 'foo' },
226+
body: { errorMsg: 'foo' },
224227
status: 400,
225228
ok: false,
226229
page: expect.any(Object),
@@ -260,7 +263,7 @@ test.describe('network signals - fetch', () => {
260263
expect(responses[0].properties!.data).toMatchObject({
261264
action: 'response',
262265
url: 'http://localhost/test',
263-
data: 'foo',
266+
body: 'foo',
264267
status: 400,
265268
ok: false,
266269
...commonSignalData,

packages/signals/signals-integration-tests/src/tests/signals-vanilla/network-signals-xhr.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test.describe('network signals - XHR', () => {
3434
expect(requests[0].properties!.data).toMatchObject({
3535
action: 'request',
3636
url: 'http://localhost/test',
37-
data: { key: 'value' },
37+
body: { key: 'value' },
3838
})
3939

4040
// Check the response
@@ -45,7 +45,7 @@ test.describe('network signals - XHR', () => {
4545
expect(responses[0].properties!.data).toMatchObject({
4646
action: 'response',
4747
url: 'http://localhost/test',
48-
data: { foo: 'test' },
48+
body: { foo: 'test' },
4949
})
5050
})
5151

@@ -74,7 +74,7 @@ test.describe('network signals - XHR', () => {
7474
expect(requests[0].properties!.data).toMatchObject({
7575
action: 'request',
7676
url: `${indexPage.origin()}/test`,
77-
data: { key: 'value' },
77+
body: { key: 'value' },
7878
})
7979

8080
// Check the response
@@ -85,7 +85,7 @@ test.describe('network signals - XHR', () => {
8585
expect(responses[0].properties!.data).toMatchObject({
8686
action: 'response',
8787
url: `${indexPage.origin()}/test`,
88-
data: { foo: 'test' },
88+
body: { foo: 'test' },
8989
})
9090
})
9191

@@ -114,7 +114,7 @@ test.describe('network signals - XHR', () => {
114114
expect(requests[0].properties!.data).toMatchObject({
115115
action: 'request',
116116
url: 'http://localhost/test',
117-
data: 'hello world',
117+
body: 'hello world',
118118
})
119119

120120
// Check the response
@@ -125,7 +125,7 @@ test.describe('network signals - XHR', () => {
125125
expect(responses[0].properties!.data).toMatchObject({
126126
action: 'response',
127127
url: 'http://localhost/test',
128-
data: { foo: 'test' },
128+
body: { foo: 'test' },
129129
})
130130
})
131131

@@ -153,7 +153,7 @@ test.describe('network signals - XHR', () => {
153153
expect(responses[0].properties!.data).toMatchObject({
154154
action: 'response',
155155
url: 'http://localhost/test',
156-
data: { hello: 'world' },
156+
body: { hello: 'world' },
157157
})
158158
})
159159

@@ -200,15 +200,15 @@ test.describe('network signals - XHR', () => {
200200
expect(request1.properties!.data).toMatchObject({
201201
action: 'request',
202202
url: req1URL,
203-
data: { req1: 'value' },
203+
body: { req1: 'value' },
204204
})
205205

206206
const request2 = requests.find((u) => u.properties!.data.url === req2URL)!
207207
expect(request2).toBeDefined()
208208
expect(request2.properties!.data).toMatchObject({
209209
action: 'request',
210210
url: req2URL,
211-
data: { req2: 'value' },
211+
body: { req2: 'value' },
212212
})
213213
})
214214

@@ -246,7 +246,7 @@ test.describe('network signals - XHR', () => {
246246
expect(responses[0].properties!.data).toMatchObject({
247247
action: 'response',
248248
url: 'http://localhost/test',
249-
data: { errorMsg: 'foo' },
249+
body: { errorMsg: 'foo' },
250250
})
251251
expect(responses).toHaveLength(1)
252252
})
@@ -284,7 +284,7 @@ test.describe('network signals - XHR', () => {
284284
expect(responses[0].properties!.data).toMatchObject({
285285
action: 'response',
286286
url: 'http://localhost/test',
287-
data: 'foo',
287+
body: 'foo',
288288
})
289289
expect(responses).toHaveLength(1)
290290
})
@@ -325,7 +325,7 @@ test.describe('network signals - XHR', () => {
325325
expect(responses[0].properties!.data).toMatchObject({
326326
action: 'response',
327327
url: 'http://localhost/test',
328-
data: null,
328+
body: null,
329329
})
330330
expect(responses).toHaveLength(1)
331331
})

0 commit comments

Comments
 (0)