Skip to content

Commit

Permalink
chore: refactor some cypress setup (#1467)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Oct 14, 2024
1 parent abd1186 commit 8e7e1ea
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 62 deletions.
30 changes: 15 additions & 15 deletions cypress/e2e/opting-out.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('opting out', () => {
cy.get('[data-cy-input]').type('hello world! ')

assertWhetherPostHogRequestsWereCalled({
'@recorder': false,
'@recorder-script': false,
'@decide': false,
'@session-recording': false,
})
Expand All @@ -51,7 +51,7 @@ describe('opting out', () => {
cy.posthogInit({ opt_out_capturing_by_default: true })

assertWhetherPostHogRequestsWereCalled({
'@recorder': false,
'@recorder-script': false,
'@decide': true,
'@session-recording': false,
})
Expand All @@ -69,7 +69,7 @@ describe('opting out', () => {
cy.posthogInit({ disable_session_recording: true })

assertWhetherPostHogRequestsWereCalled({
'@recorder': false,
'@recorder-script': false,
'@decide': true,
'@session-recording': false,
})
Expand All @@ -87,7 +87,7 @@ describe('opting out', () => {
cy.posthogInit({ opt_out_capturing_by_default: true })

assertWhetherPostHogRequestsWereCalled({
'@recorder': false,
'@recorder-script': false,
'@decide': true,
'@session-recording': false,
})
Expand All @@ -101,7 +101,7 @@ describe('opting out', () => {
})

assertWhetherPostHogRequestsWereCalled({
'@recorder': true,
'@recorder-script': true,
'@decide': true,
// no call to session-recording yet
})
Expand All @@ -117,7 +117,7 @@ describe('opting out', () => {
cy.posthogInit({ disable_session_recording: true })

assertWhetherPostHogRequestsWereCalled({
'@recorder': false,
'@recorder-script': false,
'@decide': true,
'@session-recording': false,
})
Expand All @@ -134,7 +134,7 @@ describe('opting out', () => {
cy.posthog().invoke('startSessionRecording')

assertWhetherPostHogRequestsWereCalled({
'@recorder': true,
'@recorder-script': true,
'@decide': true,
// no call to session-recording yet
})
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('opting out', () => {
})

assertWhetherPostHogRequestsWereCalled({
'@recorder': false,
'@recorder-script': false,
'@decide': true,
'@session-recording': false,
})
Expand All @@ -177,7 +177,7 @@ describe('opting out', () => {
})

assertWhetherPostHogRequestsWereCalled({
'@recorder': true,
'@recorder-script': true,
'@decide': true,
// no call to session-recording yet
})
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('opting out', () => {
})

assertWhetherPostHogRequestsWereCalled({
'@recorder': false,
'@recorder-script': false,
'@decide': true,
'@session-recording': false,
})
Expand All @@ -220,7 +220,7 @@ describe('opting out', () => {
})

assertWhetherPostHogRequestsWereCalled({
'@recorder': true,
'@recorder-script': true,
'@decide': true,
// no call to session-recording yet
})
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('opting out', () => {
})

assertWhetherPostHogRequestsWereCalled({
'@recorder': false,
'@recorder-script': false,
'@decide': true,
'@session-recording': false,
})
Expand All @@ -276,7 +276,7 @@ describe('opting out', () => {
})

assertWhetherPostHogRequestsWereCalled({
'@recorder': true,
'@recorder-script': true,
'@decide': true,
// no call to session-recording yet
})
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('opting out', () => {
})

assertWhetherPostHogRequestsWereCalled({
'@recorder': false,
'@recorder-script': false,
'@decide': true,
'@session-recording': false,
})
Expand All @@ -337,7 +337,7 @@ describe('opting out', () => {
})

assertWhetherPostHogRequestsWereCalled({
'@recorder': true,
'@recorder-script': true,
'@decide': true,
// no call to session-recording yet
})
Expand Down
14 changes: 7 additions & 7 deletions cypress/e2e/session-recording.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('Session recording', () => {
},
})

cy.wait('@recorder')
cy.wait('@recorder-script')

cy.intercept({ url: 'https://example.com', times: 1 }, (req) => {
req.reply({
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('Session recording', () => {
},
url: './playground/cypress',
})
cy.wait('@recorder')
cy.wait('@recorder-script')
})

it('captures session events', () => {
Expand Down Expand Up @@ -406,7 +406,7 @@ describe('Session recording', () => {
cy.reload()
cy.posthogInit({})
cy.wait('@decide')
cy.wait('@recorder')
cy.wait('@recorder-script')

cy.get('body')
.trigger('mousemove', { clientX: 200, clientY: 300 })
Expand Down Expand Up @@ -564,7 +564,7 @@ describe('Session recording', () => {
},
url: './playground/cypress',
})
cy.wait('@recorder')
cy.wait('@recorder-script')
})

it('does not capture when sampling is set to 0', () => {
Expand Down Expand Up @@ -594,7 +594,7 @@ describe('Session recording', () => {
}).as('decide')

assertWhetherPostHogRequestsWereCalled({
'@recorder': true,
'@recorder-script': true,
'@decide': true,
'@session-recording': false,
})
Expand All @@ -606,7 +606,7 @@ describe('Session recording', () => {
cy.posthog().invoke('startSessionRecording', { sampling: true })

assertWhetherPostHogRequestsWereCalled({
'@recorder': true,
'@recorder-script': true,
'@decide': true,
// no call to session-recording yet
})
Expand Down Expand Up @@ -637,7 +637,7 @@ describe('Session recording', () => {
},
url: './playground/cypress',
})
cy.wait('@recorder')
cy.wait('@recorder-script')

cy.get('[data-cy-input]').type('hello posthog!')

Expand Down
56 changes: 17 additions & 39 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,22 @@ beforeEach(() => {
cy.intercept('POST', '/ses/*', { status: 1 }).as('session-recording')
cy.intercept('GET', '/surveys/*').as('surveys')

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

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

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

cy.readFile('dist/array.js.map').then((body) => {
cy.intercept('/static/array.js.map', { body })
})

cy.readFile('dist/recorder.js').then((body) => {
cy.intercept('/static/recorder.js*', { body }).as('recorder')
cy.intercept('/static/recorder-v2.js*', { body }).as('recorderv2')
})

cy.readFile('dist/recorder.js.map').then((body) => {
cy.intercept('/static/recorder.js.map', { body })
})

cy.readFile('dist/surveys.js').then((body) => {
cy.intercept('/static/surveys.js*', { body })
})

cy.readFile('dist/surveys.js.map').then((body) => {
cy.intercept('/static/surveys.js.map', { body })
})

cy.readFile('dist/exception-autocapture.js').then((body) => {
cy.intercept('/static/exception-autocapture.js*', { body }).as('exception-autocapture-script')
})

cy.readFile('dist/exception-autocapture.js.map').then((body) => {
cy.intercept('/static/exception-autocapture.js.map', { body })
const lazyLoadedJSFiles = [
'array',
'array.full',
'recorder',
'surveys',
'exception-autocapture',
'tracing-headers',
'web-vitals',
]
lazyLoadedJSFiles.forEach((key: string) => {
cy.readFile(`dist/${key}.js`).then((body) => {
cy.intercept(`/static/${key}.js*`, { body }).as(`${key}-script`)
})

cy.readFile(`dist/${key}.js.map`).then((body) => {
cy.intercept(`/static/${key}.js.map`, { body })
})
})
})
2 changes: 1 addition & 1 deletion cypress/support/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const start = ({
// sometimes we have too many listeners in this test environment
// that breaks the event emitter listeners in error tracking tests
// we don't see the error in production, so it's fine to increase the limit here
EventEmitter.prototype._maxListeners = 100
EventEmitter.prototype.setMaxListeners(100)

const decideResponse = {
editorParams: {},
Expand Down

0 comments on commit 8e7e1ea

Please sign in to comment.