Skip to content

Commit 90ef369

Browse files
committed
Merge branch 'master' into ssoonmi/surveys-open-ended-choices
2 parents cccccbd + bde00d8 commit 90ef369

Some content is hidden

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

42 files changed

+1961
-1764
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ module.exports = {
8888
files: 'cypress/**/*',
8989
globals: {
9090
cy: true,
91+
Cypress: true,
9192
},
9293
},
9394
],

.github/workflows/library-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- run: yarn install && yarn build
4040

4141
- name: Cypress run
42-
uses: cypress-io/github-action@v4
42+
uses: cypress-io/github-action@v6
4343

4444
functional:
4545
name: Functional tests

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 1.92.1 - 2023-11-21
2+
3+
- feat: payload capture - move timing into copied plugin (#902)
4+
5+
## 1.92.0 - 2023-11-20
6+
7+
- feat: Create elements chain string as we store it (#823)
8+
- Move blocked UAs to own file (#905)
9+
- chore: deflake a test (#904)
10+
- chore: convert more tests to TS (#903)
11+
- latest cypress action version (#900)
12+
113
## 1.91.1 - 2023-11-15
214

315
- fix(surveys): button text field fix (#899)

cypress/e2e/capture.cy.js

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,17 @@ describe('Event capture', () => {
1212

1313
// :TRICKY: Use a custom start command over beforeEach to deal with given2 not being ready yet.
1414
const start = ({ waitForDecide = true } = {}) => {
15-
cy.route({
16-
method: 'POST',
17-
url: '**/decide/*',
18-
response: {
19-
config: {
20-
enable_collect_everything: true,
21-
},
22-
editorParams: {},
23-
featureFlags: ['session-recording-player'],
24-
isAuthenticated: false,
25-
sessionRecording: given.sessionRecording,
26-
supportedCompression: given.supportedCompression,
27-
excludedDomains: [],
28-
autocaptureExceptions: false,
15+
cy.intercept('POST', '**/decide/*', {
16+
config: {
17+
enable_collect_everything: true,
2918
},
19+
editorParams: {},
20+
featureFlags: ['session-recording-player'],
21+
isAuthenticated: false,
22+
sessionRecording: given.sessionRecording,
23+
supportedCompression: given.supportedCompression,
24+
excludedDomains: [],
25+
autocaptureExceptions: false,
3026
}).as('decide')
3127

3228
cy.visit('./playground/cypress-full')
@@ -220,8 +216,9 @@ describe('Event capture', () => {
220216
it('makes a single decide request', () => {
221217
start()
222218

223-
cy.wait(200)
224-
cy.shouldBeCalled('decide', 1)
219+
cy.get('@decide.all').then((calls) => {
220+
expect(calls.length).to.equal(1)
221+
})
225222

226223
cy.phCaptures().should('include', '$pageview')
227224
cy.get('@decide').should(({ request }) => {
@@ -238,7 +235,8 @@ describe('Event capture', () => {
238235

239236
it('captures $snapshot events', () => {
240237
start()
241-
238+
// de-flake the test
239+
cy.wait(100)
242240
cy.phCaptures().should('include', '$snapshot')
243241
})
244242

@@ -322,31 +320,32 @@ describe('Event capture', () => {
322320
it('contains the correct payload after an event', () => {
323321
start()
324322
// Pageview will be sent immediately
325-
cy.wait('@capture').should(({ request, url }) => {
326-
expect(request.headers).to.eql({
327-
'Content-Type': 'application/x-www-form-urlencoded',
328-
})
323+
cy.wait('@capture').should(({ request }) => {
324+
expect(request.headers['content-type']).to.eql('application/x-www-form-urlencoded')
329325

330-
expect(url).to.match(urlWithVersion)
326+
expect(request.url).to.match(urlWithVersion)
331327
const data = decodeURIComponent(request.body.match(/data=(.*)/)[1])
332328
const captures = JSON.parse(Buffer.from(data, 'base64'))
333329

334330
expect(captures['event']).to.equal('$pageview')
335331
})
336332

333+
// the code below is going to trigger an event capture
334+
// we want to assert on the request
335+
cy.intercept('POST', '**/e/*', async (request) => {
336+
expect(request.headers['content-type']).to.eq('text/plain')
337+
338+
const captures = await getGzipEncodedPayload(request)
339+
expect(captures.map(({ event }) => event)).to.deep.equal(['$autocapture', 'custom-event'])
340+
}).as('capture-assertion')
341+
337342
cy.get('[data-cy-custom-event-button]').click()
338343
cy.phCaptures().should('have.length', 3)
339344
cy.phCaptures().should('include', '$pageview')
340345
cy.phCaptures().should('include', '$autocapture')
341346
cy.phCaptures().should('include', 'custom-event')
342347

343-
cy.wait('@capture').its('requestBody.type').should('deep.equal', 'text/plain')
344-
345-
cy.get('@capture').should(async ({ requestBody }) => {
346-
const captures = await getGzipEncodedPayload(requestBody)
347-
348-
expect(captures.map(({ event }) => event)).to.deep.equal(['$autocapture', 'custom-event'])
349-
})
348+
cy.wait('@capture-assertion')
350349
})
351350
})
352351
})
@@ -374,11 +373,12 @@ describe('Event capture', () => {
374373
cy.get('[data-cy-input]')
375374
.type('hello posthog!')
376375
.then(() => {
377-
const requests = cy
378-
.state('requests')
379-
.filter(({ alias }) => alias === 'session-recording' || alias === 'recorder')
380-
expect(requests.length).to.be.equal(0)
376+
cy.get('@session-recording.all').then((calls) => {
377+
expect(calls.length).to.equal(0)
378+
})
381379
})
380+
381+
cy.phCaptures().should('not.include', '$snapshot')
382382
})
383383
})
384384

@@ -394,8 +394,9 @@ describe('Event capture', () => {
394394
it('makes a single decide request on start', () => {
395395
start()
396396

397-
cy.wait(200)
398-
cy.shouldBeCalled('decide', 1)
397+
cy.get('@decide.all').then((calls) => {
398+
expect(calls.length).to.equal(1)
399+
})
399400

400401
cy.get('@decide').should(({ request }) => {
401402
const payload = getBase64EncodedPayload(request)
@@ -419,14 +420,19 @@ describe('Event capture', () => {
419420
start()
420421

421422
cy.wait(200)
422-
cy.shouldBeCalled('decide', 1)
423+
cy.get('@decide.all').then((calls) => {
424+
expect(calls.length).to.equal(1)
425+
})
423426

424427
cy.posthog().invoke('group', 'company', 'id:6')
425428
cy.posthog().invoke('group', 'playlist', 'id:77')
426429
cy.posthog().invoke('group', 'anothergroup', 'id:99')
427430

428431
cy.wait('@decide')
429-
cy.shouldBeCalled('decide', 2)
432+
433+
cy.get('@decide.all').then((calls) => {
434+
expect(calls.length).to.equal(2)
435+
})
430436
})
431437
})
432438
})

cypress/e2e/session-recording.cy.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ describe('Session recording', () => {
1313

1414
describe('array.full.js', () => {
1515
beforeEach(() => {
16-
cy.route({
17-
method: 'POST',
18-
url: '**/decide/*',
19-
response: {
20-
config: { enable_collect_everything: false },
21-
editorParams: {},
22-
featureFlags: ['session-recording-player'],
23-
isAuthenticated: false,
24-
sessionRecording: {
25-
endpoint: '/ses/',
26-
},
27-
capture_performance: true,
16+
cy.intercept('POST', '**/decide/*', {
17+
config: { enable_collect_everything: false },
18+
editorParams: {},
19+
featureFlags: ['session-recording-player'],
20+
isAuthenticated: false,
21+
sessionRecording: {
22+
endpoint: '/ses/',
2823
},
24+
capture_performance: true,
2925
}).as('decide')
3026

3127
cy.visit('./playground/cypress-full')
@@ -58,20 +54,16 @@ describe('Session recording', () => {
5854

5955
describe('array.js', () => {
6056
beforeEach(() => {
61-
cy.route({
62-
method: 'POST',
63-
url: '**/decide/*',
64-
response: {
65-
config: { enable_collect_everything: false },
66-
editorParams: {},
67-
featureFlags: ['session-recording-player'],
68-
isAuthenticated: false,
69-
sessionRecording: {
70-
endpoint: '/ses/',
71-
},
72-
supportedCompression: ['gzip', 'lz64'],
73-
capture_performance: true,
57+
cy.intercept('POST', '**/decide/*', {
58+
config: { enable_collect_everything: false },
59+
editorParams: {},
60+
featureFlags: ['session-recording-player'],
61+
isAuthenticated: false,
62+
sessionRecording: {
63+
endpoint: '/ses/',
7464
},
65+
supportedCompression: ['gzip', 'lz64'],
66+
capture_performance: true,
7567
}).as('decide')
7668

7769
cy.visit('./playground/cypress')

cypress/support/commands.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,3 @@ Cypress.Commands.add('resetPhCaptures', () => {
5858
$captures = []
5959
$fullCaptures = []
6060
})
61-
62-
Cypress.Commands.add('shouldBeCalled', (alias, timesCalled) => {
63-
const calls = cy.state('requests').filter((call) => call.alias === alias)
64-
expect(calls).to.have.length(timesCalled, `${alias} should have been called ${timesCalled} times`)
65-
})

cypress/support/compression.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export function getBase64EncodedPayload(request) {
55
return JSON.parse(Buffer.from(data, 'base64'))
66
}
77

8-
export async function getGzipEncodedPayload(requestBody) {
9-
const data = new Uint8Array(await requestBody.arrayBuffer())
8+
export async function getGzipEncodedPayload(request) {
9+
const data = new Uint8Array(await request.body)
1010
const decoded = fflate.strFromU8(fflate.decompressSync(data))
1111
return JSON.parse(decoded)
1212
}

cypress/support/e2e.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ Cypress.on('window:before:load', (win) => {
3030
})
3131

3232
beforeEach(() => {
33-
cy.server()
34-
35-
cy.route('POST', '**/decide/*').as('decide')
36-
cy.route('POST', '**/e/*').as('capture')
37-
cy.route('POST', '**/ses/*').as('session-recording')
33+
cy.intercept('POST', '**/decide/*').as('decide')
34+
cy.intercept('POST', '**/e/*').as('capture')
35+
cy.intercept('POST', '**/ses/*').as('session-recording')
3836

3937
cy.readFile('dist/array.full.js').then((body) => {
4038
cy.intercept('**/static/array.full.js', { body })

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "posthog-js",
3-
"version": "1.91.1",
3+
"version": "1.92.1",
44
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
55
"repository": "https://github.com/PostHog/posthog-js",
66
"author": "[email protected]",
@@ -34,8 +34,6 @@
3434
"fflate": "^0.4.1"
3535
},
3636
"devDependencies": {
37-
"eslint-config-posthog-js": "link:./eslint-rules",
38-
"eslint-plugin-posthog-js": "link:./eslint-rules",
3937
"@babel/core": "7.18.9",
4038
"@babel/preset-env": "7.18.9",
4139
"@babel/preset-typescript": "^7.18.6",
@@ -50,16 +48,19 @@
5048
"@types/eslint": "^8.44.6",
5149
"@types/jest": "^29.5.1",
5250
"@types/react-dom": "^18.0.10",
51+
"@types/sinon": "^17.0.1",
5352
"@types/uuid": "^9.0.1",
5453
"@typescript-eslint/eslint-plugin": "^6.4.0",
5554
"@typescript-eslint/parser": "^6.4.0",
5655
"babel-eslint": "10.1.0",
5756
"babel-jest": "^26.6.3",
58-
"cypress": "10.3.1",
57+
"cypress": "13.5.1",
5958
"eslint": "8.20.0",
59+
"eslint-config-posthog-js": "link:./eslint-rules",
6060
"eslint-config-prettier": "^8.5.0",
6161
"eslint-plugin-compat": "^4.1.4",
6262
"eslint-plugin-jest": "^27.2.3",
63+
"eslint-plugin-posthog-js": "link:./eslint-rules",
6364
"eslint-plugin-prettier": "^4.2.1",
6465
"eslint-plugin-react": "^7.30.1",
6566
"eslint-plugin-react-hooks": "^4.6.0",

0 commit comments

Comments
 (0)