Skip to content

Commit

Permalink
Fix options logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jul 31, 2019
1 parent 9ed5cf0 commit bb568e1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"core-js": "^3.1.4",
"find-up": "^4.1.0",
"jest-validate": "^24.8.0",
"locate-path": "^5.0.0",
"p-event": "^4.1.0",
"p-map-series": "^2.1.0",
Expand Down
30 changes: 25 additions & 5 deletions src/options/main.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
import { cwd as getCwd } from 'process'

import { validate } from 'jest-validate'

import { getConfig } from './config.js'

// Retrieve options/configuration
export const getOpts = async function(opts = {}) {
const optsA = await getConfig({ opts })
// We need to do this twice because configuration loading needs to have
// `cwd` and `config` type checked, but it also adds new options.
validate(opts, { exampleConfig: EXAMPLE_OPTS })

const optsB = await getConfig({ opts })

const optsC = normalizeOpts(optsB)

const optsD = normalizeDuration(optsC)
return optsD
}

const optsB = { ...DEFAULT_OPTS, ...optsA }
const normalizeOpts = function(opts) {
validate(opts, { exampleConfig: EXAMPLE_OPTS })

const optsC = normalizeDuration(optsB)
return optsC
const optsA = { ...DEFAULT_OPTS, ...opts }
return optsA
}

const DEFAULT_OPTS = {
duration: 10,
cwd: getCwd(),
duration: 10,
}

export const EXAMPLE_OPTS = {
...DEFAULT_OPTS,
config: 'spyd.json',
file: 'benchmarks.js',
}

// Duration is specified in seconds by the user but we convert it to nanoseconds
const normalizeDuration = function({ duration, ...opts }) {
const durationA = duration * SECONDS_TO_NANOSECONDS
return { ...opts, duration: durationA }
Expand Down
2 changes: 0 additions & 2 deletions src/tasks/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ const getTaskFile = async function(file, cwd) {

const DEFAULT_TASK_PATHS = [
'benchmarks.js',
'benchmarks/index.js',
'benchmarks/main.js',
'benchmarks.ts',
'benchmarks/index.ts',
'benchmarks/main.ts',
]

0 comments on commit bb568e1

Please sign in to comment.