Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid overwriting the default values of options with undefined (#…
…1018) * fix(conventional-changelog-core): avoid overwriting the default values of options with undefined * test(conventional-changelog-core): add tests for merge-config * refactor(conventional-changelog-core): optimize omitUndefinedValueProps to one loop
- Loading branch information
1 parent
11195f2
commit 71b0c40
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
61 changes: 61 additions & 0 deletions
61
packages/conventional-changelog-core/test/merge-config.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict' | ||
const mergeConfig = require('../lib/merge-config') | ||
const expect = require('chai').expect | ||
const describe = require('mocha').describe | ||
|
||
const defaultOptions = { | ||
append: false, | ||
releaseCount: 1, | ||
skipUnstable: false, | ||
lernaPackage: null, | ||
outputUnreleased: true | ||
} | ||
|
||
describe('merge-config', function () { | ||
it('should return passed options', async function () { | ||
const options = { | ||
append: true, | ||
releaseCount: 0, | ||
skipUnstable: true, | ||
debug: function () {}, | ||
warn: function () {}, | ||
transform: function () {}, | ||
lernaPackage: 'foo', | ||
tagPrefix: 'bar', | ||
outputUnreleased: true, | ||
pkg: { | ||
path: 'baz', | ||
transform: function () {} | ||
} | ||
} | ||
const config = await mergeConfig(options) | ||
expect(config.options).to.deep.include(options) | ||
}) | ||
|
||
it('should return default options if empty options is passed', async function () { | ||
const { options } = await mergeConfig({}) | ||
expect(options).to.include(defaultOptions) | ||
}) | ||
|
||
it('should return default options when no options is passed', async function () { | ||
const { options } = await mergeConfig() | ||
expect(options).to.include(defaultOptions) | ||
}) | ||
|
||
it('should return default options when null is passed', async function () { | ||
const { options } = await mergeConfig(null) | ||
expect(options).to.include(defaultOptions) | ||
}) | ||
|
||
it('should return default options when undefined value is passed', async function () { | ||
const options = { | ||
append: undefined, | ||
releaseCount: undefined, | ||
skipUnstable: undefined, | ||
lernaPackage: undefined, | ||
outputUnreleased: undefined | ||
} | ||
const config = await mergeConfig(options) | ||
expect(config.options).to.include(defaultOptions) | ||
}) | ||
}) |