-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix poor merge behavior of
Config
+ overrides (#1519)
- Loading branch information
1 parent
db02249
commit 1a469d7
Showing
3 changed files
with
189 additions
and
9 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
__snapshots__/packages/core/test-out/service/Config.spec.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,56 @@ | ||
import assert from 'assert' | ||
import { describe, it } from 'mocha' | ||
import snapshot from 'snap-shot-it' | ||
import type { Config } from '../../lib/index.js' | ||
import { ConfigService } from '../../lib/index.js' | ||
|
||
describe('ConfigService', () => { | ||
describe('merge()', () => { | ||
const base = { | ||
env: { | ||
dataSource: 'GitHub', | ||
dependencies: [ | ||
'@vanilla-mcdoc', | ||
], | ||
feature: { | ||
a: true, | ||
b: false, | ||
}, | ||
}, | ||
} as unknown as Config | ||
|
||
it('Should create a clone of the base object', async () => { | ||
const merged = ConfigService.merge(base) | ||
merged.env.dataSource = 'new string' | ||
assert.notEqual(base.env.dataSource, merged.env.dataSource) | ||
}) | ||
|
||
it('Should merge empty overrides correctly', async () => { | ||
snapshot(ConfigService.merge(base)) | ||
snapshot(ConfigService.merge(base, {})) | ||
snapshot(ConfigService.merge(base, {}, {})) | ||
}) | ||
|
||
it('Should merge top-level overrides correctly', async () => { | ||
snapshot(ConfigService.merge(base, { test: true })) | ||
}) | ||
|
||
it('Should merge nested overrides correctly', async () => { | ||
snapshot(ConfigService.merge(base, { env: { dataSource: 'TEST' } })) | ||
snapshot(ConfigService.merge(base, { env: { feature: {} } })) | ||
snapshot(ConfigService.merge(base, { env: { feature: { b: true } } })) | ||
snapshot(ConfigService.merge(base, { env: { feature: { b: true, c: 9 } } })) | ||
snapshot(ConfigService.merge(base, { env: { dependencies: [] } })) | ||
}) | ||
|
||
it('Should merge multiple overrides correctly', async () => { | ||
snapshot( | ||
ConfigService.merge( | ||
base, | ||
{ env: { dataSource: 'TEST', foo: 'bar' } }, | ||
{ env: { foo: 'qux', erm: 3 } }, | ||
), | ||
) | ||
}) | ||
}) | ||
}) |