chore(workspace): move the app to apps/app under a pnpm workspace (step 2)
144 files moved with git mv (pure renames). Root package.json delegates dev/typecheck/test:run/lint/build to the packages; Node 24 LTS and pnpm 10.13.1 pinned (.nvmrc, .node-version, engines, packageManager, root devDependency, engine-strict). Dockerfile builds @faunosteo/app on node:24-alpine and copies apps/app/dist; nginx and runtime config unchanged. CI workflow for Gitea Actions. packages/ reserved (README only). Docs synced: WORKSPACE.md, CLAUDE.md, README, DEPLOY, CHANGELOG, plan. 271/271 tests, typecheck, lint, build green from the root.
This commit is contained in:
1 parent
c8d48ab4cc
commit
8673475293
164 files changed
+348
-128
No files matched your search
@@ -0,0 +1,85 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { rasterizeSvg } from '@/pdf/render/svgToPng'
|
||||
|
||||
const PNG_BYTES = new Uint8Array([
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x00,
|
||||
])
|
||||
|
||||
class MockImage {
|
||||
decoding: 'sync' | 'async' | 'auto' = 'auto'
|
||||
crossOrigin: string | null = null
|
||||
onload: (() => void) | null = null
|
||||
onerror: ((err?: unknown) => void) | null = null
|
||||
private _src = ''
|
||||
get src(): string {
|
||||
return this._src
|
||||
}
|
||||
set src(value: string) {
|
||||
this._src = value
|
||||
queueMicrotask(() => this.onload?.())
|
||||
}
|
||||
}
|
||||
|
||||
describe('rasterizeSvg', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('Image', MockImage)
|
||||
vi.stubGlobal('URL', {
|
||||
createObjectURL: () => 'blob:mock',
|
||||
revokeObjectURL: () => undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it('returns PNG bytes for a valid SVG', async () => {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.getContext = (() => ({
|
||||
fillStyle: '',
|
||||
fillRect: () => undefined,
|
||||
drawImage: () => undefined,
|
||||
})) as unknown as HTMLCanvasElement['getContext']
|
||||
canvas.toBlob = ((cb: BlobCallback) => {
|
||||
cb(new Blob([PNG_BYTES], { type: 'image/png' }))
|
||||
}) as HTMLCanvasElement['toBlob']
|
||||
vi.spyOn(document, 'createElement').mockImplementation(
|
||||
((tag: string) =>
|
||||
tag === 'canvas'
|
||||
? canvas
|
||||
: ({}) as HTMLElement) as typeof document.createElement,
|
||||
)
|
||||
|
||||
const out = await rasterizeSvg(
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"/>',
|
||||
)
|
||||
expect(out).toBeInstanceOf(Uint8Array)
|
||||
expect(out[0]).toBe(0x89)
|
||||
expect(out[1]).toBe(0x50)
|
||||
expect(out[2]).toBe(0x4e)
|
||||
expect(out[3]).toBe(0x47)
|
||||
})
|
||||
|
||||
it('falls back to toDataURL when toBlob returns null', async () => {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.getContext = (() => ({
|
||||
fillStyle: '',
|
||||
fillRect: () => undefined,
|
||||
drawImage: () => undefined,
|
||||
})) as unknown as HTMLCanvasElement['getContext']
|
||||
canvas.toBlob = ((cb: BlobCallback) => {
|
||||
cb(null)
|
||||
}) as HTMLCanvasElement['toBlob']
|
||||
canvas.toDataURL = () =>
|
||||
'data:image/png;base64,' +
|
||||
Buffer.from(PNG_BYTES).toString('base64')
|
||||
vi.spyOn(document, 'createElement').mockImplementation(
|
||||
((tag: string) =>
|
||||
tag === 'canvas'
|
||||
? canvas
|
||||
: ({}) as HTMLElement) as typeof document.createElement,
|
||||
)
|
||||
|
||||
const out = await rasterizeSvg(
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"/>',
|
||||
)
|
||||
expect(out[0]).toBe(0x89)
|
||||
expect(out[1]).toBe(0x50)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user