Skip to content

Commit

Permalink
test: initial conversion of test to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Jan 23, 2021
1 parent aebb6ba commit 9ce11e4
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 114 deletions.
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@
"build:js": "rollup -c",
"build:types": "tsc -p tsconfig.typedef.json",
"size": "npm run build && terser --compress --mangle -- ./dist/umd.js | gzip -c | wc -c",
"test": "npm run build && tape test/*.js && jsmd readme.md && npm run test:typescript",
"test:types": "dtslint --localTs node_modules/typescript/lib --expectOnly test/types",
"test:typescript": "tsc --noEmit test/typescript.ts && ts-node test/typescript.ts"
"test": "npm run test:js && npm run test:types && npm run test:jsmd",
"test:js": "ts-node -C typescript -P test/tsconfig.json -r tsconfig-paths/register node_modules/tape/bin/tape test/*.ts",
"pretest:jsmd": "npm run build:js",
"test:jsmd": "jsmd readme.md",
"test:types": "dtslint --localTs node_modules/typescript/lib --expectOnly test/types"
},
"dependencies": {},
"devDependencies": {
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@rollup/plugin-typescript": "^8.1.0",
"@types/node": "^8.10.54",
"@types/tape": "^4.13.0",
"dtslint": "^4.0.6",
"is-mergeable-object": "1.1.0",
"is-plain-obj": "^3.0.0",
Expand All @@ -61,6 +64,7 @@
"tape": "^5.0.1",
"terser": "^5.5.1",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.1.2"
},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions test/custom-array-merge.js → test/custom-array-merge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var merge = require('../')
var test = require('tape')
import { deepmerge as merge } from "deepmerge"
import test from "tape"

test('custom merge array', function(t) {
var mergeFunctionCalled = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var merge = require('../')
var test = require('tape')
import { deepmerge as merge } from "deepmerge"
import test from "tape"

test('isMergeable function copying object over object', function(t) {
var src = { key: { isMergeable: false }, baz: 'yes' }
Expand Down
4 changes: 2 additions & 2 deletions test/merge-all.js → test/merge-all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var merge = require('../')
var test = require('tape')
import { deepmerge as merge } from "deepmerge"
import test from "tape"

test('throw error if first argument is not an array', function(t) {
t.throws(merge.all.bind(null, { example: true }, { another: '2' }), Error)
Expand Down
68 changes: 34 additions & 34 deletions test/merge-plain-objects.js → test/merge-plain-objects.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
var merge = require('../')
var test = require('tape')

test('plain objects are merged by default', function(t) {
const input = {
newObject: new Object(),
objectLiteral: { a: 123 }
}
const output = merge({}, input)

t.deepEqual(output.newObject, input.newObject)
t.notEqual(output.newObject, input.newObject)
t.deepEqual(output.objectLiteral, input.objectLiteral)
t.notEqual(output.objectLiteral, input.objectLiteral)

t.end()
})

test('instantiated objects are copied by reference', function(t) {
const input = {
date: new Date(),
error: new Error(),
regex: /regex/
}
const output = merge({}, input)

t.equal(output.date, input.date)
t.equal(output.error, input.error)
t.equal(output.regex, input.regex)

t.end()
})

import { deepmerge as merge } from "deepmerge"
import test from "tape"

test('plain objects are merged by default', function(t) {
const input = {
newObject: new Object(),
objectLiteral: { a: 123 }
}
const output = merge({}, input)

t.deepEqual(output.newObject, input.newObject)
t.notEqual(output.newObject, input.newObject)
t.deepEqual(output.objectLiteral, input.objectLiteral)
t.notEqual(output.objectLiteral, input.objectLiteral)

t.end()
})

test('instantiated objects are copied by reference', function(t) {
const input = {
date: new Date(),
error: new Error(),
regex: /regex/
}
const output = merge({}, input)

t.equal(output.date, input.date)
t.equal(output.error, input.error)
t.equal(output.regex, input.regex)

t.end()
})


4 changes: 2 additions & 2 deletions test/merge.js → test/merge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var merge = require('../')
var test = require('tape')
import { deepmerge as merge } from "deepmerge"
import test from "tape"

test('add keys in target that do not exist at the root', function(t) {
var src = { key1: 'value1', key2: 'value2' }
Expand Down
8 changes: 4 additions & 4 deletions test/prototype-poisoning.js → test/prototype-poisoning.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var merge = require('../')
var test = require('tape')
var isMergeableObject = require('is-mergeable-object')
import { deepmerge as merge } from "deepmerge"
import test from "tape"
import isPlainObj from "is-plain-obj"

test('merging objects with own __proto__', function(t) {
var user = {}
Expand Down Expand Up @@ -51,7 +51,7 @@ test('merging strings works with a custom string merge', function(t) {
}

function mergeable(target) {
return isMergeableObject(target) || (typeof target === 'string' && target.length > 1)
return isPlainObj(target) || (typeof target === 'string' && target.length > 1)
}

t.equal('A. Ham', merge(target, source, { customMerge: customMerge, isMergeable: mergeable }).name)
Expand Down
65 changes: 0 additions & 65 deletions test/typescript.ts

This file was deleted.

0 comments on commit 9ce11e4

Please sign in to comment.