From a441f25cc62979464cf3a423967f7074565965dd Mon Sep 17 00:00:00 2001 From: spring-raining Date: Thu, 18 Jan 2024 00:52:58 +0900 Subject: [PATCH] test: Add test checking copy asset filter --- tests/__snapshots__/webbook.test.ts.snap | 48 ++++++++++++++++++++++++ tests/webbook.test.ts | 33 ++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/tests/__snapshots__/webbook.test.ts.snap b/tests/__snapshots__/webbook.test.ts.snap index f351acc3..4df5f010 100644 --- a/tests/__snapshots__/webbook.test.ts.snap +++ b/tests/__snapshots__/webbook.test.ts.snap @@ -1,5 +1,53 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`copy webpub assets properly 1`] = ` +"/ +└─ work/ + └─ input/ + ├─ doc.html + ├─ doc.md + ├─ node_modules/ + │ └─ pkgA/ + │ ├─ a.css + │ └─ a.html + ├─ output1/ + │ ├─ doc.html + │ ├─ publication.json + │ └─ themes/ + │ └─ packages/ + │ ├─ @org/ + │ │ └─ themeB/ + │ │ └─ theme.css + │ └─ themeA/ + │ └─ theme.css + ├─ output2/ + │ ├─ doc.html + │ ├─ publication.json + │ └─ themes/ + │ └─ packages/ + │ ├─ @org/ + │ │ └─ themeB/ + │ │ └─ theme.css + │ └─ themeA/ + │ └─ theme.css + ├─ package.json + ├─ publication.json + ├─ themes/ + │ └─ packages/ + │ ├─ @org/ + │ │ └─ themeB/ + │ │ ├─ example/ + │ │ │ └─ a.css + │ │ ├─ package.json + │ │ └─ theme.css + │ └─ themeA/ + │ ├─ example/ + │ │ └─ a.css + │ ├─ package.json + │ └─ theme.css + └─ vivliostyle.config.json" +`; + exports[`generate webpub from a plain HTML 1`] = ` "/ └─ work/ diff --git a/tests/webbook.test.ts b/tests/webbook.test.ts index 47dab5a8..e01f254c 100644 --- a/tests/webbook.test.ts +++ b/tests/webbook.test.ts @@ -11,6 +11,12 @@ vi.mock('@vivliostyle/jsdom', () => import('./commandUtil.js').then(({ getMockedJSDOM }) => getMockedJSDOM()), ); +vi.mock('../src/processor/theme.ts', async (importOriginal) => ({ + ...(await importOriginal()), + checkThemeInstallationNecessity: () => Promise.resolve(false), + installThemeDependencies: () => Promise.resolve(), +})); + afterEach(() => vol.reset()); it('generate webpub from single markdown file', async () => { @@ -202,3 +208,30 @@ it('generate webpub with complex copyAsset settings', async () => { expect(toTree(vol)).toMatchSnapshot(); }); + +it('copy webpub assets properly', async () => { + const config: VivliostyleConfigSchema = { + entry: ['doc.md'], + output: ['/work/input/output1', '/work/input/output2'], + theme: ['themeA', '@org/themeB'], + }; + vol.fromJSON({ + '/work/input/vivliostyle.config.json': JSON.stringify(config), + '/work/input/package.json': '', + '/work/input/doc.md': 'yuno', + '/work/input/node_modules/pkgA/a.html': '', + '/work/input/node_modules/pkgA/a.css': '', + '/work/input/themes/packages/themeA/package.json': '{"main": "theme.css"}', + '/work/input/themes/packages/themeA/theme.css': '', + '/work/input/themes/packages/themeA/example/a.css': '', + '/work/input/themes/packages/@org/themeB/package.json': + '{"main": "theme.css"}', + '/work/input/themes/packages/@org/themeB/theme.css': '', + '/work/input/themes/packages/@org/themeB/example/a.css': '', + }); + await build({ + configPath: '/work/input/vivliostyle.config.json', + }); + + expect(toTree(vol)).toMatchSnapshot(); +});