diff --git a/integration-testing/webpack-babel-test/.babelrc b/integration-testing/webpack-babel-test/.babelrc new file mode 100644 index 000000000..6c1ec732b --- /dev/null +++ b/integration-testing/webpack-babel-test/.babelrc @@ -0,0 +1,11 @@ +{ + "plugins": [ + "@roundingwellos/babel-plugin-handlebars-inline-precompile" + // "istanbul" + ], + "presets": [ + [ + "@babel/preset-env" + ] + ] +} \ No newline at end of file diff --git a/integration-testing/webpack-babel-test/.gitignore b/integration-testing/webpack-babel-test/.gitignore new file mode 100644 index 000000000..3a8ec2b3f --- /dev/null +++ b/integration-testing/webpack-babel-test/.gitignore @@ -0,0 +1,3 @@ +node_modules +dist +package-lock.json \ No newline at end of file diff --git a/integration-testing/webpack-babel-test/package.json b/integration-testing/webpack-babel-test/package.json new file mode 100644 index 000000000..dd21ae0af --- /dev/null +++ b/integration-testing/webpack-babel-test/package.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" + } +} diff --git a/integration-testing/webpack-babel-test/src/handlebars-inline-precompile-test.js b/integration-testing/webpack-babel-test/src/handlebars-inline-precompile-test.js new file mode 100644 index 000000000..7f764e328 --- /dev/null +++ b/integration-testing/webpack-babel-test/src/handlebars-inline-precompile-test.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') \ No newline at end of file diff --git a/integration-testing/webpack-babel-test/src/lib/assert.js b/integration-testing/webpack-babel-test/src/lib/assert.js new file mode 100644 index 000000000..9f33188db --- /dev/null +++ b/integration-testing/webpack-babel-test/src/lib/assert.js @@ -0,0 +1,5 @@ +export function assertEquals(actual, expected) { + if (actual !== expected) { + throw new Error(`Expected "${actual}" to equal "${expected}"`); + } +} diff --git a/integration-testing/webpack-babel-test/test.sh b/integration-testing/webpack-babel-test/test.sh new file mode 100755 index 000000000..a45d5625f --- /dev/null +++ b/integration-testing/webpack-babel-test/test.sh @@ -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 \ No newline at end of file diff --git a/integration-testing/webpack-babel-test/webpack.config.js b/integration-testing/webpack-babel-test/webpack.config.js new file mode 100644 index 000000000..9ad0a09b2 --- /dev/null +++ b/integration-testing/webpack-babel-test/webpack.config.js @@ -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 + } +}; diff --git a/integration-testing/webpack-test/src/handlebars-require-vs-import-test.js b/integration-testing/webpack-test/src/handlebars-require-vs-import-test.js new file mode 100644 index 000000000..13e2c97d7 --- /dev/null +++ b/integration-testing/webpack-test/src/handlebars-require-vs-import-test.js @@ -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');