UNPKG

@tldraw/utils

Version:

tldraw infinite canvas SDK (private utilities).

83 lines (63 loc) 3.16 kB
import { clearRegisteredVersionsForTests, registerTldrawLibraryVersion } from './version' jest.useFakeTimers() describe('registerTldrawLibraryVersion', () => { afterEach(() => { clearRegisteredVersionsForTests() jest.restoreAllMocks() }) it('doesnt log anything if all versions are the same', () => { const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation() registerTldrawLibraryVersion('tldraw', '1.0.0', 'esm') registerTldrawLibraryVersion('@tldraw/editor', '1.0.0', 'esm') registerTldrawLibraryVersion('@tldraw/utils', '1.0.0', 'esm') registerTldrawLibraryVersion('@tldraw/tlschema', '1.0.0', 'esm') jest.runAllTimers() expect(consoleLogSpy).toHaveBeenCalledTimes(0) }) it('logs if not all versions match', () => { const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation() registerTldrawLibraryVersion('tldraw', '1.0.0', 'esm') registerTldrawLibraryVersion('@tldraw/editor', '1.1.0', 'esm') registerTldrawLibraryVersion('@tldraw/utils', '1.1.0', 'esm') registerTldrawLibraryVersion('@tldraw/utils', '1.2.0', 'esm') registerTldrawLibraryVersion('@tldraw/tlschema', '1.2.0', 'esm') jest.runAllTimers() expect(consoleLogSpy).toHaveBeenCalledTimes(1) expect(consoleLogSpy.mock.lastCall).toMatchInlineSnapshot(` [ "[tldraw] You have multiple versions of tldraw libraries installed. This can lead to bugs and unexpected behavior. The latest version you have installed is v1.2.0. The following libraries are on the latest version: • ✅ @tldraw/tlschema The following libraries are not on the latest version, or have multiple versions installed: • ❌ tldraw (v1.0.0) • ❌ @tldraw/editor (v1.1.0) • ❌ @tldraw/utils (v1.1.0, v1.2.0)", ] `) }) it('logs if multiple versions of te same library are installed', () => { const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation() registerTldrawLibraryVersion('tldraw', '1.1.0', 'esm') registerTldrawLibraryVersion('@tldraw/editor', '1.1.0', 'esm') registerTldrawLibraryVersion('@tldraw/editor', '1.1.0', 'cjs') registerTldrawLibraryVersion('@tldraw/utils', '1.1.0', 'esm') registerTldrawLibraryVersion('@tldraw/utils', '1.1.0', 'cjs') registerTldrawLibraryVersion('@tldraw/tlschema', '1.1.0', 'esm') jest.runAllTimers() expect(consoleLogSpy).toHaveBeenCalledTimes(1) expect(consoleLogSpy.mock.lastCall).toMatchInlineSnapshot(` [ "[tldraw] You have multiple instances of some tldraw libraries active. This can lead to bugs and unexpected behavior.  This usually means that your bundler is misconfigured, and is importing the same library multiple times - usually once as an ES Module, and once as a CommonJS module. The following libraries have been imported multiple times: • ❌ @tldraw/editor v1.1.0: 1. ES Modules 2. CommonJS • ❌ @tldraw/utils v1.1.0: 1. ES Modules 2. CommonJS You should configure your bundler to only import one version of each library.", ] `) }) })