First private release. Check updated README.md for details
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2023-04-30 13:29:47 +02:00
parent 831e607591
commit 5ae59102b5
36 changed files with 890 additions and 875 deletions

View File

@@ -2,123 +2,36 @@ import {join, dirname} from "node:path";
import test from "ava";
import { rollup } from "rollup";
import css from "rollup-plugin-postcss";
import { getCode } from "../util/test.js";
import {debugPrintOutput, getCode} from "../util/test.js";
import html from "../../src/index.ts";
// const read = (file = 'index.html') => readFileSync(join('output/', file), 'utf-8');
const output = { dir: 'output', format: 'umd' };
const output = {
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
};
import {fileURLToPath} from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
process.chdir(join(__dirname, 'fixtures'));
test.serial('default options', async (t) => {
const bundle = await rollup({
input: 'batman.js',
plugins: [html()]
});
const code = await getCode(bundle, output, true);
t.snapshot(code);
});
test.serial('options', async (t) => {
test.serial('simple', async (t) => {
const bundle = await rollup({
input: 'batman.js',
input: 'index.html',
plugins: [
html({
fileName: 'batman.html',
publicPath: 'batcave/',
title: 'Batcave',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'minimum-scale=1, initial-scale=1, width=device-width' }
]
})
}),
]
});
const code = await getCode(bundle, output, true);
debugPrintOutput('simple',code);
t.snapshot(code);
});
test.serial('iife', async (t) => {
const bundle = await rollup({
input: 'batman.js',
plugins: [html()]
});
const code = await getCode(bundle, { dir: 'output', format: 'iife' }, true);
t.snapshot(code);
});
test.serial('esm', async (t) => {
const bundle = await rollup({
input: 'batman.js',
plugins: [html()]
});
const code = await getCode(bundle, { dir: 'output', format: 'es' }, true);
t.snapshot(code);
});
test.serial('unsupported output format', async (t) => {
const warnings = [];
const bundle = await rollup({
input: 'batman.js',
onwarn: (warning) => warnings.push(warning),
plugins: [html()]
});
const code = await getCode(bundle, { dir: 'output', format: 'cjs' }, true);
t.snapshot(code);
t.snapshot(warnings);
});
test.serial('css', async (t) => {
const bundle = await rollup({
input: 'joker.js',
plugins: [css({ extract: true }), html()]
});
const code = await getCode(bundle, output, true);
t.snapshot(code);
});
test.serial('attributes', async (t) => {
const bundle = await rollup({
input: 'joker.js',
plugins: [
css({ extract: true }),
html({
attributes: {
html: { batsignal: 'on', lang: 'bat' },
link: { 'data-vilian': 'joker' },
script: { defer: true }
}
})
]
});
const code = await getCode(bundle, output, true);
t.snapshot(code);
});
test.serial('imports', async (t) => {
const bundle = await rollup({
input: 'robin.js',
plugins: [html()]
});
const code = await getCode(bundle, output, true);
t.snapshot(code);
});
test.serial('template', async (t) => {
const bundle = await rollup({
input: 'batman.js',
plugins: [
html({
transform: () => '<html><body><main></main></body></html>'
})
]
});
const code = await getCode(bundle, output, true);
t.snapshot(code);
});
// TODO various parameters
// - format: cjs, iifi, ...
// - sourcemap: inline, false, (and the various exotic sourcemap options)
// Watch mode tests would be its own dir
// ...