From f9cce4dd02577743a304bbf181dc90e371673be8 Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Sat, 31 Aug 2019 13:18:47 +0200 Subject: [PATCH] chore: add framework for various integration tests --- .travis.yml | 2 +- Gruntfile.js | 2 +- integration-testing/README.md | 12 ++ .../multi-nodejs-test/.eslintrc.js | 12 ++ .../multi-nodejs-test/.gitignore | 1 + .../precompile-test-template.txt.hbs | 1 + .../multi-nodejs-test/run-handlebars.js | 14 +++ .../multi-nodejs-test/test.sh | 8 +- integration-testing/run-integration-tests.sh | 12 ++ .../.gitignore | 0 .../package-lock.json | 17 +++ .../package.json | 15 +++ .../test.sh | 3 + multi-nodejs-test/.eslintrc.js | 114 ------------------ multi-nodejs-test/expected.txt | 1 - multi-nodejs-test/run-handlebars.js | 13 -- multi-nodejs-test/template.txt.hbs | 1 - 17 files changed, 94 insertions(+), 134 deletions(-) create mode 100644 integration-testing/README.md create mode 100644 integration-testing/multi-nodejs-test/.eslintrc.js create mode 100644 integration-testing/multi-nodejs-test/.gitignore create mode 100644 integration-testing/multi-nodejs-test/precompile-test-template.txt.hbs create mode 100755 integration-testing/multi-nodejs-test/run-handlebars.js rename multi-nodejs-test/run-tests.sh => integration-testing/multi-nodejs-test/test.sh (77%) create mode 100755 integration-testing/run-integration-tests.sh create mode 100644 integration-testing/webpack-handlebars-loader-test-npm/.gitignore create mode 100644 integration-testing/webpack-handlebars-loader-test-npm/package-lock.json create mode 100644 integration-testing/webpack-handlebars-loader-test-npm/package.json create mode 100755 integration-testing/webpack-handlebars-loader-test-npm/test.sh delete mode 100644 multi-nodejs-test/.eslintrc.js delete mode 100644 multi-nodejs-test/expected.txt delete mode 100755 multi-nodejs-test/run-handlebars.js delete mode 100644 multi-nodejs-test/template.txt.hbs diff --git a/.travis.yml b/.travis.yml index b8c200dd2..20e7c895a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Gruntfile.js b/Gruntfile.js index 8fd258601..871ea4611 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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' ] }, diff --git a/integration-testing/README.md b/integration-testing/README.md new file mode 100644 index 000000000..bd9554c53 --- /dev/null +++ b/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. + + \ No newline at end of file diff --git a/integration-testing/multi-nodejs-test/.eslintrc.js b/integration-testing/multi-nodejs-test/.eslintrc.js new file mode 100644 index 000000000..7f583d1c5 --- /dev/null +++ b/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' + } +} \ No newline at end of file diff --git a/integration-testing/multi-nodejs-test/.gitignore b/integration-testing/multi-nodejs-test/.gitignore new file mode 100644 index 000000000..1de565933 --- /dev/null +++ b/integration-testing/multi-nodejs-test/.gitignore @@ -0,0 +1 @@ +target \ No newline at end of file diff --git a/integration-testing/multi-nodejs-test/precompile-test-template.txt.hbs b/integration-testing/multi-nodejs-test/precompile-test-template.txt.hbs new file mode 100644 index 000000000..d29a17914 --- /dev/null +++ b/integration-testing/multi-nodejs-test/precompile-test-template.txt.hbs @@ -0,0 +1 @@ +Author: {{author}} \ No newline at end of file diff --git a/integration-testing/multi-nodejs-test/run-handlebars.js b/integration-testing/multi-nodejs-test/run-handlebars.js new file mode 100755 index 000000000..126354dbe --- /dev/null +++ b/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'); diff --git a/multi-nodejs-test/run-tests.sh b/integration-testing/multi-nodejs-test/test.sh similarity index 77% rename from multi-nodejs-test/run-tests.sh rename to integration-testing/multi-nodejs-test/test.sh index 174a12ccb..92e7e47de 100755 --- a/multi-nodejs-test/run-tests.sh +++ b/integration-testing/multi-nodejs-test/test.sh @@ -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. @@ -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 \ No newline at end of file diff --git a/integration-testing/run-integration-tests.sh b/integration-testing/run-integration-tests.sh new file mode 100755 index 000000000..79bfa87a4 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/integration-testing/webpack-handlebars-loader-test-npm/.gitignore b/integration-testing/webpack-handlebars-loader-test-npm/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/integration-testing/webpack-handlebars-loader-test-npm/package-lock.json b/integration-testing/webpack-handlebars-loader-test-npm/package-lock.json new file mode 100644 index 000000000..f5074caf6 --- /dev/null +++ b/integration-testing/webpack-handlebars-loader-test-npm/package-lock.json @@ -0,0 +1,17 @@ +{ + "name": "webpack-handlebars-loader-test", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "handlebars": { + "version": "file:../..", + "requires": { + "neo-async": "^2.6.0", + "optimist": "^0.6.1", + "source-map": "^0.6.1", + "uglify-js": "^3.1.4" + } + } + } +} diff --git a/integration-testing/webpack-handlebars-loader-test-npm/package.json b/integration-testing/webpack-handlebars-loader-test-npm/package.json new file mode 100644 index 000000000..7bc7d19d0 --- /dev/null +++ b/integration-testing/webpack-handlebars-loader-test-npm/package.json @@ -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:../.." + } +} diff --git a/integration-testing/webpack-handlebars-loader-test-npm/test.sh b/integration-testing/webpack-handlebars-loader-test-npm/test.sh new file mode 100755 index 000000000..45816bd25 --- /dev/null +++ b/integration-testing/webpack-handlebars-loader-test-npm/test.sh @@ -0,0 +1,3 @@ +npm install +npm test + diff --git a/multi-nodejs-test/.eslintrc.js b/multi-nodejs-test/.eslintrc.js deleted file mode 100644 index 6d3592c7b..000000000 --- a/multi-nodejs-test/.eslintrc.js +++ /dev/null @@ -1,114 +0,0 @@ -module.exports = { - "extends": "eslint:recommended", - "globals": { - "self": false - }, - "env": { - "node": true - }, - "rules": { - // overrides eslint:recommended defaults - "no-sparse-arrays": "off", - "no-func-assign": "off", - "no-console": "off", - "no-debugger": "warn", - "no-unreachable": "warn", - - // Possible Errors // - //-----------------// - "no-unsafe-negation": "error", - - - // Best Practices // - //----------------// - "curly": "error", - "default-case": "warn", - "dot-notation": ["error", { "allowKeywords": false }], - "guard-for-in": "warn", - "no-alert": "error", - "no-caller": "error", - "no-div-regex": "warn", - "no-eval": "error", - "no-extend-native": "error", - "no-extra-bind": "error", - "no-floating-decimal": "error", - "no-implied-eval": "error", - "no-iterator": "error", - "no-labels": "error", - "no-lone-blocks": "error", - "no-loop-func": "error", - "no-multi-spaces": "error", - "no-multi-str": "warn", - "no-global-assign": "error", - "no-new": "error", - "no-new-func": "error", - "no-new-wrappers": "error", - "no-octal-escape": "error", - "no-process-env": "error", - "no-proto": "error", - "no-return-assign": "error", - "no-script-url": "error", - "no-self-compare": "error", - "no-sequences": "error", - "no-throw-literal": "error", - "no-unused-expressions": "error", - "no-warning-comments": "warn", - "no-with": "error", - "radix": "error", - "wrap-iife": "error", - - - // Variables // - //-----------// - "no-catch-shadow": "error", - "no-label-var": "error", - "no-shadow-restricted-names": "error", - "no-undef-init": "error", - "no-use-before-define": ["error", "nofunc"], - - - // Stylistic Issues // - //------------------// - "comma-dangle": ["error", "never"], - "quote-props": ["error", "as-needed", { "keywords": true, "unnecessary": false }], - "brace-style": ["error", "1tbs", { "allowSingleLine": true }], - "camelcase": "error", - "comma-spacing": ["error", { "before": false, "after": true }], - "comma-style": ["error", "last"], - "consistent-this": ["warn", "self"], - "eol-last": "error", - "func-style": ["error", "declaration"], - "key-spacing": ["error", { - "beforeColon": false, - "afterColon": true - }], - "new-cap": "error", - "new-parens": "error", - "no-array-constructor": "error", - "no-lonely-if": "error", - "no-mixed-spaces-and-tabs": "error", - "no-nested-ternary": "warn", - "no-new-object": "error", - "no-spaced-func": "error", - "no-trailing-spaces": "error", - "no-extra-parens": ["error", "functions"], - "quotes": ["error", "single", "avoid-escape"], - "semi": "error", - "semi-spacing": ["error", { "before": false, "after": true }], - "keyword-spacing": "error", - "space-before-blocks": ["error", "always"], - "space-before-function-paren": ["error", { "anonymous": "never", "named": "never" }], - "space-in-parens": ["error", "never"], - "space-infix-ops": "error", - "space-unary-ops": "error", - "spaced-comment": ["error", "always", { "markers": [","] }], - "wrap-regex": "warn", - - // ECMAScript 6 // - //--------------// - "no-var": "off" - }, - "parserOptions": { - "sourceType": "module" - } -} \ No newline at end of file diff --git a/multi-nodejs-test/expected.txt b/multi-nodejs-test/expected.txt deleted file mode 100644 index 19a4be2d7..000000000 --- a/multi-nodejs-test/expected.txt +++ /dev/null @@ -1 +0,0 @@ -Author: Yehuda diff --git a/multi-nodejs-test/run-handlebars.js b/multi-nodejs-test/run-handlebars.js deleted file mode 100755 index 58bc8d495..000000000 --- a/multi-nodejs-test/run-handlebars.js +++ /dev/null @@ -1,13 +0,0 @@ -// This test should run with node 0.10 as long as Handlebars has been compiled before -var Handlebars = require('../'); -var fs = require('fs'); - -console.log('Testing build Handlebars with Node version ' + process.version); -var template = fs.readFileSync(require.resolve('./template.txt.hbs'), 'utf-8'); -var compiledOutput = Handlebars.compile(template)({author: 'Yehuda'}).trim(); -var expectedOutput = fs.readFileSync(require.resolve('./expected.txt'), 'utf-8').trim(); - -if (compiledOutput !== expectedOutput) { - throw new Error('Compiled output (' + compiledOutput + ') did not match expected output (' + expectedOutput + ')'); -} -console.log('Success'); diff --git a/multi-nodejs-test/template.txt.hbs b/multi-nodejs-test/template.txt.hbs deleted file mode 100644 index 61d4dd7fa..000000000 --- a/multi-nodejs-test/template.txt.hbs +++ /dev/null @@ -1 +0,0 @@ -Author: {{author}}