Check of object hasOwnProp method

This commit is contained in:
Remy Sharp
2015-01-18 10:48:18 +00:00
parent 2367a26fdd
commit 1bb7c01fb6
2 changed files with 42 additions and 45 deletions

View File

@@ -29,7 +29,7 @@ function clone(obj) {
if (obj instanceof Object) {
copy = {};
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) {
if (obj.hasOwnProperty && obj.hasOwnProperty(attr)) {
copy[attr] = clone(obj[attr]);
}
}

View File

@@ -8,8 +8,7 @@ var cli = require('../../lib/cli/'),
nodemon = require('../../lib/nodemon'),
command = require('../../lib/config/command'),
appjs = path.resolve(__dirname, '..', 'fixtures', 'env.js'),
assert = require('assert'),
nodeMajor = parseInt((process.versions.node.split('.') || [null,null])[1] || 0, 10);
assert = require('assert');
function asCLI(cmd) {
return ('node nodemon ' + (cmd|| '')).trim();
@@ -25,54 +24,52 @@ function commandToString(command) {
return command.executable + (command.args.length ? ' ' + command.args.join(' ') : '');
}
if (nodeMajor > 8) {
describe('nodemon API events', function () {
var pwd = process.cwd(),
oldhome = utils.home;
describe('nodemon API events', function () {
var pwd = process.cwd(),
oldhome = utils.home;
afterEach(function () {
process.chdir(pwd);
utils.home = oldhome;
});
afterEach(function () {
process.chdir(pwd);
utils.home = oldhome;
});
after(function (done) {
// clean up just in case.
nodemon.reset(done);
});
after(function (done) {
// clean up just in case.
nodemon.reset(done);
});
beforeEach(function (done) {
// move to the fixtures directory to allow for config loading
process.chdir(path.resolve(pwd, 'test/fixtures'));
utils.home = path.resolve(pwd, ['test', 'fixtures', 'events'].join(path.sep));
beforeEach(function (done) {
// move to the fixtures directory to allow for config loading
process.chdir(path.resolve(pwd, 'test/fixtures'));
utils.home = path.resolve(pwd, ['test', 'fixtures', 'events'].join(path.sep));
nodemon.reset(done);
});
nodemon.reset(done);
});
it('should trigger start event script', function (done) {
var plan = new testUtils.Plan(4, done);
nodemon({
script: appjs,
verbose: true,
stdout: false,
env: { USER: 'nodemon' },
}).on('start', function () {
plan.assert(true, 'started');
}).on('exit', function () {
plan.assert(true, 'exit');
}).on('stdout', function (data) {
data = data.toString().trim();
it('should trigger start event script', function (done) {
var plan = new testUtils.Plan(4, done);
nodemon({
script: appjs,
verbose: true,
stdout: false,
env: { USER: 'nodemon' },
}).on('start', function () {
plan.assert(true, 'started');
}).on('exit', function () {
plan.assert(true, 'exit');
}).on('stdout', function (data) {
data = data.toString().trim();
if (data === 'OK') {
plan.assert(true, 'OK found');
} else if (data === 'STOPPED') {
plan.assert(true, 'STOPPED found');
} else if (data === 'nodemon') {
// expected output
} else {
plan.assert(false, data + ' found')
}
if (data === 'OK') {
plan.assert(true, 'OK found');
} else if (data === 'STOPPED') {
plan.assert(true, 'STOPPED found');
} else if (data === 'nodemon') {
// expected output
} else {
plan.assert(false, data + ' found')
}
});
});
});
}
});