import {it,expect} from 'vitest' import {PrintDocumentStore} from '../src/main/print-documents' import {conciseError} from '../src/shared/errors' it('large print documents use short isolated local addresses and can be released',()=>{ const store=new PrintDocumentStore(),html=''+ 'x'.repeat(3*1024*1024)+'' const first=store.publish(html),second=store.publish('second') expect(first.url.length).toBeLessThan(100) expect(first.url).not.toBe(second.url) expect(store.read(first.url)).toBe(html) expect(store.read(first.url+'?extra')).toBeUndefined() first.dispose();first.dispose() expect(store.read(first.url)).toBeUndefined() expect(store.read(second.url)).toBe('second') second.dispose();expect(store.read(second.url)).toBeUndefined() }) it('loading errors retain the error code without exposing embedded document content',()=>{ const message=conciseError(new Error("ERR_INVALID_URL (-300) loading 'data:text/html;charset=utf-8,"+'sensitive'.repeat(100000)+"'")) expect(message).toContain('ERR_INVALID_URL (-300)') expect(message).not.toContain('sensitive') expect(message.length).toBeLessThan(100) expect(conciseError('x'.repeat(1000)).length).toBe(400) expect(conciseError('文件夹无法访问')).toBe('文件夹无法访问') })