Skip to content

Commit

Permalink
add webpack test
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Aug 31, 2019
1 parent a26633f commit a57b682
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,3 +12,4 @@ npm-debug.log
sauce_connect.log*
.idea
yarn-error.log
/handlebars-release.tgz
1 change: 1 addition & 0 deletions integration-testing/run-integration-tests.sh
@@ -1,6 +1,7 @@
#!/bin/bash

cd "$( dirname "$( readlink -f "$0" )" )" || exit 1

for i in */test.sh ; do
(
echo "----------------------------------------"
Expand Down
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions integration-testing/webpack-test/.gitignore
@@ -0,0 +1,3 @@
node_modules
dist
package-lock.json
21 changes: 21 additions & 0 deletions integration-testing/webpack-test/package.json
@@ -0,0 +1,21 @@
{
"name": "webpack-test",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"test": "node dist/main.js"
},
"private": true,
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"handlebars": "file:../..",
"handlebars-loader": "^1.7.1",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.7"
},
"description": ""
}
@@ -0,0 +1,6 @@
import Handlebars from 'handlebars/dist/handlebars';

import {assertEquals} from './lib/assert';

const template = Handlebars.compile('Author: {{author}}');
assertEquals(template({author: 'Yehuda'}), 'Author: Yehuda');
@@ -0,0 +1,6 @@
import Handlebars from 'handlebars';
import {assertEquals} from './lib/assert';


const template = Handlebars.compile('Author: {{author}}');
assertEquals(template({author: 'Yehuda'}), 'Author: Yehuda');
@@ -0,0 +1,8 @@
import {assertEquals} from './lib/assert';

import testTemplate from './test-template.handlebars';
assertEquals(testTemplate({author: 'Yehuda'}).trim(), 'Author: Yehuda');


const testTemplateRequire = require('./test-template.handlebars');
assertEquals(testTemplateRequire({author: 'Yehuda'}).trim(), 'Author: Yehuda');
@@ -0,0 +1,6 @@
import * as Handlebars from 'handlebars/dist/handlebars';

import {assertEquals} from './lib/assert';

const template = Handlebars.compile('Author: {{author}}');
assertEquals(template({author: 'Yehuda'}), 'Author: Yehuda');
@@ -0,0 +1,5 @@
import * as Handlebars from 'handlebars';
import {assertEquals} from './lib/assert';

const template = Handlebars.compile('Author: {{author}}');
assertEquals(template({author: 'Yehuda'}), 'Author: Yehuda');
5 changes: 5 additions & 0 deletions integration-testing/webpack-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}"`);
}
}
2 changes: 2 additions & 0 deletions integration-testing/webpack-test/src/test-template.handlebars
@@ -0,0 +1,2 @@
Author: {{author}}

16 changes: 16 additions & 0 deletions integration-testing/webpack-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
22 changes: 22 additions & 0 deletions integration-testing/webpack-test/webpack.config.js
@@ -0,0 +1,22 @@
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: /\.handlebars$/, loader: 'handlebars-loader'}
]
}
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a57b682

Please sign in to comment.