Skip to content

Commit 6e33a6d

Browse files
committed
tests: update to NOT user USER as this won't overwrite local env
1 parent d7cfe08 commit 6e33a6d

File tree

6 files changed

+193
-184
lines changed

6 files changed

+193
-184
lines changed

test/config/env.test.js

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
'use strict';
22
/*global describe:true, it: true, after: true */
33
var nodemon = require('../../lib/'),
4-
path = require('path'),
5-
assert = require('assert');
4+
path = require('path'),
5+
assert = require('assert');
66

77
describe('when nodemon runs (1)', function () {
88
var tmp = path.resolve('test/fixtures/env.js');
99
after(function (done) {
1010
// clean up just in case.
11-
nodemon.once('exit', function () {
12-
nodemon.reset(done);
13-
}).emit('quit');
11+
nodemon
12+
.once('exit', function () {
13+
nodemon.reset(done);
14+
})
15+
.emit('quit');
1416
});
1517

1618
it('should pass through environment values', function (done) {
17-
nodemon({ script: tmp, stdout: false, env: { USER: 'nodemon' } }).on('stdout', function (data) {
18-
assert(data.toString().trim() === 'nodemon', 'USER env value correctly set to "nodemon": ' + data.toString());
19-
nodemon.once('exit', function () {
20-
nodemon.reset(done);
21-
}).emit('quit');
22-
});
19+
nodemon({ script: tmp, stdout: false, env: { NODEMON_ENV: 'nodemon' } }).on(
20+
'stdout',
21+
function (data) {
22+
assert(
23+
data.toString().trim() === 'nodemon',
24+
'NODEMON_ENV env value correctly set to "nodemon": ' + data.toString()
25+
);
26+
nodemon
27+
.once('exit', function () {
28+
nodemon.reset(done);
29+
})
30+
.emit('quit');
31+
}
32+
);
2333
});
2434
});

test/events/complete.test.js

+73-64
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,72 @@ var appjs = path.resolve(dir, 'env.js');
1111
var asCLI = utils.asCLI;
1212
var fork = require('child_process').fork;
1313

14-
describe('events should follow normal flow on user triggered change',
15-
function () {
16-
function conf() {
17-
utils.port++;
18-
return {
19-
script: appjs,
20-
verbose: true,
21-
stdout: false,
22-
noReset: true,
23-
ext: 'js',
24-
env: {
25-
PORT: utils.port,
26-
USER: 'nodemon',
27-
},
28-
};
29-
}
14+
describe('events should follow normal flow on user triggered change', function () {
15+
function conf() {
16+
utils.port++;
17+
return {
18+
script: appjs,
19+
verbose: true,
20+
stdout: false,
21+
noReset: true,
22+
ext: 'js',
23+
env: {
24+
PORT: utils.port,
25+
NODEMON_ENV: 'nodemon',
26+
},
27+
};
28+
}
3029

31-
var cwd = process.cwd();
30+
var cwd = process.cwd();
3231

33-
beforeEach(function (done) {
34-
debug('beforeEach');
35-
nodemon.once('exit', function () {
32+
beforeEach(function (done) {
33+
debug('beforeEach');
34+
nodemon
35+
.once('exit', function () {
3636
nodemon.reset(done);
37-
}).emit('quit');
38-
});
37+
})
38+
.emit('quit');
39+
});
3940

40-
before(function () {
41-
process.chdir(dir);
42-
});
41+
before(function () {
42+
process.chdir(dir);
43+
});
4344

44-
after(function (done) {
45-
debug('after');
46-
process.chdir(cwd);
47-
nodemon.once('exit', function () {
45+
after(function (done) {
46+
debug('after');
47+
process.chdir(cwd);
48+
nodemon
49+
.once('exit', function () {
4850
nodemon.reset(function () {
4951
setTimeout(done, 1000);
5052
});
51-
}).emit('quit');
52-
});
53+
})
54+
.emit('quit');
55+
});
5356

54-
it('start', function (done) {
55-
debug('start');
56-
nodemon(conf()).once('start', function () {
57-
assert(true, '"start" event');
58-
done();
59-
});
57+
it('start', function (done) {
58+
debug('start');
59+
nodemon(conf()).once('start', function () {
60+
assert(true, '"start" event');
61+
done();
6062
});
63+
});
6164

62-
it('config:update', function (done) {
63-
nodemon(conf()).on('config:update', function () {
64-
assert(true, '"config:update" event');
65-
done();
66-
});
65+
it('config:update', function (done) {
66+
nodemon(conf()).on('config:update', function () {
67+
assert(true, '"config:update" event');
68+
done();
6769
});
70+
});
6871

69-
it('exit', function (done) {
70-
var plan = new utils.Plan(4, function () {
71-
nodemon.reset(done);
72-
});
73-
var run = 0;
72+
it('exit', function (done) {
73+
var plan = new utils.Plan(4, function () {
74+
nodemon.reset(done);
75+
});
76+
var run = 0;
7477

75-
nodemon(conf()).on('exit', function () {
78+
nodemon(conf())
79+
.on('exit', function () {
7680
plan.assert(true, '"exit" event');
7781
if (run === 1) {
7882
setTimeout(function () {
@@ -84,33 +88,38 @@ describe('events should follow normal flow on user triggered change',
8488
} else {
8589
plan.assert(false, 'quit too many times: ' + run);
8690
}
87-
}).on('start', function () {
91+
})
92+
.on('start', function () {
8893
run++;
8994
});
90-
});
95+
});
9196

92-
it('stdout', function (done) {
93-
nodemon(conf()).once('stdout', function (data) {
94-
assert(true, '"stdout" event with: ' + data);
95-
done();
96-
});
97+
it('stdout', function (done) {
98+
nodemon(conf()).once('stdout', function (data) {
99+
assert(true, '"stdout" event with: ' + data);
100+
done();
97101
});
102+
});
98103

99-
it('restart', function (done) {
100-
var plan = new utils.Plan(4, function () {
101-
nodemon.reset(done);
102-
});
104+
it('restart', function (done) {
105+
var plan = new utils.Plan(4, function () {
106+
nodemon.reset(done);
107+
});
103108

104-
nodemon(conf()).on('restart', function (files) {
109+
nodemon(conf())
110+
.on('restart', function (files) {
105111
plan.assert(true, '"restart" event with ' + files);
106-
plan.assert(files[0] === appjs, 'restart due to ' + files.join(' ') +
107-
' changing');
108-
}).once('exit', function () {
112+
plan.assert(
113+
files[0] === appjs,
114+
'restart due to ' + files.join(' ') + ' changing'
115+
);
116+
})
117+
.once('exit', function () {
109118
plan.assert(true, '"exit" event');
110119
setTimeout(function () {
111120
plan.assert(true, 'restarting');
112121
touch.sync(appjs);
113122
}, 1500);
114123
});
115-
});
116124
});
125+
});

test/events/scripts.test.js

+35-30
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use strict';
22
/*global describe:true, it: true, afterEach: true, beforeEach: true, after:true */
33
var cli = require('../../lib/cli/'),
4-
path = require('path'),
5-
testUtils = require('../utils'),
6-
utils = require('../../lib/utils'),
7-
exec = require('../../lib/config/exec'),
8-
nodemon = require('../../lib/nodemon'),
9-
command = require('../../lib/config/command'),
10-
appjs = path.resolve(__dirname, '..', 'fixtures', 'env.js'),
11-
assert = require('assert');
4+
path = require('path'),
5+
testUtils = require('../utils'),
6+
utils = require('../../lib/utils'),
7+
exec = require('../../lib/config/exec'),
8+
nodemon = require('../../lib/nodemon'),
9+
command = require('../../lib/config/command'),
10+
appjs = path.resolve(__dirname, '..', 'fixtures', 'env.js'),
11+
assert = require('assert');
1212

1313
function asCLI(cmd) {
14-
return ('node nodemon ' + (cmd|| '')).trim();
14+
return ('node nodemon ' + (cmd || '')).trim();
1515
}
1616

1717
function parse(cmd) {
@@ -26,7 +26,7 @@ function commandToString(command) {
2626

2727
describe('nodemon API events', function () {
2828
var pwd = process.cwd(),
29-
oldhome = utils.home;
29+
oldhome = utils.home;
3030

3131
afterEach(function () {
3232
process.chdir(pwd);
@@ -41,7 +41,10 @@ describe('nodemon API events', function () {
4141
beforeEach(function (done) {
4242
// move to the fixtures directory to allow for config loading
4343
process.chdir(path.resolve(pwd, 'test/fixtures'));
44-
utils.home = path.resolve(pwd, ['test', 'fixtures', 'events'].join(path.sep));
44+
utils.home = path.resolve(
45+
pwd,
46+
['test', 'fixtures', 'events'].join(path.sep)
47+
);
4548

4649
nodemon.reset(done);
4750
});
@@ -52,23 +55,25 @@ describe('nodemon API events', function () {
5255
script: appjs,
5356
verbose: true,
5457
stdout: false,
55-
env: { USER: 'nodemon' },
56-
}).on('start', function () {
57-
plan.assert(true, 'started');
58-
}).on('exit', function () {
59-
plan.assert(true, 'exit');
60-
}).on('stdout', function (data) {
61-
data = data.toString().trim();
62-
if (data === 'OK') {
63-
plan.assert(true, 'OK found');
64-
} else if (data === 'STOPPED') {
65-
plan.assert(true, 'STOPPED found');
66-
} else if (data === 'nodemon') {
67-
// expected output
68-
} else {
69-
plan.assert(false, data + ' found');
70-
}
71-
72-
});
58+
env: { NODEMON_ENV: 'nodemon' },
59+
})
60+
.on('start', function () {
61+
plan.assert(true, 'started');
62+
})
63+
.on('exit', function () {
64+
plan.assert(true, 'exit');
65+
})
66+
.on('stdout', function (data) {
67+
data = data.toString().trim();
68+
if (data === 'OK') {
69+
plan.assert(true, 'OK found');
70+
} else if (data === 'STOPPED') {
71+
plan.assert(true, 'STOPPED found');
72+
} else if (data === 'nodemon') {
73+
// expected output
74+
} else {
75+
plan.assert(false, data + ' found');
76+
}
77+
});
7378
});
74-
});
79+
});

test/fixtures/env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log(process.env.USER);
1+
console.log(process.env.NODEMON_ENV);

0 commit comments

Comments
 (0)