forked from sindresorhus/alfy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support setting Alfred variables with alfy.output (sindresorhus#43)
- Loading branch information
C. Thomas Bailey
committed
Jan 12, 2017
1 parent
c21377f
commit 979febc
Showing
4 changed files
with
120 additions
and
3 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import test from 'ava'; | ||
import hookStd from 'hook-std'; | ||
import {alfy} from './_utils'; | ||
|
||
const m = alfy(); | ||
|
||
test.cb('.output() properly wraps item.variables', t => { | ||
const unhook = hookStd.stdout({silent: true}, output => { | ||
unhook(); | ||
const item = JSON.parse(output).items[0]; | ||
const arg = JSON.parse(item.arg); | ||
t.deepEqual(arg, { | ||
alfredworkflow: { | ||
arg: '🦄', | ||
variables: {fabulous: true} | ||
} | ||
}); | ||
t.end(); | ||
}); | ||
m.output([{ | ||
title: 'unicorn', | ||
arg: '🦄', | ||
variables: {fabulous: true} | ||
}]); | ||
}); | ||
|
||
test.cb('.output() wraps item.variables even if item.arg is not defined', t => { | ||
const unhook = hookStd.stdout({silent: true}, output => { | ||
unhook(); | ||
const item = JSON.parse(output).items[0]; | ||
const arg = JSON.parse(item.arg); | ||
t.deepEqual(arg, { | ||
alfredworkflow: { | ||
variables: {fabulous: true} | ||
} | ||
}); | ||
t.end(); | ||
}); | ||
m.output([{ | ||
title: 'unicorn', | ||
variables: {fabulous: true} | ||
}]); | ||
}); | ||
|
||
test.cb('.output() does not wrap item.arg if item.variables is not defined', t => { | ||
const unhook = hookStd.stdout({silent: true}, output => { | ||
unhook(); | ||
const item = JSON.parse(output).items[0]; | ||
t.is(item.arg, '🦄'); | ||
t.is(item.variables, undefined); | ||
t.end(); | ||
}); | ||
m.output([{ | ||
title: 'unicorn', | ||
arg: '🦄' | ||
}]); | ||
}); | ||
|
||
test('.output() accepts null and undefined items', t => { | ||
const unhook = hookStd.stdout({silent: true}, () => unhook()); | ||
t.notThrows(() => m.output([undefined, null])); | ||
}); | ||
|
||
test('.output() accepts non-arrays', t => { | ||
let done = false; | ||
const unhook = hookStd.stdout({silent: true}, () => { | ||
if (done) { | ||
unhook(); | ||
} | ||
}); | ||
t.notThrows(() => m.output({})); | ||
t.notThrows(() => m.output('unicorn')); | ||
t.notThrows(() => m.output(null)); | ||
done = true; | ||
t.notThrows(() => m.output(undefined)); | ||
}); |