Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thick-cars-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-signals': major
---

Update package to use new spec
21 changes: 14 additions & 7 deletions meta-tests/check-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { exec } from 'child_process'
import { promisify } from 'util'
import path from 'path'
import fs from 'fs'
import getPackages from 'get-monorepo-packages'

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

const allPublicPackageDirNames = [
'browser',
'core',
'node',
'signals/signals',
'signals/signals-runtime',
] as const
// Get public packages programmatically
const packages = getPackages(path.join(__dirname, '..'))
const publicPackageNames = [
'@segment/analytics-next',
'@segment/analytics-core',
'@segment/analytics-node',
'@segment/analytics-signals',
]

const allPublicPackageDirNames = packages
.filter((pkg) => publicPackageNames.includes(pkg.package.name))
.map((pkg) => path.relative('packages', pkg.location))
.sort() as readonly string[]

type PackageDirName = typeof allPublicPackageDirNames[number]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test('Should dispatch events from signals that occurred before analytics was ins
}) => {
const edgeFn = `
globalThis.processSignal = (signal) => {
if (signal.type === 'navigation' && signal.data.action === 'pageLoad') {
if (signal.type === 'navigation') {
analytics.page('dispatched from signals - navigation')
}
if (signal.type === 'userDefined') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ test('network signals fetch', async () => {
(el) => el.properties!.data.action === 'request'
)
expect(requests).toHaveLength(1)
expect(requests[0].properties!.data.data).toEqual({ foo: 'bar' })
expect(requests[0].properties!.data.body).toEqual({ foo: 'bar' })

const responses = networkEvents.filter(
(el) => el.properties!.data.action === 'response'
)
expect(responses).toHaveLength(1)
expect(responses[0].properties!.data.data).toEqual({ someResponse: 'yep' })
expect(responses[0].properties!.data.body).toEqual({ someResponse: 'yep' })
})

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

const responses = networkEvents.filter(
(el) => el.properties!.data.action === 'response'
)
expect(responses).toHaveLength(1)
expect(responses[0].properties!.data.data).toEqual({ someResponse: 'yep' })
expect(responses[0].properties!.data.body).toEqual({ someResponse: 'yep' })
expect(responses[0].properties!.data.page).toEqual(commonSignalData.page)
})

Expand Down Expand Up @@ -155,8 +155,7 @@ test('navigation signals', async ({ page }) => {
expect(ev.properties).toMatchObject({
type: 'navigation',
data: {
action: 'pageLoad',
url: indexPage.url,
currentUrl: indexPage.url,
path: expect.any(String),
hash: '',
search: '',
Expand All @@ -178,9 +177,8 @@ test('navigation signals', async ({ page }) => {
index: expect.any(Number),
type: 'navigation',
data: {
action: 'urlChange',
url: indexPage.url + '#foo',
prevUrl: indexPage.url,
currentUrl: indexPage.url + '#foo',
previousUrl: indexPage.url,
path: expect.any(String),
hash: '#foo',
search: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ test('network signals allow and disallow list', async ({ page }) => {
)
expect(allowedRequestsAndResponses).toHaveLength(2)
const [request, response] = allowedRequestsAndResponses
expect(request.properties!.data.data).toEqual({
expect(request.properties!.data.body).toEqual({
foo: 'bar',
})
expect(response.properties!.data.data).toEqual({
expect(response.properties!.data.body).toEqual({
someResponse: 'yep',
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { IndexPage } from './index-page'

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

const NON_EMPTY_STRING = expect.stringMatching(/.+/)

test.describe('network signals - fetch', () => {
let indexPage: IndexPage

Expand All @@ -30,7 +32,6 @@ test.describe('network signals - fetch', () => {
expect(requests[0].properties!.data).toMatchObject({
action: 'request',
contentType: 'multipart/form-data',
data: null,
method: 'POST',
url: 'http://localhost/upload',
...commonSignalData,
Expand Down Expand Up @@ -62,7 +63,7 @@ test.describe('network signals - fetch', () => {
expect(requests[0].properties!.data).toMatchObject({
action: 'request',
url: 'http://localhost/test',
data: { key: 'value' },
body: { key: 'value' },
...commonSignalData,
})
})
Expand Down Expand Up @@ -92,7 +93,7 @@ test.describe('network signals - fetch', () => {
expect(requests[0].properties!.data).toMatchObject({
action: 'request',
url: 'http://localhost/test',
data: 'hello world',
body: 'hello world',
...commonSignalData,
})
})
Expand Down Expand Up @@ -123,28 +124,34 @@ test.describe('network signals - fetch', () => {
(el) => el.properties!.data.action === 'request'
)
expect(requests).toHaveLength(1)
expect(requests[0].properties!.data).toEqual({
const requestData = requests[0].properties!.data
expect(requestData).toMatchObject({
action: 'request',
contentType: 'application/json',
url: 'http://localhost/test',
method: 'POST',
data: { key: 'value' },
body: { key: 'value' },
requestId: NON_EMPTY_STRING,
...commonSignalData,
})
const requestId = requestData.requestId

const responses = networkEvents.filter(
(el) => el.properties!.data.action === 'response'
)
expect(responses).toHaveLength(1)
expect(responses[0].properties!.data).toEqual({
const responseData = responses[0].properties!.data
expect(responseData).toMatchObject({
action: 'response',
contentType: 'application/json',
url: 'http://localhost/test',
data: { foo: 'test' },
body: { foo: 'test' },
status: 200,
ok: true,
requestId: NON_EMPTY_STRING,
...commonSignalData,
})
expect(responseData.requestId).toEqual(requestId)
})

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

Expand All @@ -182,7 +189,7 @@ test.describe('network signals - fetch', () => {
expect(responses[0].properties!.data).toMatchObject({
action: 'response',
url: `${indexPage.origin()}/test`,
data: { foo: 'test' },
body: { foo: 'test' },
...commonSignalData,
})
})
Expand Down Expand Up @@ -220,7 +227,7 @@ test.describe('network signals - fetch', () => {
expect(responses[0].properties!.data).toMatchObject({
action: 'response',
url: 'http://localhost/test',
data: { errorMsg: 'foo' },
body: { errorMsg: 'foo' },
status: 400,
ok: false,
page: expect.any(Object),
Expand Down Expand Up @@ -260,7 +267,7 @@ test.describe('network signals - fetch', () => {
expect(responses[0].properties!.data).toMatchObject({
action: 'response',
url: 'http://localhost/test',
data: 'foo',
body: 'foo',
status: 400,
ok: false,
...commonSignalData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test.describe('network signals - XHR', () => {
expect(requests[0].properties!.data).toMatchObject({
action: 'request',
url: 'http://localhost/test',
data: { key: 'value' },
body: { key: 'value' },
})

// Check the response
Expand All @@ -45,7 +45,7 @@ test.describe('network signals - XHR', () => {
expect(responses[0].properties!.data).toMatchObject({
action: 'response',
url: 'http://localhost/test',
data: { foo: 'test' },
body: { foo: 'test' },
})
})

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

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

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

// Check the response
Expand All @@ -125,7 +125,7 @@ test.describe('network signals - XHR', () => {
expect(responses[0].properties!.data).toMatchObject({
action: 'response',
url: 'http://localhost/test',
data: { foo: 'test' },
body: { foo: 'test' },
})
})

Expand Down Expand Up @@ -153,7 +153,7 @@ test.describe('network signals - XHR', () => {
expect(responses[0].properties!.data).toMatchObject({
action: 'response',
url: 'http://localhost/test',
data: { hello: 'world' },
body: { hello: 'world' },
})
})

Expand Down Expand Up @@ -200,15 +200,15 @@ test.describe('network signals - XHR', () => {
expect(request1.properties!.data).toMatchObject({
action: 'request',
url: req1URL,
data: { req1: 'value' },
body: { req1: 'value' },
})

const request2 = requests.find((u) => u.properties!.data.url === req2URL)!
expect(request2).toBeDefined()
expect(request2.properties!.data).toMatchObject({
action: 'request',
url: req2URL,
data: { req2: 'value' },
body: { req2: 'value' },
})
})

Expand Down Expand Up @@ -246,7 +246,7 @@ test.describe('network signals - XHR', () => {
expect(responses[0].properties!.data).toMatchObject({
action: 'response',
url: 'http://localhost/test',
data: { errorMsg: 'foo' },
body: { errorMsg: 'foo' },
})
expect(responses).toHaveLength(1)
})
Expand Down Expand Up @@ -284,7 +284,7 @@ test.describe('network signals - XHR', () => {
expect(responses[0].properties!.data).toMatchObject({
action: 'response',
url: 'http://localhost/test',
data: 'foo',
body: 'foo',
})
expect(responses).toHaveLength(1)
})
Expand Down Expand Up @@ -325,7 +325,7 @@ test.describe('network signals - XHR', () => {
expect(responses[0].properties!.data).toMatchObject({
action: 'response',
url: 'http://localhost/test',
data: null,
body: null,
})
expect(responses).toHaveLength(1)
})
Expand Down

This file was deleted.

7 changes: 0 additions & 7 deletions packages/signals/signals-runtime/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/signals/signals-runtime/.lintstagedrc.js

This file was deleted.

Loading