Skip to content

Commit

Permalink
Use filter-obj
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 27, 2019
1 parent 8d69a07 commit 3dcb9f2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"fast-deep-equal": "^2.0.1",
"fast-glob": "^3.0.4",
"figures": "^3.0.0",
"filter-obj": "^2.0.0",
"find-up": "^4.1.0",
"get-node": "^4.0.3",
"get-stream": "^5.1.0",
Expand Down
14 changes: 7 additions & 7 deletions src/bin/parse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { omitBy } from '../utils/main.js'
import filterObj from 'filter-obj'

import { normalizeDynamicOpts } from './dynamic.js'

Expand All @@ -10,19 +10,19 @@ export const parseOpts = function(yargs) {

const optsA = normalizeDynamicOpts(opts)

const optsB = omitBy(optsA, isInternalKey)
const optsB = filterObj(optsA, isUserOpt)
return [command, optsB]
}

const DEFAULT_COMMAND = 'run'

// Remove `yargs`-specific options, shortcuts and dash-cased
const isInternalKey = function(key, value) {
const isUserOpt = function(key, value) {
return (
value === undefined ||
INTERNAL_KEYS.includes(key) ||
key.length === 1 ||
key.includes('-')
value !== undefined &&
!INTERNAL_KEYS.includes(key) &&
key.length !== 1 &&
!key.includes('-')
)
}

Expand Down
8 changes: 4 additions & 4 deletions src/options/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { cwd as getCwd, stderr } from 'process'

import { validate, multipleValidOptions } from 'jest-validate'
import isInteractive from 'is-interactive'
import filterObj from 'filter-obj'

import { omitBy } from '../utils/main.js'
import { getDefaultGroup } from '../ci/info.js'

import { getConfig } from './config.js'
Expand All @@ -12,7 +12,7 @@ import { preNormalizeOpts, normalizeOpts } from './normalize.js'

// Retrieve options/configuration
export const getOpts = async function(action, opts = {}) {
const optsA = omitBy(opts, isUndefined)
const optsA = filterObj(opts, isDefined)

validateOpts(optsA)

Expand All @@ -28,8 +28,8 @@ export const getOpts = async function(action, opts = {}) {
return optsF
}

const isUndefined = function(value) {
return value === undefined
const isDefined = function(key, value) {
return value !== undefined
}

// We need to do this twice because configuration loading needs to have
Expand Down
9 changes: 4 additions & 5 deletions src/run/runners/node/options.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { validate } from 'jest-validate'

import { omitBy } from '../../../utils/main.js'
import filterObj from 'filter-obj'

// Validate runner options
export const getOpts = function(runOpts) {
const runOptsA = omitBy(runOpts, isUndefined)
const runOptsA = filterObj(runOpts, isDefined)
const runOptsB = normalizeVersions(runOptsA)

validate(runOptsB, { exampleConfig: EXAMPLE_OPTS })
Expand All @@ -13,8 +12,8 @@ export const getOpts = function(runOpts) {
return runOptsC
}

const isUndefined = function(value) {
return value === undefined
const isDefined = function(key, value) {
return value !== undefined
}

// If versions is `MAJOR` or `MAJOR.MINOR`, yargs will parse it as a number
Expand Down
8 changes: 0 additions & 8 deletions src/utils/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ const omitReduce = function(object, key) {
return objectA
}

// Like lodash _.omitBy()
export const omitBy = function(object, condition) {
const pairs = Object.entries(object)
.filter(([key, value]) => !condition(key, value))
.map(([key, value]) => ({ [key]: value }))
return Object.assign({}, ...pairs)
}

export const isEmptyObject = function(object) {
return Object.values(object).every(isUndefined)
}
Expand Down

0 comments on commit 3dcb9f2

Please sign in to comment.