integration-tests for various webpack-scenarios
related to #1553 - registering helpers on an instance retrieved via `import`, compiling the template on an instance retrieved via `require` - using `@roundingwellos/babel-plugin-handlebars-inline-precompile` to load plugins inline
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"plugins": [
|
||||
"@roundingwellos/babel-plugin-handlebars-inline-precompile"
|
||||
// "istanbul"
|
||||
],
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env"
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
dist
|
||||
package-lock.json
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "webpack-babel-test",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.5.5",
|
||||
"@babel/preset-env": "^7.5.5",
|
||||
"@roundingwellos/babel-plugin-handlebars-inline-precompile": "^3.0.1",
|
||||
"babel-loader": "^8.0.6",
|
||||
"babel-plugin-istanbul": "^5.2.0",
|
||||
"handlebars": "file:../..",
|
||||
"handlebars-loader": "^1.7.1",
|
||||
"nyc": "^14.1.1",
|
||||
"webpack": "^4.39.3",
|
||||
"webpack-cli": "^3.3.7"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "webpack --config webpack.config.js"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import * as Handlebars from 'handlebars/runtime'
|
||||
import hbs from 'handlebars-inline-precompile';
|
||||
import {assertEquals} from "../../webpack-test/src/lib/assert";
|
||||
|
||||
Handlebars.registerHelper('loud', function(text) {
|
||||
return text.toUpperCase();
|
||||
});
|
||||
|
||||
const template = hbs`{{loud name}}`;
|
||||
const output = template({name: 'yehuda'})
|
||||
|
||||
assertEquals(output, 'YEHUDA')
|
||||
@@ -0,0 +1,5 @@
|
||||
export function assertEquals(actual, expected) {
|
||||
if (actual !== expected) {
|
||||
throw new Error(`Expected "${actual}" to equal "${expected}"`);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Cleanup: package-lock and "npm ci" is not working with local dependencies
|
||||
rm dist package-lock.json -rf
|
||||
npm install
|
||||
npm run build
|
||||
|
||||
for i in dist/*-test.js ; do
|
||||
echo "----------------------"
|
||||
echo "-- Running $i"
|
||||
echo "----------------------"
|
||||
node "$i"
|
||||
echo "Success"
|
||||
done
|
||||
@@ -0,0 +1,32 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const testFiles = fs.readdirSync('src');
|
||||
const entryPoints = {};
|
||||
testFiles
|
||||
.filter(file => file.match(/-test.js$/))
|
||||
.forEach(file => {
|
||||
entryPoints[file] = `./src/${file}`;
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
entry: entryPoints,
|
||||
output: {
|
||||
filename: '[name]',
|
||||
path: __dirname + '/dist'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.js?$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: { cacheDirectory: false },
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
optimization: {
|
||||
minimize: false
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import * as HandlebarsViaImport from 'handlebars';
|
||||
const HandlebarsViaRequire = require('handlebars');
|
||||
import {assertEquals} from './lib/assert';
|
||||
|
||||
HandlebarsViaImport.registerHelper('loud', function(text) {
|
||||
return text.toUpperCase();
|
||||
});
|
||||
|
||||
const template = HandlebarsViaRequire.compile('Author: {{loud author}}');
|
||||
assertEquals(template({author: 'Yehuda'}), 'Author: YEHUDA');
|
||||
Reference in New Issue
Block a user