From ecaa903ff4e52bc1dda4eddaefb253e607113979 Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Sun, 14 May 2017 23:11:43 +0200 Subject: [PATCH] Fix build on Windows Closes #1233 - Handle path-separators properly. Use "path.sep" instead of "/". Or use "require.resolve()" if possible - Use "execFile" instead of "exec" to run the Handlebars executable. This prevents problems due to (missing) shell escaping. - Use explicit call to "node" in order to run the executable on Windows. - Add "appveyor"-CI in order to run regular tests on Windows. --- README.markdown | 1 + appveyor.yml | 38 ++++++++++++++++++++++++++++++++++++++ spec/env/browser.js | 3 ++- spec/env/runner.js | 2 +- tasks/test.js | 10 ++++++++-- 5 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 appveyor.yml diff --git a/README.markdown b/README.markdown index 89e3fc59a..434a0e3a6 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,5 @@ [![Travis Build Status](https://img.shields.io/travis/wycats/handlebars.js/master.svg)](https://travis-ci.org/wycats/handlebars.js) +[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/wycats/handlebars.js?branch=master&svg=true)](https://ci.appveyor.com/project/wycats/handlebars-js) [![Selenium Test Status](https://saucelabs.com/buildstatus/handlebars)](https://saucelabs.com/u/handlebars) Handlebars.js diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..b67fb4ca5 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,38 @@ +# Test against these versions of Node.js +environment: + matrix: + - nodejs_version: "4" + - nodejs_version: "5" + +platform: + - x64 + +# Install scripts (runs after repo cloning) +install: + # Get the latest stable version of Node.js + - ps: Install-Product node $env:nodejs_version $env:platform + # Clone submodules (mustache spec) + - cmd: git submodule update --init --recursive + # Install modules + - cmd: npm install + - cmd: npm install -g grunt-cli + + +# Post-install test scripts +test_script: + # Output useful info for debugging + - cmd: node --version + - cmd: npm --version + # Run tests + - cmd: grunt --stack travis + +# Don't actually build +build: off + +on_failure: + - cmd: 7z a coverage.zip coverage + - cmd: appveyor PushArtifact coverage.zip + + +# Set build version format here instead of in the admin panel +version: "{build}" \ No newline at end of file diff --git a/spec/env/browser.js b/spec/env/browser.js index 60a5d3547..8b89207e9 100644 --- a/spec/env/browser.js +++ b/spec/env/browser.js @@ -9,7 +9,8 @@ var filename = 'dist/handlebars.js'; if (global.minimizedTest) { filename = 'dist/handlebars.min.js'; } -vm.runInThisContext(fs.readFileSync(__dirname + '/../../' + filename), filename); +var distHandlebars = fs.readFileSync(require.resolve(`../../${filename}`), 'utf-8'); +vm.runInThisContext(distHandlebars, filename); global.CompilerContext = { browser: true, diff --git a/spec/env/runner.js b/spec/env/runner.js index f4b23d825..a069c2d71 100644 --- a/spec/env/runner.js +++ b/spec/env/runner.js @@ -15,7 +15,7 @@ if (grep === '--min') { var files = fs.readdirSync(testDir) .filter(function(name) { return (/.*\.js$/).test(name); }) - .map(function(name) { return testDir + '/' + name; }); + .map(function(name) { return testDir + path.sep + name; }); if (global.minimizedTest) { run('./runtime', function() { diff --git a/tasks/test.js b/tasks/test.js index 342a28362..6bee3920a 100644 --- a/tasks/test.js +++ b/tasks/test.js @@ -6,9 +6,15 @@ module.exports = function(grunt) { grunt.registerTask('test:bin', function() { var done = this.async(); + var cmd = './bin/handlebars'; + var args = [ '-a', 'spec/artifacts/empty.handlebars' ]; + // On Windows, the executable handlebars.js file cannot be run directly - var prefix = os.type().match(/^Windows/) ? process.argv[0] : ''; - childProcess.exec(prefix + ' ./bin/handlebars -a spec/artifacts/empty.handlebars', function(err, stdout) { + if (os.platform() === 'win32') { + args.unshift(cmd); + cmd = process.argv[0]; + } + childProcess.execFile(cmd, args, function(err, stdout) { if (err) { throw err; }