@@ -9,15 +9,11 @@ import {LinkResult, LinkState} from '../src/index';
9
9
// eslint-disable-next-line prefer-arrow-callback
10
10
describe ( 'cli' , function ( ) {
11
11
let server : http . Server ;
12
- this . timeout ( 60_000 ) ;
12
+ this . timeout ( 10_000 ) ;
Has conversations. Original line has conversations. 13
13
14
- if ( process . env . LINKINATOR_SKIP_CLI_TESTS ) {
15
- return ;
16
- }
17
-
18
- before ( async ( ) => {
19
- await execa ( 'npm' , [ 'link' ] ) ;
20
- } ) ;
14
+ const pkg = require ( '../../package.json' ) ;
15
+ const linkinator = pkg . bin . linkinator ;
16
+ const node = 'node' ;
21
17
22
18
afterEach ( async ( ) => {
23
19
if ( server ) {
@@ -26,34 +22,39 @@ describe('cli', function () {
26
22
} ) ;
27
23
28
24
it ( 'should show output for failures' , async ( ) => {
29
- const res = await execa ( 'linkinator' , [ 'test/fixtures/basic' ] , {
25
+ const res = await execa ( node , [ linkinator , 'test/fixtures/basic' ] , {
30
26
reject : false ,
31
27
} ) ;
32
28
assert . match ( res . stderr , / E R R O R : D e t e c t e d 1 b r o k e n l i n k s / ) ;
33
29
} ) ;
34
30
35
31
it ( 'should pass successful markdown scan' , async ( ) => {
36
- const res = await execa ( 'linkinator' , [ 'test/fixtures/markdown/README.md' ] ) ;
32
+ const res = await execa ( node , [
33
+ linkinator ,
34
+ 'test/fixtures/markdown/README.md' ,
35
+ ] ) ;
37
36
assert . match ( res . stderr , / S u c c e s s f u l l y s c a n n e d / ) ;
38
37
} ) ;
39
38
40
39
it ( 'should allow multiple paths' , async ( ) => {
41
- const res = await execa ( 'linkinator' , [
40
+ const res = await execa ( node , [
41
+ linkinator ,
42
42
'test/fixtures/markdown/unlinked.md' ,
43
43
'test/fixtures/markdown/README.md' ,
44
44
] ) ;
45
45
assert . match ( res . stderr , / S u c c e s s f u l l y s c a n n e d / ) ;
46
46
} ) ;
47
47
48
48
it ( 'should show help if no params are provided' , async ( ) => {
49
- const res = await execa ( ' linkinator' , {
49
+ const res = await execa ( node , [ linkinator ] , {
50
50
reject : false ,
51
51
} ) ;
52
52
assert . match ( res . stdout , / \$ l i n k i n a t o r L O C A T I O N \[ - - a r g u m e n t s \] / ) ;
53
53
} ) ;
54
54
55
55
it ( 'should flag skipped links' , async ( ) => {
56
- const res = await execa ( 'linkinator' , [
56
+ const res = await execa ( node , [
57
+ linkinator ,
57
58
'--verbosity' ,
58
59
'INFO' ,
59
60
'--skip' ,
@@ -64,7 +65,8 @@ describe('cli', function () {
64
65
} ) ;
65
66
66
67
it ( 'should provide CSV if asked nicely' , async ( ) => {
67
- const res = await execa ( 'linkinator' , [
68
+ const res = await execa ( node , [
69
+ linkinator ,
68
70
'--format' ,
69
71
'csv' ,
70
72
'test/fixtures/markdown/README.md' ,
@@ -73,7 +75,8 @@ describe('cli', function () {
73
75
} ) ;
74
76
75
77
it ( 'should provide JSON if asked nicely' , async ( ) => {
76
- const res = await execa ( 'linkinator' , [
78
+ const res = await execa ( node , [
79
+ linkinator ,
77
80
'--format' ,
78
81
'json' ,
79
82
'test/fixtures/markdown/README.md' ,
@@ -83,15 +86,17 @@ describe('cli', function () {
83
86
} ) ;
84
87
85
88
it ( 'should not show links if --silent' , async ( ) => {
86
- const res = await execa ( 'linkinator' , [
89
+ const res = await execa ( node , [
90
+ linkinator ,
87
91
'--silent' ,
88
92
'test/fixtures/markdown/README.md' ,
89
93
] ) ;
90
94
assert . notMatch ( res . stdout , / \[ / ) ;
91
95
} ) ;
92
96
93
97
it ( 'should not show 200 links if verbosity is ERROR with JSON' , async ( ) => {
94
- const res = await execa ( 'linkinator' , [
98
+ const res = await execa ( node , [
99
+ linkinator ,
95
100
'--verbosity' ,
96
101
'ERROR' ,
97
102
'--format' ,
@@ -105,7 +110,8 @@ describe('cli', function () {
105
110
} ) ;
106
111
107
112
it ( 'should accept a server-root' , async ( ) => {
108
- const res = await execa ( 'linkinator' , [
113
+ const res = await execa ( node , [
114
+ linkinator ,
109
115
'--markdown' ,
110
116
'--server-root' ,
111
117
'test/fixtures/markdown' ,
@@ -115,24 +121,29 @@ describe('cli', function () {
115
121
} ) ;
116
122
117
123
it ( 'should accept globs' , async ( ) => {
118
- const res = await execa ( 'linkinator' , [
124
+ const res = await execa ( node , [
125
+ linkinator ,
119
126
'test/fixtures/markdown/*.md' ,
120
127
'test/fixtures/markdown/**/*.md' ,
121
128
] ) ;
122
129
assert . match ( res . stderr , / S u c c e s s f u l l y s c a n n e d / ) ;
123
130
} ) ;
124
131
125
132
it ( 'should throw on invalid format' , async ( ) => {
126
- const res = await execa ( 'linkinator' , [ './README.md' , '--format' , 'LOL' ] , {
127
- reject : false ,
128
- } ) ;
133
+ const res = await execa (
134
+ node ,
135
+ [ linkinator , './README.md' , '--format' , 'LOL' ] ,
136
+ {
137
+ reject : false ,
138
+ }
139
+ ) ;
129
140
assert . match ( res . stderr , / F O R M A T m u s t b e / ) ;
130
141
} ) ;
131
142
132
143
it ( 'should throw on invalid verbosity' , async ( ) => {
133
144
const res = await execa (
134
- 'linkinator' ,
135
- [ './README.md' , '--VERBOSITY' , 'LOL' ] ,
145
+ node ,
146
+ [ linkinator , './README.md' , '--VERBOSITY' , 'LOL' ] ,
136
147
{
137
148
reject : false ,
138
149
}
@@ -142,8 +153,8 @@ describe('cli', function () {
142
153
143
154
it ( 'should throw when verbosity and silent are flagged' , async ( ) => {
144
155
const res = await execa (
145
- 'linkinator' ,
146
- [ './README.md' , '--verbosity' , 'DEBUG' , '--silent' ] ,
156
+ node ,
157
+ [ linkinator , './README.md' , '--verbosity' , 'DEBUG' , '--silent' ] ,
147
158
{
148
159
reject : false ,
149
160
}
@@ -153,8 +164,8 @@ describe('cli', function () {
153
164
154
165
it ( 'should show no output for verbosity=NONE' , async ( ) => {
155
166
const res = await execa (
156
- 'linkinator' ,
157
- [ 'test/fixtures/basic' , '--verbosity' , 'NONE' ] ,
167
+ node ,
168
+ [ linkinator , 'test/fixtures/basic' , '--verbosity' , 'NONE' ] ,
158
169
{
159
170
reject : false ,
160
171
}
@@ -166,8 +177,8 @@ describe('cli', function () {
166
177
167
178
it ( 'should show callstacks for verbosity=DEBUG' , async ( ) => {
168
179
const res = await execa (
169
- 'linkinator' ,
170
- [ 'test/fixtures/basic' , '--verbosity' , 'DEBUG' ] ,
180
+ node ,
181
+ [ linkinator , 'test/fixtures/basic' , '--verbosity' , 'DEBUG' ] ,
171
182
{
172
183
reject : false ,
173
184
}
@@ -177,7 +188,8 @@ describe('cli', function () {
177
188
} ) ;
178
189
179
190
it ( 'should allow passing a config' , async ( ) => {
180
- const res = await execa ( 'linkinator' , [
191
+ const res = await execa ( node , [
192
+ linkinator ,
181
193
'test/fixtures/basic' ,
182
194
'--config' ,
183
195
'test/fixtures/config/skip-array-config.json' ,
@@ -207,7 +219,8 @@ describe('cli', function () {
207
219
enableDestroy ( server ) ;
208
220
await new Promise < void > ( r => server . listen ( port , r ) ) ;
209
221
210
- const res = await execa ( 'linkinator' , [
222
+ const res = await execa ( node , [
223
+ linkinator ,
211
224
'--retry' ,
212
225
'test/fixtures/retryCLI' ,
213
226
] ) ;