Simple handlebars test added (old usage)

This commit is contained in:
2023-04-24 20:15:35 +02:00
parent 7e45443d19
commit da9dc3bdc1
14 changed files with 119 additions and 7 deletions

View File

@@ -4,9 +4,9 @@ import test from "ava";
import { rollup } from "rollup";
import css from "rollup-plugin-postcss";
import { getCode } from "./util/test.js";
import { getCode } from "../util/test.js";
import html from "../src/index.ts";
import html from "../../src/index.ts";
// const read = (file = 'index.html') => readFileSync(join('output/', file), 'utf-8');

View File

View File

@@ -0,0 +1,6 @@
<html>
<meta data-test="{{a}}"/>
<body>
<script src="./batman.js" type="module"></script>
</body>
</html>

View File

@@ -0,0 +1,38 @@
# Snapshot report for `test/hbs/test.js`
The actual snapshot is saved in `test.js.snap`.
Generated by [AVA](https://avajs.dev).
## handlebars
> Snapshot 1
[
{
code: `(function (factory) {␊
typeof define === 'function' && define.amd ? define(factory) :␊
factory();␊
})((function () { 'use strict';␊
␊=-u
}));␊
`,
fileName: 'batman.js',
map: null,
source: undefined,
},
{
code: undefined,
fileName: 'index.html',
map: undefined,
source: `<html>␊
<meta data-test="a"/>␊
<body>␊
<script src="./batman.js" type="module"></script>␊
</body>␊
</html>␊
`,
},
]

Binary file not shown.

33
test/hbs/test.js Normal file
View File

@@ -0,0 +1,33 @@
import {join, dirname} from "node:path";
import test from "ava";
import { rollup } from "rollup";
import { getCode } from "../util/test.js";
import html from "../../src/index.ts";
import handlebars from "handlebars";
const output = { dir: 'output', format: 'umd' };
import {readFile} from "node:fs/promises";
import {fileURLToPath} from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
process.chdir(join(__dirname, 'fixtures'));
test.serial('handlebars', async (t) => {
const template = await readFile('index.hbs', {encoding: "utf-8"});
const bundle = await rollup({
input: 'batman.js',
plugins: [
html({
fileName: 'index.html',
template(ctx){
return handlebars.compile(template)({a:'a'})
}
})
]
});
const code = await getCode(bundle, output, true);
t.snapshot(code);
});