Skip to content

Commit b1d61e6

Browse files
committed
update tests
1 parent 92a14a1 commit b1d61e6

File tree

7 files changed

+29
-4
lines changed

7 files changed

+29
-4
lines changed

packages/signals/signals/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ const { createJestTSConfig } = require('@internal/config')
22

33
module.exports = createJestTSConfig(__dirname, {
44
testEnvironment: 'jsdom',
5-
setupFilesAfterEnv: ['./jest.setup.js'],
5+
setupFilesAfterEnv: ['./jest.setup.ts'],
66
})

packages/signals/signals/jest.setup.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-disable no-undef */
2+
import 'fake-indexeddb/auto'
3+
globalThis.structuredClone = (v: any) => JSON.parse(JSON.stringify(v))
4+
5+
import './src/test-helpers/custom-snapshot-serializers'

packages/signals/signals/src/core/analytics-service/__tests__/analytics-service.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe(AnalyticsService, () => {
4242
delete call.data.page
4343
expect(call).toMatchInlineSnapshot(`
4444
{
45+
"anonymousId": "",
4546
"data": {
4647
"rawEvent": {
4748
"context": {
@@ -50,6 +51,7 @@ describe(AnalyticsService, () => {
5051
"type": "track",
5152
},
5253
},
54+
"timestamp": <ISO Timestamp>,
5355
"type": "instrumentation",
5456
}
5557
`)

packages/signals/signals/src/core/signal-generators/network-gen/__tests__/network-generator.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ describe(NetworkGenerator, () => {
9797

9898
expect(first[0]).toMatchInlineSnapshot(`
9999
{
100+
"anonymousId": "",
100101
"data": {
101102
"action": "request",
102103
"contentType": "application/json",
@@ -121,12 +122,14 @@ describe(NetworkGenerator, () => {
121122
"disallowed": [],
122123
},
123124
},
125+
"timestamp": <ISO Timestamp>,
124126
"type": "network",
125127
}
126128
`)
127129

128130
expect(second[0]).toMatchInlineSnapshot(`
129131
{
132+
"anonymousId": "",
130133
"data": {
131134
"action": "response",
132135
"contentType": "application/json",
@@ -152,6 +155,7 @@ describe(NetworkGenerator, () => {
152155
"disallowed": [],
153156
},
154157
},
158+
"timestamp": <ISO Timestamp>,
155159
"type": "network",
156160
}
157161
`)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// e.g 2025-03-18T20:27:01.459Z
2+
const isoTimestampRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
3+
4+
export const timestampSerializer: jest.SnapshotSerializerPlugin = {
5+
test(value: any) {
6+
return typeof value === 'string' && isoTimestampRegex.test(value)
7+
},
8+
print() {
9+
return '<ISO Timestamp>'
10+
},
11+
}
12+
13+
expect.addSnapshotSerializer(timestampSerializer)

packages/signals/signals/src/types/__tests__/create-network-signal.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe(createNetworkSignal, () => {
3030

3131
expect(signal).toMatchInlineSnapshot(`
3232
{
33+
"anonymousId": "",
3334
"data": {
3435
"action": "request",
3536
"contentType": "application/json",
@@ -60,6 +61,7 @@ describe(createNetworkSignal, () => {
6061
],
6162
},
6263
},
64+
"timestamp": <ISO Timestamp>,
6365
"type": "network",
6466
}
6567
`)
@@ -80,6 +82,7 @@ describe(createNetworkSignal, () => {
8082

8183
expect(signal).toMatchInlineSnapshot(`
8284
{
85+
"anonymousId": "",
8386
"data": {
8487
"action": "response",
8588
"contentType": "application/json",
@@ -111,6 +114,7 @@ describe(createNetworkSignal, () => {
111114
],
112115
},
113116
},
117+
"timestamp": <ISO Timestamp>,
114118
"type": "network",
115119
}
116120
`)

0 commit comments

Comments
 (0)