Simple handlebars test added (old usage)

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

View File

@ -1,9 +1,6 @@
{
"name": "@rollup-apps/plugin-html",
"version": "0.0.1",
"publishConfig": {
"access": "public"
},
"description": "Creates HTML files to serve Rollup bundles",
"license": "MIT",
"repository": {
@ -24,7 +21,8 @@
"import": "./dist/es/index.js"
},
"publishConfig": {
"registry": "https://npm.cerxes.net"
"registry": "https://npm.cerxes.net",
"access": "public"
},
"scripts": {
"build": "rollup -c",
@ -73,7 +71,8 @@
"rollup-plugin-delete": "^2.0.0",
"@babel/preset-typescript": "^7.21.4",
"nyc": "^15.1.0",
"lint-staged": "^13.2.1"
"lint-staged": "^13.2.1",
"handlebars": "^4.7.7"
},
"types": "./types/index.d.ts",
"ava": {

36
pnpm-lock.yaml generated
View File

@ -28,6 +28,9 @@ devDependencies:
del-cli:
specifier: ^5.0.0
version: 5.0.0
handlebars:
specifier: ^4.7.7
version: 4.7.7
lint-staged:
specifier: ^13.2.1
version: 13.2.1
@ -1610,6 +1613,19 @@ packages:
resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==}
dev: true
/handlebars@4.7.7:
resolution: {integrity: sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==}
engines: {node: '>=0.4.7'}
hasBin: true
dependencies:
minimist: 1.2.8
neo-async: 2.6.2
source-map: 0.6.1
wordwrap: 1.0.0
optionalDependencies:
uglify-js: 3.17.4
dev: true
/hard-rejection@2.1.0:
resolution: {integrity: sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA==}
engines: {node: '>=6'}
@ -2191,6 +2207,10 @@ packages:
kind-of: 6.0.3
dev: true
/minimist@1.2.8:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
dev: true
/ms@2.1.2:
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
dev: true
@ -2205,6 +2225,10 @@ packages:
hasBin: true
dev: true
/neo-async@2.6.2:
resolution: {integrity: sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==}
dev: true
/node-preload@0.2.1:
resolution: {integrity: sha512-RM5oyBy45cLEoHqCeh+MNuFAxO0vTFBLskvQbOKnEE7YTTSN4tbN8QWDIPQ6L+WvKsB/qLEGpYe2ZZ9d4W9OIQ==}
engines: {node: '>=8'}
@ -3441,6 +3465,14 @@ packages:
hasBin: true
dev: true
/uglify-js@3.17.4:
resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==}
engines: {node: '>=0.8.0'}
hasBin: true
requiresBuild: true
dev: true
optional: true
/update-browserslist-db@1.0.11(browserslist@4.21.5):
resolution: {integrity: sha512-dCwEFf0/oT85M1fHBg4F0jtLwJrutGoHSQXCh7u4o2t1drG+c0a9Flnqww6XUKSfQMPpJBRjU8d4RXB09qtvaA==}
hasBin: true
@ -3489,6 +3521,10 @@ packages:
isexe: 2.0.0
dev: true
/wordwrap@1.0.0:
resolution: {integrity: sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==}
dev: true
/wrap-ansi@6.2.0:
resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==}
engines: {node: '>=8'}

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);
});