Skip to content

Commit

Permalink
fix: Updated default config to accept undefined as default value (n…
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlanabrennan authored Jan 31, 2025
1 parent 4be1099 commit e049442
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ Config.prototype._fromPassed = function _fromPassed(external, internal, arbitrar

Object.keys(external).forEach(function overwrite(key) {
// if it's not in the defaults, it doesn't exist
if (!arbitrary && internal[key] === undefined) {
if (!arbitrary && !(key in internal)) {
return
}

Expand Down
33 changes: 33 additions & 0 deletions test/unit/config/config-defaults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const assert = require('node:assert')
const path = require('path')

const Config = require('../../../lib/config')
const proxyquire = require('proxyquire')

test('with default properties', async (t) => {
let configuration = null
Expand Down Expand Up @@ -316,3 +317,35 @@ test('with default properties', async (t) => {
assert.equal(configuration.instrumentation.npmlog.enabled, true)
})
})

test('with undefined as default', async (t) => {
const mockConfig = {
fake_key: {
another_layer: {
fake_nested_key: {
default: undefined
}
}
}
}

const defaults = require('../../../lib/config/default')
const orig = defaults.definition
defaults.definition = function stub() {
const configDefaults = orig.apply(this, arguments)
return { ...configDefaults, ...mockConfig }
}
const Config = proxyquire('../../../lib/config', {
'./default': defaults
})

const configuration = Config.initialize({
fake_key: {
another_layer: {
fake_nested_key: 'fake-value'
}
}
})

assert.equal(configuration.fake_key.another_layer.fake_nested_key, 'fake-value')
})

0 comments on commit e049442

Please sign in to comment.