diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc2f644..9056b858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ + +## [0.9.16](https://github.com/dxcli/test/compare/43dfa2997d4d3889d6a5af0300a1310f5f727eb2...v0.9.16) (2018-01-28) + + +### Bug Fixes + +* fixed config loading ([11b7668](https://github.com/dxcli/test/commit/11b7668)) + ## [0.9.15](https://github.com/dxcli/test/compare/1c361aa61eabdd02a887339d656eb06f86244a4c...v0.9.15) (2018-01-28) diff --git a/package.json b/package.json index 5b3727fa..f7a48cfb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@dxcli/test", "description": "test helpers for dxcli components", - "version": "0.9.15", + "version": "0.9.16", "author": "Jeff Dickey @jdxcode", "bugs": "https://github.com/dxcli/test/issues", "dependencies": { @@ -14,7 +14,7 @@ "@dxcli/engine": "^0.1.12", "@dxcli/loader": "^0.2.8", "@dxcli/semantic-release": "^0.3.3", - "@dxcli/tslint": "^0.0.23", + "@dxcli/tslint": "^0.0.24", "@dxcli/version": "^0.1.6", "chai": "^4.1.2", "cli-ux": "^3.2.2", diff --git a/src/command.ts b/src/command.ts index 64f62c65..3385f18d 100644 --- a/src/command.ts +++ b/src/command.ts @@ -2,8 +2,11 @@ import {IConfig} from '@dxcli/config' import run from '@dxcli/engine' import * as _ from 'lodash' +import loadConfig from './load_config' + export default (args: string[] | string | undefined) => ({ async run(ctx: {config: IConfig, expectation: string}) { + if (!ctx.config) ctx.config = await loadConfig().run({} as any) args = _.castArray(args) ctx.expectation = ctx.expectation || `runs ${args.join(' ')}` await run(args, ctx.config) diff --git a/src/hook.ts b/src/hook.ts index 32b5caf6..c0dab6f4 100644 --- a/src/hook.ts +++ b/src/hook.ts @@ -1,6 +1,8 @@ import {IConfig} from '@dxcli/config' import {Engine} from '@dxcli/engine' +import loadConfig from './load_config' + /** * tests a dxcli hook * @@ -14,6 +16,7 @@ import {Engine} from '@dxcli/engine' */ export default (event?: string, hookOpts: object = {}) => ({ async run(ctx: {config: IConfig, expectation: string}) { + if (!ctx.config) ctx.config = await loadConfig().run({} as any) ctx.expectation = ctx.expectation || `runs ${event} hook` const engine = new Engine() await engine.load(ctx.config.root) diff --git a/src/index.ts b/src/index.ts index 2820c5ad..f7b3c311 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,8 @@ import exit from './exit' import hook from './hook' import loadConfig from './load_config' +loadConfig.root = module.parent!.filename + export const test = fancy .register('loadConfig', loadConfig) .register('command', command) diff --git a/src/load_config.ts b/src/load_config.ts index 4d34e9f2..fc21de08 100644 --- a/src/load_config.ts +++ b/src/load_config.ts @@ -1,14 +1,18 @@ -import * as path from 'path' - import {IConfig} from '@dxcli/config' import {load} from '@dxcli/loader' +export type WithRoot = T & {root: string} + /** * loads CLI plugin/multi config */ -export default (opts: {root?: string} = {}) => ({ - async run(ctx: {config: IConfig}) { - const {config} = await load({root: opts.root || path.dirname(module.parent!.filename)}) - ctx.config = config +export const _loadConfig = (opts: {root?: string} = {}) => { + return { + async run(ctx: {config: IConfig}) { + const {config} = await load({root: opts.root || loadConfig.root}) + return ctx.config = config + } } -}) +} +const loadConfig = _loadConfig as WithRoot +export default loadConfig diff --git a/yarn.lock b/yarn.lock index 97ebf033..58b8dcda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -203,9 +203,9 @@ execa "^0.9.0" semantic-release "^12.2.5" -"@dxcli/tslint@^0.0.23": - version "0.0.23" - resolved "https://registry.yarnpkg.com/@dxcli/tslint/-/tslint-0.0.23.tgz#c9877ec9927bb958c1a71edac3263007ce64b22d" +"@dxcli/tslint@^0.0.24": + version "0.0.24" + resolved "https://registry.yarnpkg.com/@dxcli/tslint/-/tslint-0.0.24.tgz#32c19a574828d643bcb446cbfc0b2dbbbf1c1da0" dependencies: tslint "^5.9.1" tslint-xo "^0.5.0"