From 468fae6e98e2314d4bfaa19f1b614718144d4692 Mon Sep 17 00:00:00 2001 From: vdemedes Date: Sat, 24 Oct 2015 17:03:42 +0200 Subject: [PATCH] set process.cwd() to a test's directory --- lib/fork.js | 8 +++++++- test/fixture/process-cwd.js | 1 + test/test.js | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/fixture/process-cwd.js diff --git a/lib/fork.js b/lib/fork.js index fa7b7738b..89065bf53 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -2,6 +2,7 @@ var childProcess = require('child_process'); var Promise = require('bluebird'); +var dirname = require('path').dirname; var join = require('path').join; module.exports = fork; @@ -14,7 +15,12 @@ function fork(args) { var babel = join(__dirname, 'babel.js'); var file = args[0]; - var ps = childProcess.fork(babel, args, {silent: true}); + var options = { + silent: true, + cwd: dirname(file) + }; + + var ps = childProcess.fork(babel, args, options); var promise = new Promise(function (resolve, reject) { ps.on('results', function (results) { diff --git a/test/fixture/process-cwd.js b/test/fixture/process-cwd.js new file mode 100644 index 000000000..fcf23bcd9 --- /dev/null +++ b/test/fixture/process-cwd.js @@ -0,0 +1 @@ +console.log(process.cwd()); diff --git a/test/test.js b/test/test.js index 51ce50bc8..01b75ff6e 100644 --- a/test/test.js +++ b/test/test.js @@ -3,6 +3,7 @@ var childProcess = require('child_process'); var Promise = require('bluebird'); var figures = require('figures'); var test = require('tape'); +var join = require('path').join; var Runner = require('../lib/runner'); var ava = require('../lib/test'); @@ -850,3 +851,11 @@ test('power-assert support', function (t) { t.true((/t\.ok\(a === 'bar'\)\s*\n\s+\|\s*\n\s+"foo"/m).test(stderr)); }); }); + +test('change process.cwd() to a test\'s directory', function (t) { + execCli('fixture/process-cwd.js', function (err, stdout) { + t.ifError(err); + t.is(stdout.trim(), join(__dirname, 'fixture')); + t.end(); + }); +});