Skip to content

Commit

Permalink
chore: add framework for various integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Aug 31, 2019
1 parent 16572cd commit f9cce4d
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,7 @@ before_install:
- npm install -g grunt-cli
script:
- grunt --stack travis
- multi-nodejs-test/run-tests.sh 0.10 0.12 4 5 6 7 8 9 10 11
- integration-testing/run-integration-tests.sh
email:
on_failure: change
on_success: never
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Expand Up @@ -13,7 +13,7 @@ module.exports = function(grunt) {
'tasks/**/*.js',
'lib/**/!(*.min|parser).js',
'spec/**/!(*.amd|json2|require).js',
'multi-nodejs-test/*.js'
'integration-testing/**/*.js'
]
},

Expand Down
12 changes: 12 additions & 0 deletions integration-testing/README.md
@@ -0,0 +1,12 @@
Add a new integration test by creating a new subfolder

Add a file "test.sh" to that runs the test. "test.sh" should exit with a non-zero exit code
and display an error message, if something goes wrong.

* An integration test should reflect real-world setups that use handlebars.
* It should compile a minimal template and compare the output to an expected output.
* It should use "../.." as dependency for Handlebars so that the currently built library is used.

Currently, integration tests are only running on Linux, especially in travis-ci.


12 changes: 12 additions & 0 deletions integration-testing/multi-nodejs-test/.eslintrc.js
@@ -0,0 +1,12 @@
module.exports = {
"extends": "eslint:recommended",
"globals": {
"self": false
},
"env": {
"node": true
},
"rules": {
'no-console': 'off'
}
}
1 change: 1 addition & 0 deletions integration-testing/multi-nodejs-test/.gitignore
@@ -0,0 +1 @@
target
@@ -0,0 +1 @@
Author: {{author}}
14 changes: 14 additions & 0 deletions integration-testing/multi-nodejs-test/run-handlebars.js
@@ -0,0 +1,14 @@
// This test should run successfully with node 0.10 as long as Handlebars has been compiled before
var assert = require('assert');
var Handlebars = require('../../');

console.log('Testing build Handlebars with Node version ' + process.version);

var output = Handlebars.compile('Author: {{author}}')({author: 'Yehuda'});
if (output !== 'Author: Yehuda') {
throw new Error('Compiled output (' + compiledOutput + ') did not match expected output (' + expectedOutput + ')');
}

assert.equal(output, 'Author: Yehuda')

console.log('Success');
@@ -1,6 +1,6 @@
#!/bin/bash

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

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

# A list of NodeJS versions is expected as cli-args
echo "Handlebars should be able to run in various versions of NodeJS"
for i in "$@" ; do
for i in 0.10 0.12 4 5 6 7 8 9 10 11 ; do
rm target -rf
mkdir target
nvm install "$i"
nvm exec "$i" node ./run-handlebars.js >/dev/null || exit 1
nvm exec "$i" node ../bin/handlebars template.txt.hbs >/dev/null || exit 1
nvm exec "$i" node ../../bin/handlebars precompile-test-template.txt.hbs -f target/precompile-test-template.js || exit 1
echo Success
done
12 changes: 12 additions & 0 deletions integration-testing/run-integration-tests.sh
@@ -0,0 +1,12 @@
#!/bin/bash

cd "$( dirname "$( readlink -f "$0" )" )" || exit 1
for i in */test.sh ; do
(
echo "----------------------------------------"
echo "-- Running integration test: $i"
echo "----------------------------------------"
cd "$( dirname "$i" )" || exit 1
./test.sh || exit 1
)
done
Empty file.

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

@@ -0,0 +1,15 @@
{
"name": "webpack-handlebars-loader-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"handlebars": "file:../.."
}
}
@@ -0,0 +1,3 @@
npm install
npm test

114 changes: 0 additions & 114 deletions multi-nodejs-test/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion multi-nodejs-test/expected.txt

This file was deleted.

13 changes: 0 additions & 13 deletions multi-nodejs-test/run-handlebars.js

This file was deleted.

1 change: 0 additions & 1 deletion multi-nodejs-test/template.txt.hbs

This file was deleted.

0 comments on commit f9cce4d

Please sign in to comment.