2021-02-09 16:28:01 +01:00
|
|
|
import 'givens/setup'
|
2020-05-19 20:48:10 +02:00
|
|
|
import './commands'
|
2022-08-09 20:12:41 +02:00
|
|
|
import 'cypress-axe'
|
2022-12-30 11:23:09 +01:00
|
|
|
import { decideResponse } from '../fixtures/api/decide'
|
2020-05-19 20:48:10 +02:00
|
|
|
|
2021-02-09 16:28:01 +01:00
|
|
|
try {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
require('cypress-terminal-report/src/installLogsCollector')()
|
2023-10-12 01:51:47 +02:00
|
|
|
// eslint-disable-next-line no-empty
|
2021-02-09 16:28:01 +01:00
|
|
|
} catch {}
|
2020-08-11 10:52:43 +02:00
|
|
|
|
2023-10-12 12:15:17 +02:00
|
|
|
const E2E_TESTING = Cypress.env('E2E_TESTING')
|
|
|
|
|
2021-10-15 12:47:06 +02:00
|
|
|
// Add console errors into cypress logs. This helps with failures in Github Actions which otherwise swallows them.
|
|
|
|
// From: https://github.com/cypress-io/cypress/issues/300#issuecomment-688915086
|
|
|
|
Cypress.on('window:before:load', (win) => {
|
|
|
|
cy.spy(win.console, 'error')
|
|
|
|
cy.spy(win.console, 'warn')
|
2024-03-11 12:48:55 +01:00
|
|
|
|
|
|
|
win._cypress_posthog_captures = []
|
2021-10-15 12:47:06 +02:00
|
|
|
})
|
|
|
|
|
2020-05-19 20:48:10 +02:00
|
|
|
beforeEach(() => {
|
2023-07-10 16:59:30 +02:00
|
|
|
Cypress.env('POSTHOG_PROPERTY_CURRENT_TEST_TITLE', Cypress.currentTest.title)
|
|
|
|
Cypress.env('POSTHOG_PROPERTY_CURRENT_TEST_FULL_TITLE', Cypress.currentTest.titlePath.join(' > '))
|
|
|
|
Cypress.env('POSTHOG_PROPERTY_GITHUB_ACTION_RUN_URL', process.env.GITHUB_ACTION_RUN_URL)
|
2024-02-20 23:43:48 +01:00
|
|
|
cy.useSubscriptionStatus('subscribed')
|
2022-10-20 14:24:56 +02:00
|
|
|
|
2024-03-11 12:48:55 +01:00
|
|
|
cy.intercept('**/decide/*', (req) =>
|
2022-06-20 11:04:29 +02:00
|
|
|
req.reply(
|
|
|
|
decideResponse({
|
2024-04-23 11:48:20 +02:00
|
|
|
// Feature flag to be treated as rolled out in E2E tests, e.g.:
|
2022-10-17 15:03:35 +02:00
|
|
|
// 'toolbar-launch-side-action': true,
|
2022-06-20 11:04:29 +02:00
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-03-20 21:03:11 +01:00
|
|
|
// un-intercepted sometimes this doesn't work and the page gets stuck on the SpinnerOverlay
|
|
|
|
cy.intercept(/app.posthog.com\/api\/projects\/@current\/feature_flags\/my_flags.*/, (req) => req.reply([]))
|
2023-03-21 18:10:10 +01:00
|
|
|
cy.intercept('https://www.gravatar.com/avatar/**', (req) =>
|
|
|
|
req.reply({ statusCode: 404, body: 'Cypress forced 404' })
|
|
|
|
)
|
2023-03-20 21:03:11 +01:00
|
|
|
|
2024-04-23 11:48:20 +02:00
|
|
|
cy.intercept('GET', /\/api\/projects\/\d+\/insights\/?\?/).as('getInsights')
|
2020-05-19 20:48:10 +02:00
|
|
|
|
2024-04-23 11:48:20 +02:00
|
|
|
cy.request('POST', '/api/login/', {
|
|
|
|
email: 'test@posthog.com',
|
|
|
|
password: '12345678',
|
|
|
|
})
|
|
|
|
|
|
|
|
if (Cypress.spec.name.includes('before-onboarding')) {
|
2022-04-02 18:35:14 +02:00
|
|
|
cy.visit('/?no-preloaded-app-context=true')
|
|
|
|
} else {
|
2024-04-23 11:48:20 +02:00
|
|
|
cy.visit('/insights')
|
|
|
|
cy.wait('@getInsights').then(() => {
|
|
|
|
cy.get('.saved-insights tr').should('exist')
|
2022-04-02 18:35:14 +02:00
|
|
|
})
|
2021-02-09 16:28:01 +01:00
|
|
|
}
|
2020-05-19 20:48:10 +02:00
|
|
|
})
|
|
|
|
|
2023-10-12 12:15:17 +02:00
|
|
|
afterEach(function () {
|
|
|
|
const { state, duration } = this.currentTest
|
|
|
|
const event = state === 'passed' ? 'e2e_testing_test_passed' : 'e2e_testing_test_failed'
|
2023-07-10 16:59:30 +02:00
|
|
|
|
2023-10-12 12:15:17 +02:00
|
|
|
if (E2E_TESTING) {
|
2023-07-10 16:59:30 +02:00
|
|
|
cy.window().then((win) => {
|
2023-10-12 12:15:17 +02:00
|
|
|
;(win as any).posthog?.capture(event, { state, duration })
|
2023-07-10 16:59:30 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-06-29 22:20:02 +02:00
|
|
|
const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
|
|
|
|
Cypress.on('uncaught:exception', (err) => {
|
|
|
|
/* returning false here prevents Cypress from failing the test */
|
|
|
|
if (resizeObserverLoopErrRe.test(err.message)) {
|
|
|
|
return false
|
|
|
|
}
|
2020-05-19 20:48:10 +02:00
|
|
|
})
|