Skip to content

Commit

Permalink
test: Add test checking copy asset filter
Browse files Browse the repository at this point in the history
  • Loading branch information
spring-raining committed Jan 17, 2024
1 parent a1921e2 commit a441f25
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/__snapshots__/webbook.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
33 changes: 33 additions & 0 deletions tests/webbook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ vi.mock('@vivliostyle/jsdom', () =>
import('./commandUtil.js').then(({ getMockedJSDOM }) => getMockedJSDOM()),
);

vi.mock('../src/processor/theme.ts', async (importOriginal) => ({
...(await importOriginal<typeof import('../src/processor/theme.js')>()),
checkThemeInstallationNecessity: () => Promise.resolve(false),
installThemeDependencies: () => Promise.resolve(),
}));

afterEach(() => vol.reset());

it('generate webpub from single markdown file', async () => {
Expand Down Expand Up @@ -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();
});

0 comments on commit a441f25

Please sign in to comment.