import type { ReactNode } from 'react' import Artplayer from 'artplayer' import { Component, StrictMode } from 'react' import { createRoot } from 'react-dom/client' import Player from './src/Player' const records: { art: Artplayer, destroyed: number }[] = [] const errors: { message: string, same: boolean }[] = [] const container = document.getElementById('root') if (!container) throw new Error('Missing React fixture container') const root = createRoot(container) const option = { url: '/pattern.mp4', muted: true } const changedOption = { ...option, volume: 0.2 } const failure = new Error('react-consumer-callback-failure') function capture(art: Artplayer) { const record = { art, destroyed: 0 } records.push(record) art.on('destroy', () => record.destroyed++) } function changedCapture(art: Artplayer) { capture(art) } function fail(art: Artplayer) { capture(art) throw failure } function failWithCleanupError(art: Artplayer) { const destroy = art.destroy.bind(art) art.destroy = (...args) => { destroy(...args) throw new Error('secondary-cleanup-error') } fail(art) } class Boundary extends Component<{ children: ReactNode }, { failed: boolean }> { state = { failed: false } static getDerivedStateFromError() { return { failed: true } } componentDidCatch(error: Error) { errors.push({ message: error.message, same: error === failure }) } render() { return this.state.failed ?