Skip to content

Commit

Permalink
Fix test for windows. Add https://ci.appveyor.com as windows CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Zarouski committed Dec 4, 2016
1 parent 1e32718 commit 67e0340
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 15 deletions.
23 changes: 23 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Test against this version of Node.js
environment:
matrix:
- nodejs_version: "Stable"
- nodejs_version: "LTS"

# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node.js or io.js
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- npm test

# Don't actually build.
build: off
17 changes: 6 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,7 @@ function bump(manifest, type, options) {
*/
function runNpmScriptIfExists(pkgScripts, script) {
if (pkgScripts && pkgScripts[script]) {
try {
exec('npm', ['run', script], {skipCustomErrorLog: true});
} catch (ex) {
//windows fallback, until https://github.com/libuv/libuv/pull/358 is fixed
if (ex.code === 'ENOENT') {
exec('npm.cmd', ['run', script]);
} else {
throw ex;
}
}
exec('npm', ['run', script]);
}
}

Expand Down Expand Up @@ -206,7 +197,11 @@ function exec(command, args, opts) {
opts = opts || {};
var skipCustomErrorLog = opts.skipCustomErrorLog;
delete opts.skipCustomErrorLog;
var result = spawnSync(command, args, opts);
//use which to make sure that node spawn can find correct executable, at the moment this is used as
//a windows fallback, until https://github.com/libuv/libuv/pull/358 is fixed
var which = require('npm-which')(process.cwd());
var pathToCommand = which.sync(command);
var result = spawnSync(pathToCommand, args, opts);
if (result.status || result.error) {
if (!skipCustomErrorLog) {
console.error(
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"scripts": {
"lint": "jshint . --verbose && jscs . --verbose",
"build": "npm run lint",
"test": "mocha --bail --recursive tests/fixtures tests/specs",
"test": "mocha --bail --recursive --timeout 3000 tests/fixtures tests/specs",
"upgrade": "npm-check -u",
"bump": "node bin/bump.js --prompt --tag --push --all",
"release": "npm run upgrade && npm run build && npm test && npm run bump && npm publish",
Expand All @@ -42,6 +42,7 @@
"lodash": "^4.16.4",
"mocha": "^3.1.1",
"npm-check": "^5.4.0",
"npm-which": "^3.0.1",
"sinon": "^1.17.6"
},
"dependencies": {
Expand All @@ -62,4 +63,4 @@
"bin": {
"bump": "bin/bump.js"
}
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/.tmp/git.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\bin\git" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\bin\git" %*
)
7 changes: 7 additions & 0 deletions tests/fixtures/bin/git.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\git" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\git" %*
)
16 changes: 14 additions & 2 deletions tests/fixtures/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ beforeEach(function() {
fs.mkdirSync(tmpPath)
}
else {
// Make sure the .tmp directory is empty
// Make sure the .tmp directory is empty, except for git.cmd,
// which is a hack to make appveyor build work (has some issues with PATH modification)
fs.readdirSync(tmpPath).forEach(function(file) {
if (file === 'git.cmd') {
return;
}
fs.unlinkSync(path.join(tmpPath, file));
});
}
Expand Down Expand Up @@ -58,7 +62,15 @@ function bump(args, initialJSON, finalJSON) {
// Modify the PATH environment variable so bump will execute our fake `git`
var binPath = path.join(__dirname, 'bin');
fs.chmodSync(path.join(binPath, 'git'), '0777');
var env = _.clone(process.env);
var env = _.reduce(process.env, function (memo, value, key) {
//in windows, environment variables are case insensitive and can be defined as Path, path, ...
//since in code below we're relying on PATH to be uppercase, make sure it is cloned as uppercase
if (/^path$/i.test(key)) {
memo.PATH = value;
}
memo[key] = value;
return memo;
}, {});
env.PATH = binPath + path.delimiter + env.PATH;

// Run bump
Expand Down

0 comments on commit 67e0340

Please sign in to comment.