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

fix: Updated default config to accept undefined as default value #2917

Merged
Merged
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
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')
})
Loading