Skip to content

Commit

Permalink
Add inserted
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Mar 31, 2017
1 parent 825c1b2 commit 6fe8147
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ function config (options) {
try {
// specifying an encoding returns a string instead of a buffer
var parsedObj = parse(fs.readFileSync(path, { encoding: encoding }))
var insertedObj = {}

Object.keys(parsedObj).forEach(function (key) {
process.env[key] = process.env[key] || parsedObj[key]
var value = process.env[key] || parsedObj[key]

insertedObj[key] = value
process.env[key] = value
})

return { parsed: parsedObj }
return { parsed: parsedObj, inserted: insertedObj }
} catch (e) {
return { error: e }
}
Expand Down
8 changes: 8 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ describe('dotenv', function () {
done()
})

it('returns inserted object', function (done) {
var env = dotenv.config()

env.should.not.have.property('error')
env.inserted.should.eql({ test: 'val' })
done()
})

it('returns any errors thrown from reading file or parsing', function (done) {
readFileSyncStub.throws()

Expand Down

0 comments on commit 6fe8147

Please sign in to comment.