Skip to content

Commit 8c6ef59

Browse files
committed
Adds tests for passing environment variables to spawned processes correctly
1 parent 90a7bc5 commit 8c6ef59

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

test/fixtures/echoEnv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "$FOO" "$BAR"

test/fixtures/echoEnv.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo %FOO% %BAR%

test/test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,40 @@ extension\');', { mode: parseInt('0777', 8) });
150150
});
151151
});
152152

153+
describe('should preserve environment variables', function () {
154+
before(function () {
155+
process.env.FOO = 'foovalue';
156+
});
157+
158+
it('when env dictionary is omitted', function (next) {
159+
buffered(method, __dirname + '/fixtures/echoEnv', function (err, data, code) {
160+
expect(err).to.not.be.ok();
161+
expect(code).to.be(0);
162+
expect(data.trim()).to.equal('foovalue');
163+
164+
next();
165+
});
166+
});
167+
168+
it('when env dictionary is passed', function (next) {
169+
buffered(method, __dirname + '/fixtures/echoEnv', {
170+
env: {
171+
BAR: 'barvalue',
172+
},
173+
}, function (err, data, code) {
174+
expect(err).to.not.be.ok();
175+
expect(code).to.be(0);
176+
expect(data.trim()).to.equal('barvalue');
177+
178+
next();
179+
});
180+
});
181+
182+
after(function () {
183+
delete process.env.FOO;
184+
});
185+
});
186+
153187
it('should handle arguments with quotes', function (next) {
154188
buffered(method, 'node', [
155189
__dirname + '/fixtures/echo',

0 commit comments

Comments
 (0)