Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid setting undefined options #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module.exports = function(grunt) {
globalOption: 'foo'
},
testData: {
UNDEFINED_OPTION: function() {
// logic here might return undefined or not, but for testing we do
return undefined;
},
TEST: 'test',
data: 'bar'
},
Expand Down Expand Up @@ -97,6 +101,12 @@ module.exports = function(grunt) {
assert.equal(process.env.data, 'bar', 'data should be set');
delete process.env.globalOption;
delete process.env.data;

assert.equal(
process.env.hasOwnProperty('UNDEFINED_OPTION'),
false,
'UNDEFINED_OPTION should not be set on process.env'
);
});

grunt.registerTask('testOptions', function() {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~1.2.0",
Copy link
Author

@evanshortiss evanshortiss Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm test only works if grunt-cli is a global install. This fixes that.

"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-jshint": "~0.11.0",
"grunt-jscs": "^1.5.0"
Expand All @@ -42,4 +43,4 @@
"ini": "~1.3.0",
"lodash": "~2.4.1"
}
}
}
5 changes: 4 additions & 1 deletion tasks/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ module.exports = function(grunt) {
} else {
var data = {};
data[option] = typeof optionData === 'function' ? optionData() : optionData;
_.extend(process.env, data);

if (data[option] !== undefined) {
_.extend(process.env, data);
}
}
});
}
Expand Down