-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
8 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"plugins": [ | ||
"@roundingwellos/babel-plugin-handlebars-inline-precompile" | ||
// "istanbul" | ||
], | ||
"presets": [ | ||
[ | ||
"@babel/preset-env" | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
integration-testing/webpack-babel-test/src/handlebars-inline-precompile-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function assertEquals(actual, expected) { | ||
if (actual !== expected) { | ||
throw new Error(`Expected "${actual}" to equal "${expected}"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
}; |
10 changes: 10 additions & 0 deletions
10
integration-testing/webpack-test/src/handlebars-require-vs-import-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |