tldraw/packages/tldraw/setupTests.js
Steve Ruiz 530596ac5d
[fix] Asset versions (#2389)
This PR fixes a bug where the `version` was not updated during our last
release. This causes the assets not to load.

### Change Type

- [x] `patch` — Bug fix
2023-12-31 11:07:38 +00:00

57 lines
1.3 KiB
JavaScript

require('fake-indexeddb/auto')
require('jest-canvas-mock')
global.ResizeObserver = require('resize-observer-polyfill')
global.crypto ??= new (require('@peculiar/webcrypto').Crypto)()
global.FontFace = class FontFace {
load() {
return Promise.resolve()
}
}
document.fonts = {
add: () => {},
delete: () => {},
forEach: () => {},
[Symbol.iterator]: () => [][Symbol.iterator](),
}
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(),
})),
})
Object.defineProperty(global.URL, 'createObjectURL', {
writable: true,
value: jest.fn(),
})
// Extract verson from package.json
const { version } = require('./package.json')
window.fetch = async (input, init) => {
if (input === `https://unpkg.com/@tldraw/assets@${version}/translations/en.json`) {
const json = await import('@tldraw/assets/translations/main.json')
return {
ok: true,
json: async () => json.default,
}
}
if (input === '/icons/icon/icon-names.json') {
return {
ok: true,
json: async () => [],
}
}
throw new Error(`Unhandled request: ${input}`)
}