mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-24 20:31:31 +00:00
add opt-in Cypress browser failure forwarding
This commit is contained in:
parent
08ad8f128c
commit
1fd5c205a9
2 changed files with 77 additions and 2 deletions
|
|
@ -25,6 +25,45 @@ import '../../plugins/init.client'
|
|||
|
||||
import { mount } from 'cypress/vue2'
|
||||
|
||||
const shouldForwardBrowserDebug = () => Boolean(Cypress.env('ABS_CYPRESS_DEBUG_BROWSER'))
|
||||
|
||||
const formatErrorDetails = (value) => {
|
||||
if (!value) return ''
|
||||
if (value.stack) return value.stack
|
||||
if (typeof value === 'string') return value
|
||||
|
||||
try {
|
||||
return JSON.stringify(value, null, 2)
|
||||
} catch {
|
||||
return String(value)
|
||||
}
|
||||
}
|
||||
|
||||
const forwardBrowserDebug = (type, message, details) => {
|
||||
if (!shouldForwardBrowserDebug()) return
|
||||
|
||||
cy.task('absCypressDebug', {
|
||||
type,
|
||||
message,
|
||||
details: formatErrorDetails(details)
|
||||
}, { log: false })
|
||||
}
|
||||
|
||||
window.addEventListener('error', (event) => {
|
||||
forwardBrowserDebug('window-error', event.message || 'Unhandled window error', event.error)
|
||||
})
|
||||
|
||||
window.addEventListener('unhandledrejection', (event) => {
|
||||
const reason = event.reason
|
||||
const message = reason?.message || 'Unhandled promise rejection'
|
||||
forwardBrowserDebug('unhandledrejection', message, reason)
|
||||
})
|
||||
|
||||
Cypress.on('fail', (error, runnable) => {
|
||||
forwardBrowserDebug('cypress-fail', `${runnable?.fullTitle?.() || 'Unknown test'} failed`, error)
|
||||
throw error
|
||||
})
|
||||
|
||||
//Cypress.Commands.add('mount', mount)
|
||||
Cypress.Commands.add('mount', (component, options = {}) => {
|
||||
|
||||
|
|
@ -35,4 +74,4 @@ Cypress.Commands.add('mount', (component, options = {}) => {
|
|||
})
|
||||
|
||||
// Example use:
|
||||
// cy.mount(MyComponent)
|
||||
// cy.mount(MyComponent)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue