diff --git a/test/custom-array-merge.ts b/test/custom-array-merge.ts index 29084d0..bc6c827 100644 --- a/test/custom-array-merge.ts +++ b/test/custom-array-merge.ts @@ -1,5 +1,5 @@ import type { Options } from "deepmerge" -import { deepmerge as merge } from "deepmerge" +import { deepmerge } from "deepmerge" import test from "tape" test(`custom merge array`, (t) => { @@ -20,7 +20,7 @@ test(`custom merge array`, (t) => { someArray: [ 1, 2, 3 ], } - const actual = merge(destination, source, { arrayMerge: overwriteMerge }) + const actual = deepmerge(destination, source, { arrayMerge: overwriteMerge }) const expected = { someArray: [ 1, 2, 3 ], someObject: { what: `yes` }, @@ -34,7 +34,7 @@ test(`custom merge array`, (t) => { test(`merge top-level arrays`, (t) => { const overwriteMerge: Options[`arrayMerge`] = (a, b) => b - const actual = merge([ 1, 2 ], [ 1, 2 ], { arrayMerge: overwriteMerge }) + const actual = deepmerge([ 1, 2 ], [ 1, 2 ], { arrayMerge: overwriteMerge }) const expected = [ 1, 2 ] t.deepEqual(actual, expected) @@ -63,9 +63,9 @@ test(`cloner function is available for merge functions to use`, (t) => { key2: [ `four` ], } - t.deepEqual(merge(target, src, { arrayMerge: cloneMerge }), expected) + t.deepEqual(deepmerge(target, src, { arrayMerge: cloneMerge }), expected) t.ok(customMergeWasCalled) - t.ok(Array.isArray(merge(target, src).key1)) - t.ok(Array.isArray(merge(target, src).key2)) + t.ok(Array.isArray(deepmerge(target, src).key1)) + t.ok(Array.isArray(deepmerge(target, src).key2)) t.end() }) diff --git a/test/custom-is-mergeable-object.ts b/test/custom-is-mergeable-object.ts index d76f628..4f4df08 100644 --- a/test/custom-is-mergeable-object.ts +++ b/test/custom-is-mergeable-object.ts @@ -1,5 +1,5 @@ import type { Options } from "deepmerge" -import { deepmerge as merge } from "deepmerge" +import { deepmerge } from "deepmerge" import test from "tape" test(`isMergeable function copying object over object`, (t) => { @@ -9,7 +9,7 @@ test(`isMergeable function copying object over object`, (t) => { const customIsMergeable: Options[`isMergeable`] = (object) => object && typeof object === `object` && object.isMergeable !== false - const res = merge(target, src, { + const res = deepmerge(target, src, { isMergeable: customIsMergeable, }) @@ -25,7 +25,7 @@ test(`isMergeable function copying object over nothing`, (t) => { const customIsMergeable: Options[`isMergeable`] = (object) => object && typeof object === `object` && object.isMergeable !== false - const res = merge(target, src, { + const res = deepmerge(target, src, { isMergeable: customIsMergeable, }) diff --git a/test/merge-all.ts b/test/merge-all.ts index 99b4821..13c7e38 100644 --- a/test/merge-all.ts +++ b/test/merge-all.ts @@ -1,19 +1,19 @@ -import { deepmergeAll as mergeAll } from "deepmerge" +import { deepmergeAll } from "deepmerge" import test from "tape" test(`throw error if first argument is not an array`, (t) => { // @ts-expect-error -- Calling mergeAll without passing in an array. - t.throws(mergeAll.bind(null, { example: true }, { another: `2` }), Error) + t.throws(deepmergeAll.bind(null, { example: true }, { another: `2` }), Error) t.end() }) test(`return an empty object if first argument is an array with no elements`, (t) => { - t.deepEqual(mergeAll([]), {}) + t.deepEqual(deepmergeAll([]), {}) t.end() }) test(`Work just fine if first argument is an array with least than two elements`, (t) => { - const actual = mergeAll([{ example: true }]) + const actual = deepmergeAll([{ example: true }]) const expected = { example: true } t.deepEqual(actual, expected) t.end() @@ -21,13 +21,13 @@ test(`Work just fine if first argument is an array with least than two elements` test(`execute correctly if options object were not passed`, (t) => { const arrayToMerge = [{ example: true }, { another: `123` }] - t.doesNotThrow(mergeAll.bind(null, arrayToMerge)) + t.doesNotThrow(deepmergeAll.bind(null, arrayToMerge)) t.end() }) test(`execute correctly if options object were passed`, (t) => { const arrayToMerge = [{ example: true }, { another: `123` }] - t.doesNotThrow(mergeAll.bind(null, arrayToMerge, { clone: true })) + t.doesNotThrow(deepmergeAll.bind(null, arrayToMerge, { clone: true })) t.end() }) @@ -37,7 +37,7 @@ test(`invoke merge on every item in array should result with all props`, (t) => const thirdObject = { third: 123 } const fourthObject = { fourth: `some string` } - const mergedObject = mergeAll([ firstObject, secondObject, thirdObject, fourthObject ]) + const mergedObject = deepmergeAll([ firstObject, secondObject, thirdObject, fourthObject ]) t.ok(mergedObject.first === true) t.ok(mergedObject.second === false) @@ -51,7 +51,7 @@ test(`invoke merge on every item in array with clone should clone all elements`, const secondObject = { b: { e: true } } const thirdObject = { c: { f: `string` } } - const mergedWithClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) + const mergedWithClone = deepmergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) t.notEqual(mergedWithClone.a, firstObject.a) t.notEqual(mergedWithClone.b, secondObject.b) @@ -65,7 +65,7 @@ test(`invoke merge on every item in array with clone=false should not clone all const secondObject = { b: { e: true } } const thirdObject = { c: { f: `string` } } - const mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: false }) + const mergedWithoutClone = deepmergeAll([ firstObject, secondObject, thirdObject ], { clone: false }) t.equal(mergedWithoutClone.a, firstObject.a) t.equal(mergedWithoutClone.b, secondObject.b) @@ -79,7 +79,7 @@ test(`invoke merge on every item in array with clone=true should clone all eleme const secondObject = { b: { e: true } } const thirdObject = { c: { f: `string` } } - const mergedWithoutClone = mergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) + const mergedWithoutClone = deepmergeAll([ firstObject, secondObject, thirdObject ], { clone: true }) t.notEqual(mergedWithoutClone.a, firstObject.a) t.notEqual(mergedWithoutClone.b, secondObject.b) diff --git a/test/merge-plain-objects.ts b/test/merge-plain-objects.ts index 0efd771..1254cbf 100644 --- a/test/merge-plain-objects.ts +++ b/test/merge-plain-objects.ts @@ -1,4 +1,4 @@ -import { deepmerge as merge } from "deepmerge" +import { deepmerge } from "deepmerge" import test from "tape" test(`plain objects are merged by default`, (t) => { @@ -6,7 +6,7 @@ test(`plain objects are merged by default`, (t) => { newObject: new Object(), objectLiteral: { a: 123 }, } - const output = merge({}, input, { clone: false }) + const output = deepmerge({}, input, { clone: false }) t.deepEqual(output.newObject, input.newObject) t.equal(output.newObject, input.newObject) @@ -22,7 +22,7 @@ test(`instantiated objects are copied by reference`, (t) => { error: new Error(), regex: /regex/, } - const output = merge({}, input) + const output = deepmerge({}, input) t.equal(output.date, input.date) t.equal(output.error, input.error) diff --git a/test/merge.ts b/test/merge.ts index 3b1bd36..1c1dba0 100644 --- a/test/merge.ts +++ b/test/merge.ts @@ -1,12 +1,12 @@ import type { Options } from "deepmerge" -import { deepmerge as merge } from "deepmerge" +import { deepmerge } from "deepmerge" import test from "tape" test(`add keys in target that do not exist at the root`, (t) => { const src = { key1: `value1`, key2: `value2` } const target = {} - const res = merge(target, src) + const res = deepmerge(target, src) t.deepEqual(target, {}, `merge should be immutable`) t.deepEqual(res, src) @@ -24,7 +24,7 @@ test(`merge existing simple keys in target at the roots`, (t) => { } t.deepEqual(target, { key1: `value1`, key3: `value3` }) - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -56,7 +56,7 @@ test(`merge nested objects into target`, (t) => { subkey2: `value2`, }, }) - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -80,8 +80,8 @@ test(`replace simple key with nested object in target`, (t) => { key2: `value2`, } - t.deepEqual(merge(target, src, { clone: true }), expected) - t.deepEqual(merge(target, src, { clone: false }), expected) + t.deepEqual(deepmerge(target, src, { clone: true }), expected) + t.deepEqual(deepmerge(target, src, { clone: false }), expected) t.end() }) @@ -103,7 +103,7 @@ test(`should add nested object in target`, (t) => { }, } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -129,7 +129,7 @@ test(`should clone source and target`, (t) => { }, } - const merged = merge(target, src, { clone: true }) + const merged = deepmerge(target, src, { clone: true }) t.deepEqual(merged, expected) @@ -152,7 +152,7 @@ test(`should clone source and target if specified`, (t) => { }, } - const merged = merge(target, src, { clone: true }) + const merged = deepmerge(target, src, { clone: true }) t.notEqual(merged.a, target.a) t.notEqual(merged.b, src.b) @@ -178,7 +178,7 @@ test(`should replace object with simple key in target`, (t) => { }, key2: `value2`, }) - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -189,7 +189,7 @@ test(`should replace objects with arrays`, (t) => { const expected = { key1: [ `subkey` ] } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -200,7 +200,7 @@ test(`should replace arrays with objects`, (t) => { const expected = { key1: { subkey: `one` } } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -211,7 +211,7 @@ test(`should replace dates with arrays`, (t) => { const expected = { key1: [ `subkey` ] } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -228,7 +228,7 @@ test(`should replace null with arrays`, (t) => { key1: [ `subkey` ], } - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -238,8 +238,8 @@ test(`should work on simple array`, (t) => { const expected = [ `one`, `two`, `one`, `three` ] - t.deepEqual(merge(target, src), expected) - t.ok(Array.isArray(merge(target, src))) + t.deepEqual(deepmerge(target, src), expected) + t.ok(Array.isArray(deepmerge(target, src))) t.end() }) @@ -249,8 +249,8 @@ test(`should work on another simple array`, (t) => { const expected = [ `a1`, `a2`, `c1`, `f1`, `p1`, `t1`, `s1`, `c2`, `r1`, `p2`, `p3` ] t.deepEqual(target, [ `a1`, `a2`, `c1`, `f1`, `p1` ]) - t.deepEqual(merge(target, src), expected) - t.ok(Array.isArray(merge(target, src))) + t.deepEqual(deepmerge(target, src), expected) + t.ok(Array.isArray(deepmerge(target, src))) t.end() }) @@ -268,9 +268,9 @@ test(`should work on array properties`, (t) => { key2: [ `four` ], } - t.deepEqual(merge(target, src), expected) - t.ok(Array.isArray(merge(target, src).key1)) - t.ok(Array.isArray(merge(target, src).key2)) + t.deepEqual(deepmerge(target, src), expected) + t.ok(Array.isArray(deepmerge(target, src).key1)) + t.ok(Array.isArray(deepmerge(target, src).key2)) t.end() }) @@ -286,7 +286,7 @@ test(`should work on array properties with clone option`, (t) => { t.deepEqual(target, { key1: [ `one`, `two` ], }) - const merged = merge(target, src, { clone: true }) + const merged = deepmerge(target, src, { clone: true }) t.notEqual(merged.key1, src.key1) t.notEqual(merged.key1, target.key1) t.notEqual(merged.key2, src.key2) @@ -310,9 +310,9 @@ test(`should work on array of objects`, (t) => { { key3: [ `five` ] }, ] - t.deepEqual(merge(target, src), expected) - t.ok(Array.isArray(merge(target, src)), `result should be an array`) - t.ok(Array.isArray(merge(target, src)[0].key1), `subkey should be an array too`) + t.deepEqual(deepmerge(target, src), expected) + t.ok(Array.isArray(deepmerge(target, src)), `result should be an array`) + t.ok(Array.isArray(deepmerge(target, src)[0].key1), `subkey should be an array too`) t.end() }) @@ -334,10 +334,10 @@ test(`should work on array of objects with clone option`, (t) => { { key3: [ `five` ] }, ] - const merged = merge(target, src, { clone: true }) + const merged = deepmerge(target, src, { clone: true }) t.deepEqual(merged, expected) - t.ok(Array.isArray(merge(target, src)), `result should be an array`) - t.ok(Array.isArray(merge(target, src)[0].key1), `subkey should be an array too`) + t.ok(Array.isArray(deepmerge(target, src)), `result should be an array`) + t.ok(Array.isArray(deepmerge(target, src)[0].key1), `subkey should be an array too`) t.notEqual(merged[0].key1, src[0].key1) t.notEqual(merged[0].key1, target[0].key1) t.false(Object.prototype.hasOwnProperty.call(merged[0], `key2`), `"key2" should not exist on "merged[0]"`) @@ -351,8 +351,8 @@ test(`should treat regular expressions like primitive values`, (t) => { const src = { key1: /efg/ } const expected = { key1: /efg/ } - t.deepEqual(merge(target, src), expected) - t.deepEqual(merge(target, src).key1.test(`efg`), true) + t.deepEqual(deepmerge(target, src), expected) + t.deepEqual(deepmerge(target, src).key1.test(`efg`), true) t.end() }) @@ -361,7 +361,7 @@ test(`should treat regular expressions like primitive values and should not` const target = { key1: /abc/ } const src = { key1: /efg/ } - const output = merge(target, src, { clone: true }) + const output = deepmerge(target, src, { clone: true }) t.equal(output.key1, src.key1) t.end() @@ -382,7 +382,7 @@ test(`should treat dates like primitives`, (t) => { const expected = { key: tuesday, } - const actual = merge(target, source) + const actual = deepmerge(target, source) t.deepEqual(actual, expected) t.equal(actual.key.valueOf(), tuesday.valueOf()) @@ -401,7 +401,7 @@ test(`should treat dates like primitives and should not clone even with clone` key: tuesday, } - const actual = merge(target, source, { clone: true }) + const actual = deepmerge(target, source, { clone: true }) t.equal(actual.key, tuesday) t.end() @@ -414,7 +414,7 @@ test(`should work on array with null in it`, (t) => { const expected = [ null ] - t.deepEqual(merge(target, src), expected) + t.deepEqual(deepmerge(target, src), expected) t.end() }) @@ -423,7 +423,7 @@ test(`should clone array's element if it is object`, (t) => { const target = [] const source = [ a ] - const output = merge(target, source, { clone: true }) + const output = deepmerge(target, source, { clone: true }) t.notEqual(output[0], a) t.equal(output[0].key, `yup`) @@ -434,7 +434,7 @@ test(`should clone an array property when there is no target array`, (t) => { const someObject = {} const target = {} const source = { ary: [ someObject ] } - const output = merge(target, source, { clone: true }) + const output = deepmerge(target, source, { clone: true }) t.deepEqual(output, { ary: [{}] }) t.notEqual(output.ary[0], someObject) @@ -453,9 +453,9 @@ test(`should overwrite values when property is initialised but undefined`, (t) = t.equal(typeof o.value, `undefined`) } - hasUndefinedProperty(merge(target1, src)) - hasUndefinedProperty(merge(target2, src)) - hasUndefinedProperty(merge(target3, src)) + hasUndefinedProperty(deepmerge(target1, src)) + hasUndefinedProperty(deepmerge(target2, src)) + hasUndefinedProperty(deepmerge(target3, src)) t.end() }) @@ -468,7 +468,7 @@ test(`dates should copy correctly in an array`, (t) => { const source = [ tuesday, `lol` ] const expected = [ monday, `dude`, tuesday, `lol` ] - const actual = merge(target, source) + const actual = deepmerge(target, source) t.deepEqual(actual, expected) t.end() @@ -513,7 +513,7 @@ test(`should handle custom merge functions`, (t) => { return mergePeople } - return merge + return deepmerge }, } @@ -526,7 +526,7 @@ test(`should handle custom merge functions`, (t) => { }, } - const actual = merge(target, source, options) + const actual = deepmerge(target, source, options) t.deepEqual(actual, expected) t.end() }) @@ -569,7 +569,7 @@ test(`should handle custom merge functions`, (t) => { }, } - const actual = merge(target, source, options) + const actual = deepmerge(target, source, options) t.deepEqual(actual, expected) t.end() }) @@ -601,7 +601,7 @@ test(`should merge correctly if custom merge is not a valid function`, (t) => { }, } - const actual = merge(target, source) + const actual = deepmerge(target, source) t.deepEqual(actual, expected) t.end() }) @@ -611,7 +611,7 @@ test(`copy symbol keys in target that do not exist on the target`, (t) => { const src = { [mySymbol]: `value1` } const target = {} - const res = merge(target, src) + const res = deepmerge(target, src) t.equal(res[mySymbol], `value1`) t.deepEqual(Object.getOwnPropertySymbols(res), Object.getOwnPropertySymbols(src)) @@ -623,7 +623,7 @@ test(`copy symbol keys in target that do exist on the target`, (t) => { const src = { [mySymbol]: `value1` } const target = { [mySymbol]: `wat` } - const res = merge(target, src) + const res = deepmerge(target, src) t.equal(res[mySymbol as unknown as string], `value1`) t.end() @@ -632,7 +632,7 @@ test(`copy symbol keys in target that do exist on the target`, (t) => { test(`should not mutate options`, (t) => { const options: Options = {} - merge({}, {}, options) + deepmerge({}, {}, options) t.deepEqual(options, {}) t.end() @@ -651,7 +651,7 @@ test(`Falsey properties should be mergeable`, (t) => { let customMergeWasCalled = false - const result = merge(target, source, { + const result = deepmerge(target, source, { isMergeable() { return true }, diff --git a/test/prototype-poisoning.ts b/test/prototype-poisoning.ts index cd1379c..49d4313 100644 --- a/test/prototype-poisoning.ts +++ b/test/prototype-poisoning.ts @@ -1,12 +1,12 @@ import type { Options } from "deepmerge" -import { deepmerge as merge } from "deepmerge" +import { deepmerge } from "deepmerge" import isPlainObj from "is-plain-obj" import test from "tape" test(`merging objects with own __proto__`, (t) => { const user = {} const malicious = JSON.parse(`{ "__proto__": { "admin": true } }`) - const mergedObject = merge(user, malicious) + const mergedObject = deepmerge(user, malicious) t.notOk(mergedObject.__proto__.admin, `non-plain properties should not be merged`) t.notOk(mergedObject.admin, `the destination should have an unmodified prototype`) t.end() @@ -29,7 +29,7 @@ test(`merging objects with plain and non-plain properties`, (t) => { [plainSymbolKey]: `qux`, } - const mergedObject = merge(target, source, { clone: true }) + const mergedObject = deepmerge(target, source, { clone: true }) t.equal(undefined, mergedObject.parentKey, `inherited properties of target should be removed, not merged or ignored`) t.equal(`bar`, mergedObject.plainKey, `enumerable own properties of target should be merged`) t.equal(`baz`, mergedObject.newKey, `properties not yet on target should be merged`) @@ -47,14 +47,14 @@ test(`merging strings works with a custom string merge`, (t) => { return target[0] + `. ` + source.substring(0, 3) } } else { - return merge + return deepmerge } } const mergeable: Options[`isMergeable`] = (target) => isPlainObj(target) || (typeof target === `string` && target.length > 1) - t.equal(`A. Ham`, merge(target, source, { customMerge, isMergeable: mergeable }).name) + t.equal(`A. Ham`, deepmerge(target, source, { customMerge, isMergeable: mergeable }).name) t.end() }) @@ -73,6 +73,6 @@ test(`merging objects with null prototype`, (t) => { }, } - t.deepEqual(merge(target, source, { clone: true }), expected) + t.deepEqual(deepmerge(target, source, { clone: true }), expected) t.end() })