Skip to content

Commit

Permalink
refactor: rename merge and mergeAll to deepmerge and deepmergeAll
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Jan 23, 2021
1 parent 887c988 commit 678eda3
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 76 deletions.
12 changes: 6 additions & 6 deletions test/custom-array-merge.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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` },
Expand All @@ -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)
Expand Down Expand Up @@ -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()
})
6 changes: 3 additions & 3 deletions test/custom-is-mergeable-object.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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,
})

Expand All @@ -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,
})

Expand Down
20 changes: 10 additions & 10 deletions test/merge-all.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
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()
})

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()
})

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/merge-plain-objects.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { deepmerge as merge } from "deepmerge"
import { deepmerge } from "deepmerge"
import test from "tape"

test(`plain objects are merged by default`, (t) => {
const input = {
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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 678eda3

Please sign in to comment.