Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
searls committed Feb 12, 2023
1 parent 94eb68b commit 18c746d
Show file tree
Hide file tree
Showing 18 changed files with 429 additions and 318 deletions.
597 changes: 354 additions & 243 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Expand Up @@ -95,32 +95,32 @@
},
"dependencies": {
"lodash": "^4.17.21",
"quibble": "^0.6.14",
"quibble": "^0.6.16",
"stringify-object-es5": "^2.5.0",
"theredoc": "^1.0.0"
},
"devDependencies": {
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@types/node": "^18.13.0",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"browserify": "^17.0.0",
"codeclimate-test-reporter": "^0.5.1",
"cross-conf-env": "^1.3.0",
"dedent": "^0.7.0",
"headerify": "^1.0.1",
"is-number": "^7.0.0",
"is-promise": "^4.0.0",
"mkdirp": "^1.0.4",
"mkdirp": "^2.1.3",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"rimraf": "^3.0.2",
"rimraf": "^4.1.2",
"standard": "^17.0.0",
"teenytest": "^6.0.3",
"teenytest": "^6.0.4",
"teenytest-promise": "^1.0.0",
"testdouble": "^3.16.7",
"testdouble": "^3.16.8",
"ts-node": "^10.9.1",
"tsify": "^5.0.4",
"typescript": "^4.9.3"
"typescript": "^4.9.5"
},
"directories": {
"doc": "./docs",
Expand Down
8 changes: 4 additions & 4 deletions src/args-match.js
Expand Up @@ -11,14 +11,14 @@ export default (expectedArgs, actualArgs, config = {}) => {
}
}

var arityMismatch = (expectedArgs, actualArgs, config) =>
const arityMismatch = (expectedArgs, actualArgs, config) =>
expectedArgs.length !== actualArgs.length && !config.ignoreExtraArgs

var equalsWithMatchers = (expectedArgs, actualArgs) =>
const equalsWithMatchers = (expectedArgs, actualArgs) =>
_.every(expectedArgs, (expectedArg, key) =>
argumentMatchesExpectation(expectedArg, actualArgs[key]))

var argumentMatchesExpectation = (expectedArg, actualArg) => {
const argumentMatchesExpectation = (expectedArg, actualArg) => {
if (isMatcher(expectedArg)) {
return matcherTestFor(expectedArg)(actualArg)
} else {
Expand All @@ -30,5 +30,5 @@ var argumentMatchesExpectation = (expectedArg, actualArg) => {
}
}

var matcherTestFor = (matcher) =>
const matcherTestFor = (matcher) =>
matcher.__matches
2 changes: 1 addition & 1 deletion src/config.js
Expand Up @@ -30,7 +30,7 @@ const deleteDeletedOptions = (overrides) => {
})
}

var ensureOverridesExist = (overrides) => {
const ensureOverridesExist = (overrides) => {
_.each(overrides, (val, key) => {
if (!Object.prototype.hasOwnProperty.call(configData, key)) {
log.error('td.config',
Expand Down
2 changes: 1 addition & 1 deletion src/constructor.js
Expand Up @@ -7,7 +7,7 @@ export default (typeOrNames) =>
? imitate(typeOrNames)
: fakeConstructorFromNames(typeOrNames)

var fakeConstructorFromNames = (funcNames) => {
const fakeConstructorFromNames = (funcNames) => {
return _.tap(tdFunction('(unnamed constructor)'), (fakeConstructor) => {
fakeConstructor.prototype.toString = () =>
'[test double instance of constructor]'
Expand Down
4 changes: 2 additions & 2 deletions src/function.js
Expand Up @@ -10,7 +10,7 @@ export default function func (nameOrFunc, __optionalName) {
: createTestDoubleNamed(nameOrFunc || __optionalName)
}

var createTestDoubleNamed = function (name) {
const createTestDoubleNamed = function (name) {
return _.tap(createTestDoubleFunction(), (testDouble) => {
const entry = store.for(testDouble, true)
if (name != null) {
Expand All @@ -22,7 +22,7 @@ var createTestDoubleNamed = function (name) {
})
}

var createTestDoubleFunction = function () {
const createTestDoubleFunction = function () {
return function testDouble (...args) {
calls.log(testDouble, args, this)
return stubbings.invoke(testDouble, args, this)
Expand Down
2 changes: 1 addition & 1 deletion src/log.js
Expand Up @@ -18,7 +18,7 @@ export default {
}
}

var withUrl = (url) =>
const withUrl = (url) =>
url != null
? ` (see: ${url} )`
: ''
2 changes: 1 addition & 1 deletion src/matchers/create.js
Expand Up @@ -15,7 +15,7 @@ export default config =>
_.invoke(config, 'onCreate', matcherInstance, matcherArgs)
})

var nameFor = (config, matcherArgs) => {
const nameFor = (config, matcherArgs) => {
if (_.isFunction(config.name)) {
return config.name(matcherArgs)
} else if (config.name != null) {
Expand Down
14 changes: 7 additions & 7 deletions src/object.js
Expand Up @@ -12,7 +12,7 @@ export default function object (nameOrType, config) {
})
}

var fakeObject = function (nameOrType, config, argCount) {
const fakeObject = function (nameOrType, config, argCount) {
if (_.isArray(nameOrType)) {
return createTestDoublesForFunctionNames(nameOrType)
} else if (_.isObjectLike(nameOrType)) {
Expand All @@ -26,15 +26,15 @@ var fakeObject = function (nameOrType, config, argCount) {
}
}

var createTestDoublesForFunctionNames = (names) =>
const createTestDoublesForFunctionNames = (names) =>
_.transform(names, (acc, funcName) => {
acc[funcName] = tdFunction(`.${String(funcName)}`)
}, {})

var ensureFunctionIsNotPassed = () =>
const ensureFunctionIsNotPassed = () =>
log.error('td.object', 'Functions are not valid arguments to `td.object` (as of testdouble@2.0.0). Please use `td.function()`, `td.constructor()` or `td.instance()` instead for creating fake functions.')

var ensureOtherGarbageIsNotPassed = () =>
const ensureOtherGarbageIsNotPassed = () =>
log.error('td.object', `\
To create a fake object with td.object(), pass it a plain object that contains
functions, an array of function names, or (if your runtime supports ES Proxy
Expand All @@ -44,15 +44,15 @@ If you passed td.object an instance of a custom type, consider passing the
type's constructor to \`td.constructor()\` instead.
`)

var withDefaults = (config) =>
const withDefaults = (config) =>
_.extend({}, DEFAULT_OPTIONS, config)

var addToStringToDouble = (fakeObject, nameOrType) => {
const addToStringToDouble = (fakeObject, nameOrType) => {
const name = nameOf(nameOrType)
fakeObject.toString = () => `[test double object${name ? ` for "${name}"` : ''}]`
}

var nameOf = (nameOrType) =>
const nameOf = (nameOrType) =>
_.isString(nameOrType)
? nameOrType
: ''
4 changes: 2 additions & 2 deletions src/replace/property.js
Expand Up @@ -26,7 +26,7 @@ export default function (object, property, manualReplacement) {
}
}

var getFake = (isManual, property, manualReplacement, realThing) => {
const getFake = (isManual, property, manualReplacement, realThing) => {
if (isManual) {
warnIfTypeMismatch(property, manualReplacement, realThing)
return manualReplacement
Expand All @@ -35,7 +35,7 @@ var getFake = (isManual, property, manualReplacement, realThing) => {
}
}

var warnIfTypeMismatch = (property, fakeThing, realThing) => {
const warnIfTypeMismatch = (property, fakeThing, realThing) => {
const fakeType = typeof fakeThing
const realType = typeof realThing
if (realThing !== undefined && fakeType !== realType) {
Expand Down
20 changes: 10 additions & 10 deletions src/store/stubbings.js
Expand Up @@ -29,11 +29,11 @@ export default {
}
}

var stubbingFor = (testDouble, actualArgs) =>
const stubbingFor = (testDouble, actualArgs) =>
_.findLast(store.for(testDouble).stubbings, stubbing =>
isSatisfied(stubbing, actualArgs))

var executePlan = (stubbing, actualArgs, actualContext) => {
const executePlan = (stubbing, actualArgs, actualContext) => {
const value = stubbedValueFor(stubbing)
stubbing.callCount += 1
invokeCallbackFor(stubbing, actualArgs)
Expand All @@ -46,7 +46,7 @@ var executePlan = (stubbing, actualArgs, actualContext) => {
}
}

var invokeCallbackFor = (stubbing, actualArgs) => {
const invokeCallbackFor = (stubbing, actualArgs) => {
if (_.some(stubbing.args, isCallback)) {
_.each(stubbing.args, (expectedArg, i) => {
if (isCallback(expectedArg)) {
Expand All @@ -56,7 +56,7 @@ var invokeCallbackFor = (stubbing, actualArgs) => {
}
}

var callbackArgs = (stubbing, expectedArg) => {
const callbackArgs = (stubbing, expectedArg) => {
if (expectedArg.args != null) {
return expectedArg.args
} else if (stubbing.config.plan === 'thenCallback') {
Expand All @@ -66,7 +66,7 @@ var callbackArgs = (stubbing, expectedArg) => {
}
}

var callCallback = (stubbing, callback, args) => {
const callCallback = (stubbing, callback, args) => {
if (stubbing.config.delay) {
_.delay(callback, stubbing.config.delay, ...args)
} else if (stubbing.config.defer) {
Expand All @@ -76,7 +76,7 @@ var callCallback = (stubbing, callback, args) => {
}
}

var createPromise = (stubbing, value, willResolve) => {
const createPromise = (stubbing, value, willResolve) => {
const Promise = config().promiseConstructor
ensurePromise(Promise)
return new Promise((resolve, reject) => {
Expand All @@ -86,21 +86,21 @@ var createPromise = (stubbing, value, willResolve) => {
})
}

var stubbedValueFor = (stubbing) =>
const stubbedValueFor = (stubbing) =>
stubbing.callCount < stubbing.stubbedValues.length
? stubbing.stubbedValues[stubbing.callCount]
: _.last(stubbing.stubbedValues)

var isSatisfied = (stubbing, actualArgs) =>
const isSatisfied = (stubbing, actualArgs) =>
argsMatch(stubbing.args, actualArgs, stubbing.config) &&
hasTimesRemaining(stubbing)

var hasTimesRemaining = (stubbing) =>
const hasTimesRemaining = (stubbing) =>
stubbing.config.times == null
? true
: stubbing.callCount < stubbing.config.times

var ensurePromise = (Promise) => {
const ensurePromise = (Promise) => {
if (Promise == null) {
return log.error('td.when', `\
no promise constructor is set (perhaps this runtime lacks a native Promise
Expand Down
4 changes: 2 additions & 2 deletions src/stringify/anything.js
Expand Up @@ -25,7 +25,7 @@ export default (anything) => {
}
}

var stringifyString = (string) =>
const stringifyString = (string) =>
_.includes(string, '\n')
? `"""\n${string}\n"""`
: `"${string.replace(new RegExp('"', 'g'), '\\"')}"`
: `"${string.replace(/"/g, '\\"')}"`
20 changes: 10 additions & 10 deletions src/verify.js
Expand Up @@ -21,7 +21,7 @@ export default (__userDoesRehearsalInvocationHere__, config = {}) => {
}
}

var ensureRehearsalOccurred = (last) => {
const ensureRehearsalOccurred = (last) => {
if (!last) {
log.error('td.verify', `\
No test double invocation detected for \`verify()\`.
Expand All @@ -46,7 +46,7 @@ const notifyMatchers = (testDouble, expectedArgs, config) => {
})
}

var warnIfStubbed = (testDouble, actualArgs) => {
const warnIfStubbed = (testDouble, actualArgs) => {
if (_.some(stubbingsStore.for(testDouble), (stubbing) =>
argsMatch(stubbing.args, actualArgs, stubbing.config))
) {
Expand All @@ -57,25 +57,25 @@ var warnIfStubbed = (testDouble, actualArgs) => {
}
}

var unsatisfiedErrorMessage = (testDouble, args, config) =>
const unsatisfiedErrorMessage = (testDouble, args, config) =>
baseSummary(testDouble, args, config) +
matchedInvocationSummary(testDouble, args, config) +
invocationSummary(testDouble, args, config)

var stringifyName = (testDouble) => {
const stringifyName = (testDouble) => {
const name = store.for(testDouble).name
return name ? ` \`${name}\`` : ''
}

var baseSummary = (testDouble, args, config) =>
const baseSummary = (testDouble, args, config) =>
`\
Unsatisfied verification on test double${stringifyName(testDouble)}.
Wanted:
- called with \`(${stringifyArgs(args)})\`${timesMessage(config)}${ignoreMessage(config)}.\
`

var invocationSummary = (testDouble, args, config) => {
const invocationSummary = (testDouble, args, config) => {
const calls = callsStore.for(testDouble)
if (calls.length === 0) {
return '\n\n But there were no invocations of the test double.'
Expand All @@ -86,7 +86,7 @@ var invocationSummary = (testDouble, args, config) => {
}
}

var matchedInvocationSummary = (testDouble, args, config) => {
const matchedInvocationSummary = (testDouble, args, config) => {
const calls = callsStore.where(testDouble, args, config)
const expectedCalls = config.times || 0

Expand All @@ -99,15 +99,15 @@ var matchedInvocationSummary = (testDouble, args, config) => {
}
}

var pluralize = (x, msg) =>
const pluralize = (x, msg) =>
`${x} ${msg}${x === 1 ? '' : 's'}`

var timesMessage = (config) =>
const timesMessage = (config) =>
config.times != null
? ` ${pluralize(config.times, 'time')}`
: ''

var ignoreMessage = (config) =>
const ignoreMessage = (config) =>
config.ignoreExtraArgs != null
? ', ignoring any additional arguments'
: ''
4 changes: 2 additions & 2 deletions test/helper.js
Expand Up @@ -2,8 +2,8 @@ require('ts-node/register')
global.assert = require('assert')
global.ES_SUPPORT = require('./support/es-support')

var CallLog = require('../src/value/call-log').default
var StubbingRegister = require('../src/value/stubbing-register').default
const CallLog = require('../src/value/call-log').default
const StubbingRegister = require('../src/value/stubbing-register').default

module.exports = {
beforeAll: function () {
Expand Down
4 changes: 2 additions & 2 deletions test/safe/imitate.test.js
Expand Up @@ -38,7 +38,7 @@ module.exports = {
},
'skips encountered objects' () {
const foo = { a: 1, b: 2 }
const bar = { c: 3, foo: foo }
const bar = { c: 3, foo }
foo.bar = bar
const original = { item: foo }

Expand All @@ -51,7 +51,7 @@ module.exports = {
b: 2,
bar: {
c: 3,
foo: foo // <- and so on
foo // <- and so on
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion test/unit/function/generate-fake-function.test.js
Expand Up @@ -15,7 +15,7 @@ module.exports = {

subject(double).call('fake this', 1, 2, 3)

var calls = CallLog.instance.for(double)
const calls = CallLog.instance.for(double)
assert.equal(calls.length, 1)
assert.equal(calls[0].context, 'fake this')
assert.deepEqual(calls[0].args, [1, 2, 3])
Expand Down

0 comments on commit 18c746d

Please sign in to comment.