Skip to content

Commit

Permalink
set process.cwd() to a test's directory
Browse files Browse the repository at this point in the history
  • Loading branch information
vdemedes committed Oct 24, 2015
1 parent 4a0aa8c commit 468fae6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/fixture/process-cwd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(process.cwd());
9 changes: 9 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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();
});
});

0 comments on commit 468fae6

Please sign in to comment.