-
-
Notifications
You must be signed in to change notification settings - Fork 210
/
cli.js
156 lines (132 loc) · 3.81 KB
/
cli.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module alex:test:cli
* @fileoverview Test suite for alex.
*/
'use strict'
/* Dependencies. */
var path = require('path')
var test = require('ava')
var execa = require('execa')
test('version', function(t) {
return execa.stdout('./cli.js', ['-v']).then(function(result) {
t.is(result, require('../package').version)
})
})
test('help', function(t) {
return execa.stdout('./cli.js', ['-h']).then(function(result) {
t.regex(result, /Usage: alex \[<glob> ...] /)
})
})
test('stdin', function(t) {
return execa
.stderr('./cli.js', ['--stdin'], {input: 'His'})
.catch(function(err) {
t.is(
err.stderr,
[
'<stdin>',
' 1:1-1:4 warning `His` may be insensitive, use `Their`, `Theirs`, `Them` instead her-him retext-equality',
'',
'⚠ 1 warning',
''
].join('\n')
)
})
})
test('stdin and globs', function(t) {
var rp = path.join('test', 'fixtures', 'one.md')
return execa
.stderr('./cli.js', ['--stdin', rp], {input: 'His'})
.catch(function(err) {
t.regex(err.stderr, /Do not pass globs with `--stdin`/)
})
})
test('markdown by default', function(t) {
var rp = path.join('test', 'fixtures', 'one.md')
return execa.stderr('./cli.js', [rp]).then(function(result) {
t.is(result, rp + ': no issues found')
})
})
test('text optional', function(t) {
var rp = path.join('test', 'fixtures', 'one.md')
return execa.stderr('./cli.js', [rp, '--text']).catch(function(err) {
t.is(
err.stderr,
[
rp,
' 1:18-1:21 warning `his` may be insensitive, use `their`, `theirs`, `them` instead her-him retext-equality',
'',
'⚠ 1 warning',
''
].join('\n')
)
})
})
test('successful files', function(t) {
var rp = path.join('test', 'fixtures', 'ok.txt')
return execa.stderr('./cli.js', [rp]).then(function(result) {
t.is(result, rp + ': no issues found')
})
})
test('quiet on ok files', function(t) {
var fp = path.join(__dirname, 'fixtures', 'ok.txt')
return execa.stderr('./cli.js', [fp, '-q']).then(function(result) {
t.is(result, '')
})
})
test('quiet on nok files', function(t) {
var rp = path.join('test', 'fixtures', 'one.md')
return execa.stderr('./cli.js', [rp, '--text']).catch(function(err) {
t.is(
err.stderr,
[
rp,
' 1:18-1:21 warning `his` may be insensitive, use `their`, `theirs`, `them` instead her-him retext-equality',
'',
'⚠ 1 warning',
''
].join('\n')
)
})
})
test('binary (default)', function(t) {
var rp = path.join('test', 'fixtures', 'binary', 'two.md')
return execa.stderr('./cli.js', [rp]).then(function(result) {
t.is(result, rp + ': no issues found')
})
})
test('non-binary (optional)', function(t) {
var rp = path.join('test', 'fixtures', 'non-binary', 'two.md')
return execa.stderr('./cli.js', [rp]).catch(function(err) {
var expected = [
rp,
' 1:1-1:3 warning `He` may be insensitive, use `They`, `It` instead he-she retext-equality',
' 1:7-1:10 warning `she` may be insensitive, use `they`, `it` instead he-she retext-equality',
'',
'⚠ 2 warnings',
''
].join('\n')
t.is(err.stderr, expected)
})
})
test('default globs', function(t) {
return execa.stderr('./cli.js').catch(function(err) {
var expected = [
'code-of-conduct.md',
' 1:1 error Cannot process specified file: it’s ignored',
'',
'contributing.md: no issues found',
'example.md',
' 1:1 error Cannot process specified file: it’s ignored',
'',
'readme.md: no issues found',
'',
'✖ 2 errors',
''
].join('\n')
t.is(err.stderr, expected)
})
})