From 6c86e1cf85fee5873969ed3551ea621a8ea98f10 Mon Sep 17 00:00:00 2001 From: Jaybe Date: Fri, 14 Nov 2025 23:45:08 +0900 Subject: [PATCH] =?UTF-8?q?test(zip):=20Export=20ZIP=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=20=EA=B0=95=ED=99=94(assets=20=EC=9C=A0=EB=AC=B4/=EC=84=9C?= =?UTF-8?q?=EB=B8=8C=ED=8F=B4=EB=8D=94=20=ED=8F=AC=ED=95=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/exporter/zip.validation.test.ts | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 lib/exporter/zip.validation.test.ts diff --git a/lib/exporter/zip.validation.test.ts b/lib/exporter/zip.validation.test.ts new file mode 100644 index 0000000..c6ee0dc --- /dev/null +++ b/lib/exporter/zip.validation.test.ts @@ -0,0 +1,44 @@ +import { describe, it, expect } from 'vitest' +import JSZip from 'jszip' +import { buildZip } from '@/lib/exporter/zip' + +const TE = new TextEncoder() + +describe('Export ZIP 검증 강화', () => { + it('assets가 비어있을 때 index.html/styles.css/app.js만 포함한다', async () => { + const zipBytes = await buildZip({ + html: 'aok', + css: 'body{color:#111}', + js: 'console.log("ok")', + assets: {}, + }) + const zip = await JSZip.loadAsync(zipBytes) + const names = Object.keys(zip.files).sort() + expect(names).toEqual(['app.js','index.html','styles.css']) + }) + + it('assets가 있으면 모든 파일을 그대로 포함한다(서브폴더 포함)', async () => { + const assets = { + 'assets/img/logo.png': new Uint8Array([0,1,2,3]), + 'assets/svg/icon.svg': TE.encode(''), + 'assets/fonts/inter.woff2': new Uint8Array([4,5,6]), + } + const zipBytes = await buildZip({ + html: 'aok', + css: 'body{color:#111}', + js: 'console.log("ok")', + assets, + }) + const zip = await JSZip.loadAsync(zipBytes) + const names = Object.keys(zip.files) + expect(names).toContain('index.html') + expect(names).toContain('styles.css') + expect(names).toContain('app.js') + expect(names).toContain('assets/img/logo.png') + expect(names).toContain('assets/svg/icon.svg') + expect(names).toContain('assets/fonts/inter.woff2') + + const logo = await zip.files['assets/img/logo.png'].async('uint8array') + expect(Array.from(logo)).toEqual([0,1,2,3]) + }) +})