forked from vitejs/vite
-
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(build): properly handle alias key in config merge (vitejs#2847)
Co-authored-by: Anthony Fu <[email protected]>
- Loading branch information
1 parent
176e55d
commit 41261c7
Showing
2 changed files
with
114 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { mergeConfig, UserConfigExport } from '../config' | ||
|
||
describe('mergeConfig', () => { | ||
test('handles configs with different alias schemas', () => { | ||
const baseConfig: UserConfigExport = { | ||
resolve: { | ||
alias: [ | ||
{ | ||
find: 'foo', | ||
replacement: 'foo-value' | ||
} | ||
] | ||
} | ||
} | ||
|
||
const newConfig: UserConfigExport = { | ||
resolve: { | ||
alias: { | ||
bar: 'bar-value', | ||
baz: 'baz-value' | ||
} | ||
} | ||
} | ||
|
||
const mergedConfig: UserConfigExport = { | ||
resolve: { | ||
alias: [ | ||
{ | ||
find: 'foo', | ||
replacement: 'foo-value' | ||
}, | ||
{ | ||
find: 'bar', | ||
replacement: 'bar-value' | ||
}, | ||
{ | ||
find: 'baz', | ||
replacement: 'baz-value' | ||
} | ||
] | ||
} | ||
} | ||
|
||
expect(mergeConfig(baseConfig, newConfig)).toEqual(mergedConfig) | ||
}) | ||
|
||
test('handles assetsInclude', () => { | ||
const baseConfig: UserConfigExport = { | ||
assetsInclude: 'some-string' | ||
} | ||
|
||
const newConfig: UserConfigExport = { | ||
assetsInclude: ['some-other-string', /regexp?/] | ||
} | ||
|
||
const mergedConfig: UserConfigExport = { | ||
assetsInclude: ['some-string', 'some-other-string', /regexp?/] | ||
} | ||
|
||
expect(mergeConfig(baseConfig, newConfig)).toEqual(mergedConfig) | ||
}) | ||
|
||
test('not handles alias not under `resolve`', () => { | ||
const baseConfig = { | ||
custom: { | ||
alias: { | ||
bar: 'bar-value', | ||
baz: 'baz-value' | ||
} | ||
} | ||
} | ||
|
||
const newConfig = { | ||
custom: { | ||
alias: { | ||
bar: 'bar-value-2', | ||
foo: 'foo-value' | ||
} | ||
} | ||
} | ||
|
||
const mergedConfig = { | ||
custom: { | ||
alias: { | ||
bar: 'bar-value-2', | ||
baz: 'baz-value', | ||
foo: 'foo-value' | ||
} | ||
} | ||
} | ||
|
||
expect(mergeConfig(baseConfig, newConfig)).toEqual(mergedConfig) | ||
}) | ||
}) |
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