55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
import {join, dirname} from "node:path";
|
|
import {test, expect} from "@jest/globals";
|
|
|
|
import urlPlugin from "@rollup/plugin-url";
|
|
|
|
import html from "../../src/index.ts";
|
|
import {runBrowserTest} from "../util/browser-test.ts";
|
|
|
|
import {fileURLToPath} from "node:url";
|
|
import handlebars from "handlebars";
|
|
import {serializer} from "../util/index.ts";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
process.chdir(join(__dirname, 'fixtures'));
|
|
|
|
|
|
const defaultAssetInclude = [
|
|
'**/*.(png|jpg|jpeg|gif|ico|svg)',// images, svg
|
|
'**/*.(woff|woff2|eot|ttf|otf)',// fonts
|
|
'**/*.(webm|mp4)',// video
|
|
];
|
|
|
|
test('evaluated-web-bundle', async ()=>{
|
|
expect.addSnapshotSerializer(serializer);
|
|
const out = await runBrowserTest({
|
|
input: 'index.hbs',
|
|
treeshake: 'smallest',
|
|
plugins: [
|
|
html({
|
|
include: [
|
|
'**/*.(html|hbs)',// html or handlebars
|
|
],
|
|
transform(src) {
|
|
return handlebars.compile(src)({
|
|
head: `<title>I'm cool!</title>`
|
|
});
|
|
}
|
|
}),
|
|
urlPlugin({
|
|
include: defaultAssetInclude,
|
|
}),
|
|
],
|
|
}, {
|
|
path: 'index.html',
|
|
},{
|
|
dir: 'output', // Output all files
|
|
format: 'es', // iifi and cjs should be added to tests
|
|
sourcemap: true,// Test if #sourcemapUrl is not accidentally included in the html-output
|
|
chunkFileNames: '[name].js',
|
|
entryFileNames: '[name].[extname]',
|
|
assetFileNames: '[name].[extname]',
|
|
});
|
|
expect(out).toMatchSnapshot();
|
|
});
|