Skip to content

Commit e049442

Browse files
fix: Updated default config to accept undefined as default value (#2917)
1 parent 4be1099 commit e049442

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/config/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ Config.prototype._fromPassed = function _fromPassed(external, internal, arbitrar
10421042

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

test/unit/config/config-defaults.test.js

+33
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const assert = require('node:assert')
1010
const path = require('path')
1111

1212
const Config = require('../../../lib/config')
13+
const proxyquire = require('proxyquire')
1314

1415
test('with default properties', async (t) => {
1516
let configuration = null
@@ -316,3 +317,35 @@ test('with default properties', async (t) => {
316317
assert.equal(configuration.instrumentation.npmlog.enabled, true)
317318
})
318319
})
320+
321+
test('with undefined as default', async (t) => {
322+
const mockConfig = {
323+
fake_key: {
324+
another_layer: {
325+
fake_nested_key: {
326+
default: undefined
327+
}
328+
}
329+
}
330+
}
331+
332+
const defaults = require('../../../lib/config/default')
333+
const orig = defaults.definition
334+
defaults.definition = function stub() {
335+
const configDefaults = orig.apply(this, arguments)
336+
return { ...configDefaults, ...mockConfig }
337+
}
338+
const Config = proxyquire('../../../lib/config', {
339+
'./default': defaults
340+
})
341+
342+
const configuration = Config.initialize({
343+
fake_key: {
344+
another_layer: {
345+
fake_nested_key: 'fake-value'
346+
}
347+
}
348+
})
349+
350+
assert.equal(configuration.fake_key.another_layer.fake_nested_key, 'fake-value')
351+
})

0 commit comments

Comments
 (0)