-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
104 additions
and
644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
import run from '@dxcli/engine' | ||
import {Plugin} from 'fancy-mocha' | ||
import * as _ from 'lodash' | ||
|
||
import {Options} from '.' | ||
|
||
export default (args: string[] | string, opts: Options = {}) => { | ||
return { | ||
async before() { | ||
args = _.castArray(args) | ||
await run(args, {root: opts.root || module.parent!.parent!.filename}) | ||
} | ||
} | ||
} | ||
// const exit = opts.exit || 0 | ||
// try { | ||
// await run(args, {root: opts.root || module.parent!.parent!.filename}) | ||
// } catch (err) { | ||
// if (err.code !== 'EEXIT') throw err | ||
// if (err['cli-ux'].exit !== exit) { | ||
// throw new Error(`Expected exit code to be ${exit} but got ${err['cli-ux'].exit}`) | ||
// } | ||
// } | ||
export default (async (next, __, args: string[] | string, opts: Options) => { | ||
_.defaults(opts, { | ||
root: module.parent!.parent!.filename | ||
}) | ||
await run(_.castArray(args), {root: opts.root}) | ||
await next({}) | ||
}) as Plugin<{}, (string[] | string), Partial<Options>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
import {CLIError} from 'cli-ux' | ||
import {Plugin} from 'fancy-mocha' | ||
|
||
/** | ||
* ensures that a dxcli command or hook exits | ||
* | ||
* @param code - expected code | ||
* @default 0 | ||
*/ | ||
export default (code = 0) => { | ||
let err: CLIError | ||
return { | ||
catch(_: any, e: CLIError) { | ||
err = e | ||
if (!err['cli-ux'] || typeof err['cli-ux'].exit !== 'number') throw err | ||
if (err['cli-ux'].exit !== code) { | ||
throw new Error(`Expected hook to exit with ${code} but exited with ${err['cli-ux'].exit}`) | ||
} | ||
}, | ||
finally() { | ||
if (!err) throw new Error(`Expected hook to exit with code ${code} but it ran without exiting`) | ||
export default (async (next, __, code) => { | ||
try { | ||
await next({}) | ||
throw new Error(`Expected hook to exit with code ${code} but it ran without exiting`) | ||
} catch (err) { | ||
if (!err['cli-ux'] || typeof err['cli-ux'].exit !== 'number') throw err | ||
if (err['cli-ux'].exit !== code) { | ||
throw new Error(`Expected hook to exit with ${code} but exited with ${err['cli-ux'].exit}`) | ||
} | ||
} | ||
} | ||
}) as Plugin<{}, number> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
import base, {expect, Test, TestBase} from 'fancy-mocha' | ||
import {Base, expect, fancy} from 'fancy-mocha' | ||
|
||
import command from './command' | ||
import exit from './exit' | ||
import hook from './hook' | ||
|
||
import {Options} from './options' | ||
|
||
export const test = base | ||
.extend('command', command) | ||
.extend('exit', exit) | ||
.extend('hook', hook) | ||
export const test = fancy | ||
.register('command', command) | ||
.register('exit', exit) | ||
.register('hook', hook) | ||
|
||
export default test | ||
|
||
export { | ||
expect, | ||
exit, | ||
Test, | ||
TestBase, | ||
Options, | ||
Base, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.