Simple handlebars test added (old usage)
This commit is contained in:
@@ -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');
|
||||
|
||||
0
test/hbs/fixtures/batman.js
Normal file
0
test/hbs/fixtures/batman.js
Normal file
6
test/hbs/fixtures/index.hbs
Normal file
6
test/hbs/fixtures/index.hbs
Normal file
@@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<meta data-test="{{a}}"/>
|
||||
<body>
|
||||
<script src="./batman.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
38
test/hbs/snapshots/test.js.md
Normal file
38
test/hbs/snapshots/test.js.md
Normal 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>␊
|
||||
`,
|
||||
},
|
||||
]
|
||||
BIN
test/hbs/snapshots/test.js.snap
Normal file
BIN
test/hbs/snapshots/test.js.snap
Normal file
Binary file not shown.
33
test/hbs/test.js
Normal file
33
test/hbs/test.js
Normal 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);
|
||||
});
|
||||
Reference in New Issue
Block a user