|
| 1 | +import test from 'ava' |
| 2 | +import {spy} from 'sinon' |
| 3 | +import proxyquire from 'proxyquire' |
| 4 | + |
| 5 | +test('inits omelette', t => { |
| 6 | + const {autocomplete, initSpy} = getAutocomplete() |
| 7 | + autocomplete() |
| 8 | + t.true(initSpy.calledOnce) |
| 9 | +}) |
| 10 | + |
| 11 | +test('calls this.reply with the available scripts', t => { |
| 12 | + const stubConfig = { |
| 13 | + scripts: { |
| 14 | + build: {default: {script: 'build'}, watch: 'build.watch', main: {umd: 'build.main.umd', default: 'build.main'}}, |
| 15 | + lint: {default: {script: 'lint', description: 'lint things'}, watch: 'lint.watch'}, |
| 16 | + test: 'test', |
| 17 | + camelCase: 'camelCase', |
| 18 | + cover: {description: 'this is a description', script: 'this is the script'}, |
| 19 | + }, |
| 20 | + } |
| 21 | + const expectedReplyArgs = [ |
| 22 | + 'build', 'build.watch', 'build.main', 'build.main.umd', |
| 23 | + 'lint', 'lint.watch', |
| 24 | + 'test', 'camel-case', 'cover', |
| 25 | + ] |
| 26 | + const {autocomplete, getReplyArgs} = getAutocomplete() |
| 27 | + autocomplete(stubConfig) |
| 28 | + const actualReplyArgs = getReplyArgs() |
| 29 | + t.deepEqual(actualReplyArgs, expectedReplyArgs) |
| 30 | +}) |
| 31 | + |
| 32 | +test('install calls setupShellInitFile with the given destination', t => { |
| 33 | + const {install, setupShellInitFileSpy} = getInstall() |
| 34 | + const destination = '~/.my_bash_profile' |
| 35 | + install(destination) |
| 36 | + const [actualDestination] = setupShellInitFileSpy.firstCall.args |
| 37 | + t.true(setupShellInitFileSpy.calledOnce) |
| 38 | + t.is(actualDestination, destination) |
| 39 | +}) |
| 40 | + |
| 41 | +test('install defaults to ~/.bash_profile', t => { |
| 42 | + const {install, setupShellInitFileSpy} = getInstall() |
| 43 | + const expectedDestination = '~/.bash_profile' |
| 44 | + install() |
| 45 | + const [actualDestination] = setupShellInitFileSpy.firstCall.args |
| 46 | + t.true(setupShellInitFileSpy.calledOnce) |
| 47 | + t.is(actualDestination, expectedDestination) |
| 48 | +}) |
| 49 | + |
| 50 | +function getAutocomplete() { |
| 51 | + const onSpy = spy() |
| 52 | + const initSpy = spy() |
| 53 | + const omelette = spy(() => { |
| 54 | + return {on: onSpy, init: initSpy} |
| 55 | + }) |
| 56 | + const autocomplete = proxyquire('./index', {omelette}).default |
| 57 | + return {autocomplete, getReplyArgs, initSpy} |
| 58 | + |
| 59 | + function getReplyArgs() { |
| 60 | + const [, replier] = onSpy.firstCall.args |
| 61 | + const reply = spy() |
| 62 | + const context = {reply} |
| 63 | + replier.call(context) |
| 64 | + return reply.firstCall.args[0] |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +function getInstall() { |
| 69 | + const setupShellInitFileSpy = spy() |
| 70 | + const omelette = spy(() => ({setupShellInitFile: setupShellInitFileSpy})) |
| 71 | + const {install} = proxyquire('./index', {omelette}) |
| 72 | + return {install, setupShellInitFileSpy} |
| 73 | +} |
0 commit comments