Skip to content

Commit

Permalink
Improve suffixes in test-each
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 20, 2019
1 parent 7a36d85 commit 0ac3cc1
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions test/helpers/test_each/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ import { isPlainObject } from './utils.js'

// Serialize an argument so it can be used as a suffix
export const serializeArg = function(arg) {
// `{ suffix }` can be used to override the default suffix
if (isPlainObject(arg) && typeof arg.suffix === 'string') {
if (hasSuffix(arg)) {
return arg.suffix
}

return serializeValue(arg)
}

const serializeValue = function(value) {
if (typeof value === 'string') {
return value
if (typeof arg === 'string') {
return arg
}

if (typeof value === 'function') {
return serializeFunction(value)
if (typeof arg === 'function') {
return serializeFunction(arg)
}

return inspect(value, INSPECT_OPTS)
return inspect(arg, INSPECT_OPTS)
}

// `{ suffix }` can be used to override the default suffix
const hasSuffix = function(arg) {
return (
isPlainObject(arg) &&
typeof arg.suffix === 'string' &&
arg.suffix.trim() !== ''
)
}

const serializeFunction = function(func) {
Expand Down

0 comments on commit 0ac3cc1

Please sign in to comment.