Skip to content

Commit b92589a

Browse files
committedFeb 18, 2019
test: add test for NodeJS compatibility
The test is a simple addition to the existing tests. It should ensure that the built Handlebars artifact only uses language features that are available in old versions of NodeJS. A simple program and the precompiler are started with NodeJS 0.10 to 11
1 parent 1c62d4c commit b92589a

File tree

7 files changed

+153
-1
lines changed

7 files changed

+153
-1
lines changed
 

‎.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +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
67
email:
78
on_failure: change
89
on_success: never

‎Gruntfile.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = function(grunt) {
1212
'bench/**/*.js',
1313
'tasks/**/*.js',
1414
'lib/**/!(*.min|parser).js',
15-
'spec/**/!(*.amd|json2|require).js'
15+
'spec/**/!(*.amd|json2|require).js',
16+
'multi-nodejs-test/*.js'
1617
]
1718
},
1819

‎multi-nodejs-test/.eslintrc.js

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
module.exports = {
2+
"extends": "eslint:recommended",
3+
"globals": {
4+
"self": false
5+
},
6+
"env": {
7+
"node": true
8+
},
9+
"rules": {
10+
// overrides eslint:recommended defaults
11+
"no-sparse-arrays": "off",
12+
"no-func-assign": "off",
13+
"no-console": "off",
14+
"no-debugger": "warn",
15+
"no-unreachable": "warn",
16+
17+
// Possible Errors //
18+
//-----------------//
19+
"no-unsafe-negation": "error",
20+
21+
22+
// Best Practices //
23+
//----------------//
24+
"curly": "error",
25+
"default-case": "warn",
26+
"dot-notation": ["error", { "allowKeywords": false }],
27+
"guard-for-in": "warn",
28+
"no-alert": "error",
29+
"no-caller": "error",
30+
"no-div-regex": "warn",
31+
"no-eval": "error",
32+
"no-extend-native": "error",
33+
"no-extra-bind": "error",
34+
"no-floating-decimal": "error",
35+
"no-implied-eval": "error",
36+
"no-iterator": "error",
37+
"no-labels": "error",
38+
"no-lone-blocks": "error",
39+
"no-loop-func": "error",
40+
"no-multi-spaces": "error",
41+
"no-multi-str": "warn",
42+
"no-global-assign": "error",
43+
"no-new": "error",
44+
"no-new-func": "error",
45+
"no-new-wrappers": "error",
46+
"no-octal-escape": "error",
47+
"no-process-env": "error",
48+
"no-proto": "error",
49+
"no-return-assign": "error",
50+
"no-script-url": "error",
51+
"no-self-compare": "error",
52+
"no-sequences": "error",
53+
"no-throw-literal": "error",
54+
"no-unused-expressions": "error",
55+
"no-warning-comments": "warn",
56+
"no-with": "error",
57+
"radix": "error",
58+
"wrap-iife": "error",
59+
60+
61+
// Variables //
62+
//-----------//
63+
"no-catch-shadow": "error",
64+
"no-label-var": "error",
65+
"no-shadow-restricted-names": "error",
66+
"no-undef-init": "error",
67+
"no-use-before-define": ["error", "nofunc"],
68+
69+
70+
// Stylistic Issues //
71+
//------------------//
72+
"comma-dangle": ["error", "never"],
73+
"quote-props": ["error", "as-needed", { "keywords": true, "unnecessary": false }],
74+
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
75+
"camelcase": "error",
76+
"comma-spacing": ["error", { "before": false, "after": true }],
77+
"comma-style": ["error", "last"],
78+
"consistent-this": ["warn", "self"],
79+
"eol-last": "error",
80+
"func-style": ["error", "declaration"],
81+
"key-spacing": ["error", {
82+
"beforeColon": false,
83+
"afterColon": true
84+
}],
85+
"new-cap": "error",
86+
"new-parens": "error",
87+
"no-array-constructor": "error",
88+
"no-lonely-if": "error",
89+
"no-mixed-spaces-and-tabs": "error",
90+
"no-nested-ternary": "warn",
91+
"no-new-object": "error",
92+
"no-spaced-func": "error",
93+
"no-trailing-spaces": "error",
94+
"no-extra-parens": ["error", "functions"],
95+
"quotes": ["error", "single", "avoid-escape"],
96+
"semi": "error",
97+
"semi-spacing": ["error", { "before": false, "after": true }],
98+
"keyword-spacing": "error",
99+
"space-before-blocks": ["error", "always"],
100+
"space-before-function-paren": ["error", { "anonymous": "never", "named": "never" }],
101+
"space-in-parens": ["error", "never"],
102+
"space-infix-ops": "error",
103+
"space-unary-ops": "error",
104+
"spaced-comment": ["error", "always", { "markers": [","] }],
105+
"wrap-regex": "warn",
106+
107+
// ECMAScript 6 //
108+
//--------------//
109+
"no-var": "off"
110+
},
111+
"parserOptions": {
112+
"sourceType": "module"
113+
}
114+
}

‎multi-nodejs-test/expected.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Author: Yehuda

‎multi-nodejs-test/run-handlebars.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This test should run with node 0.10 as long as Handlebars has been compiled before
2+
var Handlebars = require('../');
3+
var fs = require('fs');
4+
5+
console.log('Testing build Handlebars with Node version ' + process.version);
6+
var template = fs.readFileSync(require.resolve('./template.txt.hbs'), 'utf-8');
7+
var compiledOutput = Handlebars.compile(template)({author: 'Yehuda'}).trim();
8+
var expectedOutput = fs.readFileSync(require.resolve('./expected.txt'), 'utf-8').trim();
9+
10+
if (compiledOutput !== expectedOutput) {
11+
throw new Error('Compiled output (' + compiledOutput + ') did not match expected output (' + expectedOutput + ')');
12+
}
13+
console.log('Success');

‎multi-nodejs-test/run-tests.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
cd "$( dirname "$( readlink -f "$0" )" )"
4+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
5+
6+
# This script tests with precompiler and the built distribution with multiple NodeJS version.
7+
# The rest of the travis-build will only work with newer NodeJS versions, because the build
8+
# tools don't support older versions.
9+
# However, the built distribution should work with older NodeJS versions as well.
10+
# This test is simple by design. It merely ensures, that calling Handlebars does not fail with old versions.
11+
# It does (almost) not test for correctness, because that is already done in the mocha-tests.
12+
# And it does not use any NodeJS based testing framwork to make this part independent of the Node version.
13+
14+
# A list of NodeJS versions is expected as cli-args
15+
echo "Handlebars should be able to run in various versions of NodeJS"
16+
for i in "$@" ; do
17+
nvm install "$i"
18+
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
20+
echo Success
21+
done

‎multi-nodejs-test/template.txt.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Author: {{author}}

0 commit comments

Comments
 (0)
Please sign in to comment.