包含: - furniture-3d-system:Next.js 16 全栈应用(资产中心、产品管理、3D装配动画) - autocad-plugin:AutoCAD 家具导出插件源码 - 资产中心改造:编辑弹窗化、删除功能、Toast反馈、自定义Select组件 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
88 lines
2.2 KiB
JavaScript
88 lines
2.2 KiB
JavaScript
import '@testing-library/jest-dom'
|
||
import { TextDecoder, TextEncoder } from 'util'
|
||
|
||
// Node/JSDOM 环境下某些依赖(如 Prisma/cuid2)需要 TextEncoder/TextDecoder
|
||
if (typeof global.TextEncoder === 'undefined') {
|
||
global.TextEncoder = TextEncoder
|
||
}
|
||
if (typeof global.TextDecoder === 'undefined') {
|
||
global.TextDecoder = TextDecoder
|
||
}
|
||
|
||
// Polyfill setImmediate for Prisma
|
||
if (typeof setImmediate === 'undefined') {
|
||
global.setImmediate = (callback, ...args) => setTimeout(callback, 0, ...args)
|
||
}
|
||
|
||
// Polyfill Request and Response for Next.js server components
|
||
if (typeof Request === 'undefined') {
|
||
global.Request = class Request {
|
||
constructor(input, init) {
|
||
this.url = typeof input === 'string' ? input : input.url
|
||
this.method = init?.method || 'GET'
|
||
this.headers = new Map(Object.entries(init?.headers || {}))
|
||
this.body = init?.body
|
||
}
|
||
}
|
||
}
|
||
|
||
if (typeof Response === 'undefined') {
|
||
global.Response = class Response {
|
||
constructor(body, init) {
|
||
this.body = body
|
||
this.status = init?.status || 200
|
||
this.statusText = init?.statusText || 'OK'
|
||
this.headers = new Map(Object.entries(init?.headers || {}))
|
||
}
|
||
|
||
json() {
|
||
return Promise.resolve(JSON.parse(this.body))
|
||
}
|
||
|
||
text() {
|
||
return Promise.resolve(this.body)
|
||
}
|
||
}
|
||
}
|
||
|
||
// Mock IntersectionObserver
|
||
global.IntersectionObserver = class IntersectionObserver {
|
||
constructor() {}
|
||
disconnect() {}
|
||
observe() {}
|
||
unobserve() {}
|
||
}
|
||
|
||
// Mock ResizeObserver
|
||
global.ResizeObserver = class ResizeObserver {
|
||
constructor() {}
|
||
disconnect() {}
|
||
observe() {}
|
||
unobserve() {}
|
||
}
|
||
|
||
// Mock matchMedia (only in browser environment)
|
||
if (typeof window !== 'undefined') {
|
||
Object.defineProperty(window, 'matchMedia', {
|
||
writable: true,
|
||
value: jest.fn().mockImplementation(query => ({
|
||
matches: false,
|
||
media: query,
|
||
onchange: null,
|
||
addListener: jest.fn(), // deprecated
|
||
removeListener: jest.fn(), // deprecated
|
||
addEventListener: jest.fn(),
|
||
removeEventListener: jest.fn(),
|
||
dispatchEvent: jest.fn(),
|
||
})),
|
||
})
|
||
}
|
||
|
||
// Mock CSS.supports
|
||
global.CSS = {
|
||
supports: jest.fn().mockReturnValue(true),
|
||
}
|
||
|
||
// Mock performance.now
|
||
global.performance.now = jest.fn(() => Date.now())
|