Skip to content

Commit

Permalink
Fix build on Windows
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
nknapp authored and mattolson committed Jun 29, 2019
1 parent de6ded4 commit 47adcda
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -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
Expand Down
38 changes: 38 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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}"
8 changes: 7 additions & 1 deletion spec/env/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ var fs = require('fs'),
vm = require('vm');

global.Handlebars = 'no-conflict';
vm.runInThisContext(fs.readFileSync(__dirname + '/../../dist/handlebars.js'), 'dist/handlebars.js');

var filename = 'dist/handlebars.js';
if (global.minimizedTest) {
filename = 'dist/handlebars.min.js';
}
var distHandlebars = fs.readFileSync(require.resolve(`../../${filename}`), 'utf-8');
vm.runInThisContext(distHandlebars, filename);

global.CompilerContext = {
browser: true,
Expand Down
2 changes: 1 addition & 1 deletion spec/env/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var files = [ testDir + '/basic.js' ];

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; });

run('./node', function() {
run('./browser', function() {
Expand Down
13 changes: 11 additions & 2 deletions tasks/test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
var childProcess = require('child_process'),
fs = require('fs');
fs = require('fs'),
os = require('os');

module.exports = function(grunt) {
grunt.registerTask('test:bin', function() {
var done = this.async();

childProcess.exec('./bin/handlebars -a spec/artifacts/empty.handlebars', function(err, stdout) {
var cmd = './bin/handlebars';
var args = [ '-a', 'spec/artifacts/empty.handlebars' ];

// On Windows, the executable handlebars.js file cannot be run directly
if (os.platform() === 'win32') {
args.unshift(cmd);
cmd = process.argv[0];
}
childProcess.execFile(cmd, args, function(err, stdout) {
if (err) {
throw err;
}
Expand Down

0 comments on commit 47adcda

Please sign in to comment.