Skip to content

Commit f9cce4d

Browse files
committed
chore: add framework for various integration tests
1 parent 16572cd commit f9cce4d

17 files changed

+94
-134
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ before_install:
33
- npm install -g grunt-cli
44
script:
55
- grunt --stack travis
6-
- multi-nodejs-test/run-tests.sh 0.10 0.12 4 5 6 7 8 9 10 11
6+
- integration-testing/run-integration-tests.sh
77
email:
88
on_failure: change
99
on_success: never

Gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function(grunt) {
1313
'tasks/**/*.js',
1414
'lib/**/!(*.min|parser).js',
1515
'spec/**/!(*.amd|json2|require).js',
16-
'multi-nodejs-test/*.js'
16+
'integration-testing/**/*.js'
1717
]
1818
},
1919

integration-testing/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Add a new integration test by creating a new subfolder
2+
3+
Add a file "test.sh" to that runs the test. "test.sh" should exit with a non-zero exit code
4+
and display an error message, if something goes wrong.
5+
6+
* An integration test should reflect real-world setups that use handlebars.
7+
* It should compile a minimal template and compare the output to an expected output.
8+
* It should use "../.." as dependency for Handlebars so that the currently built library is used.
9+
10+
Currently, integration tests are only running on Linux, especially in travis-ci.
11+
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
"extends": "eslint:recommended",
3+
"globals": {
4+
"self": false
5+
},
6+
"env": {
7+
"node": true
8+
},
9+
"rules": {
10+
'no-console': 'off'
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Author: {{author}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This test should run successfully with node 0.10 as long as Handlebars has been compiled before
2+
var assert = require('assert');
3+
var Handlebars = require('../../');
4+
5+
console.log('Testing build Handlebars with Node version ' + process.version);
6+
7+
var output = Handlebars.compile('Author: {{author}}')({author: 'Yehuda'});
8+
if (output !== 'Author: Yehuda') {
9+
throw new Error('Compiled output (' + compiledOutput + ') did not match expected output (' + expectedOutput + ')');
10+
}
11+
12+
assert.equal(output, 'Author: Yehuda')
13+
14+
console.log('Success');

multi-nodejs-test/run-tests.sh renamed to integration-testing/multi-nodejs-test/test.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
cd "$( dirname "$( readlink -f "$0" )" )"
3+
cd "$( dirname "$( readlink -f "$0" )" )" || exit 1
44
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
55

66
# This script tests with precompiler and the built distribution with multiple NodeJS version.
@@ -13,9 +13,11 @@ cd "$( dirname "$( readlink -f "$0" )" )"
1313

1414
# A list of NodeJS versions is expected as cli-args
1515
echo "Handlebars should be able to run in various versions of NodeJS"
16-
for i in "$@" ; do
16+
for i in 0.10 0.12 4 5 6 7 8 9 10 11 ; do
17+
rm target -rf
18+
mkdir target
1719
nvm install "$i"
1820
nvm exec "$i" node ./run-handlebars.js >/dev/null || exit 1
19-
nvm exec "$i" node ../bin/handlebars template.txt.hbs >/dev/null || exit 1
21+
nvm exec "$i" node ../../bin/handlebars precompile-test-template.txt.hbs -f target/precompile-test-template.js || exit 1
2022
echo Success
2123
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
cd "$( dirname "$( readlink -f "$0" )" )" || exit 1
4+
for i in */test.sh ; do
5+
(
6+
echo "----------------------------------------"
7+
echo "-- Running integration test: $i"
8+
echo "----------------------------------------"
9+
cd "$( dirname "$i" )" || exit 1
10+
./test.sh || exit 1
11+
)
12+
done

integration-testing/webpack-handlebars-loader-test-npm/.gitignore

Whitespace-only changes.

integration-testing/webpack-handlebars-loader-test-npm/package-lock.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "webpack-handlebars-loader-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\""
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"handlebars": "file:../.."
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
npm install
2+
npm test
3+

multi-nodejs-test/.eslintrc.js

-114
This file was deleted.

multi-nodejs-test/expected.txt

-1
This file was deleted.

multi-nodejs-test/run-handlebars.js

-13
This file was deleted.

multi-nodejs-test/template.txt.hbs

-1
This file was deleted.

0 commit comments

Comments
 (0)