-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
92 lines (71 loc) · 1.83 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var test = require('tessed').namespace('run')
var run = require('.')
var flag = require('@cli/flag')
var command = require('@cli/command')
var alias = require('@cli/alias')
var handler = require('@cli/handler')
var app = require('@cli/app')
test('run commands and flags', function (t) {
t.plan(7)
var c = command(
alias('test'),
handler(function (context) {
t.deepEqual(context.data, ['test'], 'command data context')
t.deepEqual(context.flags, {t: 'value'}, 'flag context')
t.deepEqual(context.options, {key: 'value'}, 'options context')
})
)
var f = flag(
alias('-t', '--test'),
handler(function (value, context) {
t.equal(value, value, 'flag value')
t.deepEqual(context.data, ['test'], 'command data context')
t.deepEqual(context.flags, {t: 'value'}, 'flag context')
t.deepEqual(context.options, {flag: 'options'}, 'options context')
})
)
var cli = app(
c({key: 'value'}),
f({flag: 'options'})
)
run(['test', '-t', 'value'], cli())
})
test('runs command-flags', function (t) {
var results = []
var globalFlag = flag(
alias('--f1'),
handler(function () {
results.push('global flag')
})
)
var commandFlag = flag(
alias('--f2'),
handler(function () {
results.push('command flag')
})
)
var testCommand = command(
alias('test'),
handler(function () {
results.push('command')
}),
commandFlag()
)
var cli = app(
testCommand(),
globalFlag()
)
run(['test', '--f2', '--f1'], cli())
t.deepEqual(results, [
'global flag',
'command flag',
'command'
], 'order of execution')
results = []
run(['test', '--f1', '--f2'], cli())
t.deepEqual(results, [
'global flag',
'command flag',
'command'
], 'order of execution is the same no matter the input order')
})