Skip to content

Commit e329c06

Browse files
authored
Update to use new signals specification (#1311)
1 parent ef021fe commit e329c06

File tree

59 files changed

+236
-2122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+236
-2122
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

meta-tests/check-dts.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { exec } from 'child_process'
22
import { promisify } from 'util'
33
import path from 'path'
44
import fs from 'fs'
5+
import getPackages from 'get-monorepo-packages'
56

67
/**
78
* This script is for extra typechecking of the built .d.ts files in {package_name}/dist/types/*.
@@ -11,13 +12,19 @@ import fs from 'fs'
1112
*/
1213
const execa = promisify(exec)
1314

14-
const allPublicPackageDirNames = [
15-
'browser',
16-
'core',
17-
'node',
18-
'signals/signals',
19-
'signals/signals-runtime',
20-
] as const
15+
// Get public packages programmatically
16+
const packages = getPackages(path.join(__dirname, '..'))
17+
const publicPackageNames = [
18+
'@segment/analytics-next',
19+
'@segment/analytics-core',
20+
'@segment/analytics-node',
21+
'@segment/analytics-signals',
22+
]
23+
24+
const allPublicPackageDirNames = packages
25+
.filter((pkg) => publicPackageNames.includes(pkg.package.name))
26+
.map((pkg) => path.relative('packages', pkg.location))
27+
.sort() as readonly string[]
2128

2229
type PackageDirName = typeof allPublicPackageDirNames[number]
2330

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: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ test('network signals fetch', async () => {
2929
(el) => el.properties!.data.action === 'request'
3030
)
3131
expect(requests).toHaveLength(1)
32-
expect(requests[0].properties!.data.data).toEqual({ foo: 'bar' })
32+
expect(requests[0].properties!.data.body).toEqual({ foo: 'bar' })
3333

3434
const responses = networkEvents.filter(
3535
(el) => el.properties!.data.action === 'response'
3636
)
3737
expect(responses).toHaveLength(1)
38-
expect(responses[0].properties!.data.data).toEqual({ someResponse: 'yep' })
38+
expect(responses[0].properties!.data.body).toEqual({ someResponse: 'yep' })
3939
})
4040

4141
test('network signals xhr', async () => {
@@ -51,13 +51,13 @@ test('network signals xhr', async () => {
5151
(el) => el.properties!.data.action === 'request'
5252
)
5353
expect(requests).toHaveLength(1)
54-
expect(requests[0].properties!.data.data).toEqual({ foo: 'bar' })
54+
expect(requests[0].properties!.data.body).toEqual({ foo: 'bar' })
5555

5656
const responses = networkEvents.filter(
5757
(el) => el.properties!.data.action === 'response'
5858
)
5959
expect(responses).toHaveLength(1)
60-
expect(responses[0].properties!.data.data).toEqual({ someResponse: 'yep' })
60+
expect(responses[0].properties!.data.body).toEqual({ someResponse: 'yep' })
6161
expect(responses[0].properties!.data.page).toEqual(commonSignalData.page)
6262
})
6363

@@ -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-allow-list.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ test('network signals allow and disallow list', async ({ page }) => {
2525
)
2626
expect(allowedRequestsAndResponses).toHaveLength(2)
2727
const [request, response] = allowedRequestsAndResponses
28-
expect(request.properties!.data.data).toEqual({
28+
expect(request.properties!.data.body).toEqual({
2929
foo: 'bar',
3030
})
31-
expect(response.properties!.data.data).toEqual({
31+
expect(response.properties!.data.body).toEqual({
3232
someResponse: 'yep',
3333
})
3434

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

Lines changed: 18 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,28 +124,34 @@ 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+
const requestData = requests[0].properties!.data
128+
expect(requestData).toMatchObject({
127129
action: 'request',
128130
contentType: 'application/json',
129131
url: 'http://localhost/test',
130132
method: 'POST',
131-
data: { key: 'value' },
133+
body: { key: 'value' },
134+
requestId: NON_EMPTY_STRING,
132135
...commonSignalData,
133136
})
137+
const requestId = requestData.requestId
134138

135139
const responses = networkEvents.filter(
136140
(el) => el.properties!.data.action === 'response'
137141
)
138142
expect(responses).toHaveLength(1)
139-
expect(responses[0].properties!.data).toEqual({
143+
const responseData = responses[0].properties!.data
144+
expect(responseData).toMatchObject({
140145
action: 'response',
141146
contentType: 'application/json',
142147
url: 'http://localhost/test',
143-
data: { foo: 'test' },
148+
body: { foo: 'test' },
144149
status: 200,
145150
ok: true,
151+
requestId: NON_EMPTY_STRING,
146152
...commonSignalData,
147153
})
154+
expect(responseData.requestId).toEqual(requestId)
148155
})
149156

150157
test('can handle relative url paths', async () => {
@@ -171,7 +178,7 @@ test.describe('network signals - fetch', () => {
171178
expect(requests[0].properties!.data).toMatchObject({
172179
action: 'request',
173180
url: `${indexPage.origin()}/test`,
174-
data: { key: 'value' },
181+
body: { key: 'value' },
175182
...commonSignalData,
176183
})
177184

@@ -182,7 +189,7 @@ test.describe('network signals - fetch', () => {
182189
expect(responses[0].properties!.data).toMatchObject({
183190
action: 'response',
184191
url: `${indexPage.origin()}/test`,
185-
data: { foo: 'test' },
192+
body: { foo: 'test' },
186193
...commonSignalData,
187194
})
188195
})
@@ -220,7 +227,7 @@ test.describe('network signals - fetch', () => {
220227
expect(responses[0].properties!.data).toMatchObject({
221228
action: 'response',
222229
url: 'http://localhost/test',
223-
data: { errorMsg: 'foo' },
230+
body: { errorMsg: 'foo' },
224231
status: 400,
225232
ok: false,
226233
page: expect.any(Object),
@@ -260,7 +267,7 @@ test.describe('network signals - fetch', () => {
260267
expect(responses[0].properties!.data).toMatchObject({
261268
action: 'response',
262269
url: 'http://localhost/test',
263-
data: 'foo',
270+
body: 'foo',
264271
status: 400,
265272
ok: false,
266273
...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
})

packages/signals/signals-integration-tests/src/tests/signals-vanilla/runtime-constants.test.ts

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

packages/signals/signals-runtime/.eslintrc.js

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

packages/signals/signals-runtime/.lintstagedrc.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)