From da9dc3bdc16d64f1d67a24d912db90af1b68fa26 Mon Sep 17 00:00:00 2001 From: Miel Truyen Date: Mon, 24 Apr 2023 20:15:35 +0200 Subject: [PATCH] Simple handlebars test added (old usage) --- package.json | 9 +++--- pnpm-lock.yaml | 36 ++++++++++++++++++++++ test/{ => basic}/fixtures/batman.js | 0 test/{ => basic}/fixtures/joker.css | 0 test/{ => basic}/fixtures/joker.js | 0 test/{ => basic}/fixtures/robin.js | 0 test/{ => basic}/snapshots/test.js.md | 0 test/{ => basic}/snapshots/test.js.snap | Bin test/{ => basic}/test.js | 4 +-- test/hbs/fixtures/batman.js | 0 test/hbs/fixtures/index.hbs | 6 ++++ test/hbs/snapshots/test.js.md | 38 ++++++++++++++++++++++++ test/hbs/snapshots/test.js.snap | Bin 0 -> 469 bytes test/hbs/test.js | 33 ++++++++++++++++++++ 14 files changed, 119 insertions(+), 7 deletions(-) rename test/{ => basic}/fixtures/batman.js (100%) rename test/{ => basic}/fixtures/joker.css (100%) rename test/{ => basic}/fixtures/joker.js (100%) rename test/{ => basic}/fixtures/robin.js (100%) rename test/{ => basic}/snapshots/test.js.md (100%) rename test/{ => basic}/snapshots/test.js.snap (100%) rename test/{ => basic}/test.js (97%) create mode 100644 test/hbs/fixtures/batman.js create mode 100644 test/hbs/fixtures/index.hbs create mode 100644 test/hbs/snapshots/test.js.md create mode 100644 test/hbs/snapshots/test.js.snap create mode 100644 test/hbs/test.js diff --git a/package.json b/package.json index 9c42a0e..a44b6b9 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a818290..f33c93d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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'} diff --git a/test/fixtures/batman.js b/test/basic/fixtures/batman.js similarity index 100% rename from test/fixtures/batman.js rename to test/basic/fixtures/batman.js diff --git a/test/fixtures/joker.css b/test/basic/fixtures/joker.css similarity index 100% rename from test/fixtures/joker.css rename to test/basic/fixtures/joker.css diff --git a/test/fixtures/joker.js b/test/basic/fixtures/joker.js similarity index 100% rename from test/fixtures/joker.js rename to test/basic/fixtures/joker.js diff --git a/test/fixtures/robin.js b/test/basic/fixtures/robin.js similarity index 100% rename from test/fixtures/robin.js rename to test/basic/fixtures/robin.js diff --git a/test/snapshots/test.js.md b/test/basic/snapshots/test.js.md similarity index 100% rename from test/snapshots/test.js.md rename to test/basic/snapshots/test.js.md diff --git a/test/snapshots/test.js.snap b/test/basic/snapshots/test.js.snap similarity index 100% rename from test/snapshots/test.js.snap rename to test/basic/snapshots/test.js.snap diff --git a/test/test.js b/test/basic/test.js similarity index 97% rename from test/test.js rename to test/basic/test.js index 5451910..568929d 100644 --- a/test/test.js +++ b/test/basic/test.js @@ -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'); diff --git a/test/hbs/fixtures/batman.js b/test/hbs/fixtures/batman.js new file mode 100644 index 0000000..e69de29 diff --git a/test/hbs/fixtures/index.hbs b/test/hbs/fixtures/index.hbs new file mode 100644 index 0000000..075ab39 --- /dev/null +++ b/test/hbs/fixtures/index.hbs @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/hbs/snapshots/test.js.md b/test/hbs/snapshots/test.js.md new file mode 100644 index 0000000..cd3ad1b --- /dev/null +++ b/test/hbs/snapshots/test.js.md @@ -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: `␊ + ␊ + ␊ + ␊ + ␊ + ␊ + `, + }, + ] diff --git a/test/hbs/snapshots/test.js.snap b/test/hbs/snapshots/test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..f57403c531c2aecb9a78399080dbe6a4a8e84b8d GIT binary patch literal 469 zcmV;`0V@7MRzVV8L&)8 zI%N|*Qbu3j3Be3Iu^w$wBl&`5u(z;oBlZ#NP+fz{L6)%@z=AcKO#%)9i@*xN;oOMq zDzA`dRGyGNBTj*k8^i+?S=HlUEV%*eleSu|56cTmUJ-AIRf~|eRkGMWEe!%o1e&O^ zHozuOS%W36ge)5CmUP2u%1xwF+6@^uDx3A_g;O`PiBusKGK^A5ecz{@g|I{0?c$)% z5<&Nh=F7k1)C=D24V=qf_uE4-opz>LQf;z`o6f+&b=gB*Y0l*^iscbY7PCSPNJ7JR#ZZ}FNRjsBOpC{BB|GbV`+5Kw*CrX7p?~hCp|24v|knba48xC{#t}{%e zVKo1-HjUKAcbV(qZlJ^ri{@E0F;r*Vcl+Mwy { + 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); +});