mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-13 06:51:29 +00:00
81 lines
2.3 KiB
JavaScript
81 lines
2.3 KiB
JavaScript
// ***********************************************************
|
|
// This example support/component.js is processed and
|
|
// loaded automatically before your test files.
|
|
//
|
|
// This is a great place to put global configuration and
|
|
// behavior that modifies Cypress.
|
|
//
|
|
// You can change the location of this file or turn off
|
|
// automatically serving support files with the
|
|
// 'supportFile' configuration option.
|
|
//
|
|
// You can read more here:
|
|
// https://on.cypress.io/configuration
|
|
// ***********************************************************
|
|
import '../../assets/app.css'
|
|
import './tailwind.compiled.css'
|
|
// Import commands.js using ES2015 syntax:
|
|
import './commands'
|
|
import Vue from 'vue'
|
|
|
|
import { Constants } from '../../plugins/constants'
|
|
import Strings from '../../strings/en-us.json'
|
|
import '../../plugins/utils'
|
|
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 })
|
|
}
|
|
|
|
if (!window.__absCypressDebugListenersRegistered) {
|
|
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
|
|
})
|
|
|
|
window.__absCypressDebugListenersRegistered = true
|
|
}
|
|
|
|
//Cypress.Commands.add('mount', mount)
|
|
Cypress.Commands.add('mount', (component, options = {}) => {
|
|
|
|
Vue.prototype.$constants = Constants
|
|
Vue.prototype.$strings = Strings
|
|
|
|
return mount(component, options)
|
|
})
|
|
|
|
// Example use:
|
|
// cy.mount(MyComponent)
|