-
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
9 changed files
with
105 additions
and
74 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
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,21 +1,18 @@ | ||
import {Plugin} from 'fancy-mocha' | ||
|
||
/** | ||
* ensures that a dxcli command or hook exits | ||
* | ||
* @param code - expected code | ||
* @default 0 | ||
*/ | ||
export default (code = 0) => { | ||
const plugin = (() => { | ||
export default (code = 0) => ({ | ||
run() { | ||
throw new Error(`Expected hook to exit with code ${code} but it ran without exiting`) | ||
}) as Plugin | ||
plugin.catch = context => { | ||
const err = context.error | ||
}, | ||
catch(ctx: {error: any}) { | ||
const err = ctx.error | ||
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}`) | ||
} | ||
} | ||
return plugin | ||
} | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import * as path from 'path' | ||
|
||
import test, {expect} from '../src' | ||
import fancy, {expect} from '../src' | ||
|
||
const root = path.join(__dirname, 'fixtures/multi') | ||
|
||
describe('command', () => { | ||
test() | ||
fancy | ||
.stdout() | ||
.command(['foo:bar'], {root}) | ||
.run(output => expect(output.stdout).to.equal('hello world!\n')) | ||
.end('runs foo:bar') | ||
.do(output => expect(output.stdout).to.equal('hello world!\n')) | ||
.it() | ||
|
||
test() | ||
fancy | ||
.stdout() | ||
.command(['foo:bar', '--name=foo'], {root}) | ||
.run(output => expect(output.stdout).to.equal('hello foo!\n')) | ||
.end('runs foo:bar') | ||
.do(output => expect(output.stdout).to.equal('hello foo!\n')) | ||
.it() | ||
|
||
test() | ||
fancy | ||
.stdout() | ||
.command(['foo:bar', '--name=foo'], {root}) | ||
.run(output => expect(output.stdout).to.equal('hello foo!\n')) | ||
.end('runs foo:bar') | ||
.do(output => expect(output.stdout).to.equal('hello foo!\n')) | ||
.it() | ||
}) |
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,27 +1,27 @@ | ||
import * as path from 'path' | ||
|
||
import {expect, test} from '../src' | ||
import fancy, {expect} from '../src' | ||
|
||
describe('hooks', () => { | ||
const stdout = `test/0.0.0 (${process.platform}-${process.arch}) node-${process.version}\n` | ||
const root = path.join(__dirname, 'fixtures/multi') | ||
|
||
test() | ||
fancy | ||
.stdout() | ||
.hook('init', {id: '-v'}, {root}) | ||
.exit(0) | ||
.run(output => expect(output.stdout).to.equal(stdout)) | ||
.end('catches -v') | ||
.do(output => expect(output.stdout).to.equal(stdout)) | ||
.it('catches -v') | ||
|
||
test() | ||
fancy | ||
.stdout() | ||
.hook('init', {id: '--version'}, {root}) | ||
.exit(0) | ||
.run(output => expect(output.stdout).to.equal(stdout)) | ||
.end('catches --version') | ||
.do(output => expect(output.stdout).to.equal(stdout)) | ||
.it('catches --version') | ||
|
||
test() | ||
fancy | ||
.stdout() | ||
.hook('init', {}, {root}) | ||
.end('does not fail') | ||
.it() | ||
}) |
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