-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
馃敤 fix: loadConfiguration - replace arrays instead of merging (#9)
* 馃敤 fix: loadConfiguration - replace arrays instead of merging * 馃摝 bumped package version
- Loading branch information
Showing
4 changed files
with
109 additions
and
3 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
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,9 @@ | ||
import { isArray } from 'lodash'; | ||
|
||
// Custom merge function that replaces arrays instead of merging them | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const customMerge = (objValue: any, srcValue: any): any => { | ||
if (isArray(objValue)) { | ||
return srcValue; | ||
} | ||
}; |
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,91 @@ | ||
import * as configModule from 'lilconfig'; | ||
|
||
import { createDefaultConfiguration } from './createDefaultConfiguration'; | ||
import { loadConfiguration } from './loadConfiguration'; | ||
|
||
jest.mock('lilconfig'); | ||
|
||
describe('loadConfiguration', () => { | ||
const mockLilconfig = configModule.lilconfig as jest.MockedFunction< | ||
typeof configModule.lilconfig | ||
>; | ||
|
||
const mockSearch = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
mockLilconfig.mockReturnValue({ search: mockSearch } as any); | ||
}); | ||
|
||
it('returns default configuration if no config found', async () => { | ||
mockSearch.mockResolvedValue(null); | ||
|
||
const defaultConfiguration = createDefaultConfiguration({}); | ||
|
||
const result = await loadConfiguration(); | ||
|
||
expect(result).toEqual(defaultConfiguration); | ||
}); | ||
|
||
it('returns default configuration if found config is empty', async () => { | ||
mockSearch.mockResolvedValue({ config: {} }); | ||
|
||
const defaultConfiguration = createDefaultConfiguration({}); | ||
|
||
const result = await loadConfiguration(); | ||
|
||
expect(result).toEqual(defaultConfiguration); | ||
}); | ||
|
||
it('returns merged configuration if found config has values', async () => { | ||
const customConfig = { | ||
jiraIssuePrefix: 'CUSTOM', | ||
branchConfiguration: { branchTypes: ['custom'] }, | ||
messageConfiguration: { capitalizeMessage: false }, | ||
}; | ||
|
||
mockSearch.mockResolvedValue({ config: customConfig }); | ||
|
||
const result = await loadConfiguration(); | ||
|
||
expect(result.jiraIssuePrefix).toEqual('CUSTOM'); | ||
|
||
expect(result.branchConfiguration.branchTypes).toEqual(['custom']); | ||
|
||
expect(result.messageConfiguration.capitalizeMessage).toEqual(false); | ||
}); | ||
|
||
it('handles conditional defaults when specific config properties are provided', async () => { | ||
const customConfig = { | ||
jiraIssuePrefix: 'FOO', | ||
jiraTicketExample: 'FOO-1234', | ||
}; | ||
|
||
mockSearch.mockResolvedValue({ config: customConfig }); | ||
|
||
const result = await loadConfiguration(); | ||
|
||
expect(result.jiraIssuePrefix).toEqual('FOO'); | ||
|
||
expect(result.jiraTicketExample).toEqual('FOO-1234'); | ||
}); | ||
|
||
it('handles conditional defaults when no specific config properties are provided', async () => { | ||
const customConfig = {}; | ||
|
||
mockSearch.mockResolvedValue({ config: customConfig }); | ||
|
||
const defaultConfiguration = createDefaultConfiguration({}); | ||
|
||
const result = await loadConfiguration(); | ||
|
||
expect(result.jiraIssuePrefix).toEqual( | ||
defaultConfiguration.jiraIssuePrefix, | ||
); | ||
|
||
expect(result.jiraTicketExample).toEqual( | ||
defaultConfiguration.jiraTicketExample, | ||
); | ||
}); | ||
}); |
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