Skip to content

Commit

Permalink
test: Add a copyAsset config test
Browse files Browse the repository at this point in the history
  • Loading branch information
spring-raining committed Oct 30, 2023
1 parent 62b41f3 commit 82639bc
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/__snapshots__/webbook.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,40 @@ exports[`generate webpub from vivliostyle.config.js 3`] = `
</html>
"
`;
exports[`generate webpub with complex copyAsset settings 1`] = `
"/
└─ work/
├─ input/
├─ .vs/
├─ assetA.jxl
├─ doc.html
├─ node_modules/
└─ pkgB/
├─ a.html
└─ bar/
└─ b.html
└─ publication.json
├─ assetA.jxl
├─ assetB.svg
├─ cover.png
├─ doc.md
├─ node_modules/
├─ pkgA/
└─ img.png
└─ pkgB/
├─ a.html
└─ bar/
└─ b.html
├─ package.json
└─ vivliostyle.config.json
└─ output/
├─ assetA.jxl
├─ doc.html
├─ node_modules/
└─ pkgB/
├─ a.html
└─ bar/
└─ b.html
└─ publication.json"
`;
34 changes: 34 additions & 0 deletions tests/webbook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,37 @@ it('generate webpub from a remote HTML document', async () => {
const entry = file['/work/output/work/input/index.html'];
expect(format(entry as string, { parser: 'html' })).toMatchSnapshot();
});

it('generate webpub with complex copyAsset settings', async () => {
const config: VivliostyleConfigSchema = {
copyAsset: {
includes: [
// The following line should also work, but under the mock environment of memfs, fast-glob does not work without '/**'.
// 'node_modules/pkgB',
'node_modules/pkgB/**',
],
excludes: ['cover.png'],
includeFileExtensions: ['jxl'],
excludeFileExtensions: ['svg'],
},
entry: ['doc.md'],
output: ['/work/output'],
workspaceDir: '.vs',
};
vol.fromJSON({
'/work/input/vivliostyle.config.json': JSON.stringify(config),
'/work/input/package.json': '',
'/work/input/doc.md': 'yuno',
'/work/input/cover.png': '',
'/work/input/assetA.jxl': '',
'/work/input/assetB.svg': '',
'/work/input/node_modules/pkgA/img.png': '',
'/work/input/node_modules/pkgB/a.html': '',
'/work/input/node_modules/pkgB/bar/b.html': '',
});
await build({
configPath: '/work/input/vivliostyle.config.json',
});

expect(toTree(vol)).toMatchSnapshot();
});

0 comments on commit 82639bc

Please sign in to comment.