-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Ignore
context
options from being deep merged (#144)
- Loading branch information
1 parent
548002c
commit 2123d83
Showing
8 changed files
with
53 additions
and
19 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
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
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,13 @@ | ||
import mergeWith from 'lodash-es/mergeWith'; | ||
|
||
function customizer(objValue, srcValue, key) { | ||
// Arrays and `context` options should just replace the existing value | ||
// and not be deep merged. | ||
if (Array.isArray(objValue) || ['context'].includes(key)) { | ||
return srcValue; | ||
} | ||
} | ||
|
||
export default function mergeConfigs(...configs) { | ||
return mergeWith({}, ...configs, customizer); | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/@pollyjs/core/tests/unit/utils/merge-configs-test.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,28 @@ | ||
import mergeConfigs from '../../../src/utils/merge-configs'; | ||
|
||
describe('Unit | Utils | mergeConfigs', function() { | ||
it('should exist', function() { | ||
expect(mergeConfigs).to.be.a('function'); | ||
}); | ||
|
||
it('should not deep merge context objects', async function() { | ||
const context = {}; | ||
const config = mergeConfigs( | ||
{ fetch: {}, xhr: {} }, | ||
{ fetch: { context } }, | ||
{ xhr: { context } }, | ||
{ fetch: {}, xhr: {} } | ||
); | ||
|
||
expect(config.fetch.context).to.equal(context); | ||
expect(config.xhr.context).to.equal(context); | ||
}); | ||
|
||
it('should not deep merge arrays', async function() { | ||
const array = [{}]; | ||
const config = mergeConfigs({ array: [] }, { array }); | ||
|
||
expect(config.array).to.equal(array); | ||
expect(config.array[0]).to.equal(array[0]); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -7828,7 +7828,7 @@ is-path-inside@^1.0.0: | |
dependencies: | ||
path-is-inside "^1.0.1" | ||
|
||
is-plain-obj@^1.0.0, is-plain-obj@^1.1, is-plain-obj@^1.1.0: | ||
is-plain-obj@^1.0.0, is-plain-obj@^1.1.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e" | ||
|
||
|
@@ -9585,12 +9585,6 @@ [email protected]: | |
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61" | ||
|
||
merge-options@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/merge-options/-/merge-options-1.0.1.tgz#2a64b24457becd4e4dc608283247e94ce589aa32" | ||
dependencies: | ||
is-plain-obj "^1.1" | ||
|
||
merge-stream@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-1.0.1.tgz#4041202d508a342ba00174008df0c251b8c135e1" | ||
|