@@ -1,425 +1,1302 @@
1−'use strict';
1+'use strict'
22
3−var fs = require('fs');
4−var path = require('path');
5−var test = require('tape');
6−var execa = require('execa');
7−var remark = require('remark');
8−var strip = require('strip-ansi');
9−var links = require('..');
3+var fs = require('fs')
4+var path = require('path')
5+var childProcess = require('child_process')
6+var test = require('tape')
7+var vfile = require('to-vfile')
8+var remark = require('remark')
9+var strip = require('strip-ansi')
10+var rimraf = require('rimraf')
11+var sort = require('./sort')
12+var links = require('..')
1013
11−process.chdir(path.resolve(process.cwd(), 'test', 'fixtures'));
14+process.chdir(path.resolve(process.cwd(), 'test', 'fixtures'))
1215
1316test.onFinish(function () {
14− process.chdir(path.resolve(process.cwd(), '..', '..'));
15−});
17+ process.chdir(path.resolve(process.cwd(), '..', '..'))
18+})
1619
17−var bin = path.join('..', '..', 'node_modules', '.bin', 'remark');
18−
19−var source = ' remark-validate-links remark-validate-links';
20+var bin = path.join('..', '..', 'node_modules', '.bin', 'remark')
2021
2122test('remark-validate-links', function (t) {
22− t.plan(12);
23−
24− t.throws(
25− function () {
26− remark().use(links).freeze();
27− },
28− /Error: remark-validate-links only works on the CLI/,
29− 'should throw an error when not on the CLI'
30− );
31−
32− t.test('should throw on unparsable git repositories', function (st) {
33− st.plan(1);
34−
35− execa(bin, [
36− '--no-config',
37− '--no-ignore',
38− '--use',
39− '../..=repository:"invalid:shortcode"',
40− 'definitions.md'
41− ]).then(function () {
42− st.fail('should not be successful');
43− }, function (err) {
44− st.equal(
45− strip(err.stderr).split('\n').slice(0, 2).join('\n'),
23+ t.test('should work on the API', function (st) {
24+ st.plan(1)
25+
26+ remark()
27+ .use(links)
28+ .use(sort)
29+ .process(vfile.readSync('github.md'), function (err, file) {
30+ st.deepEqual(
31+ [err].concat(file.messages.map(String)),
32+ [
33+ null,
34+ 'github.md:5:37-5:51: Link to unknown heading: `world`',
35+ 'github.md:27:10-27:37: Link to unknown file: `examples/world.md`',
36+ 'github.md:29:10-29:35: Link to unknown file: `examples/world.md`',
37+ 'github.md:49:10-49:40: Link to unknown file: `examples/world.md`',
38+ 'github.md:51:10-51:38: Link to unknown file: `examples/world.md`'
39+ ],
40+ 'should report messages'
41+ )
42+ })
43+ })
44+
45+ t.test('should ignore invalid repositories', function (st) {
46+ st.plan(1)
47+
48+ childProcess.exec(
49+ [
50+ bin,
51+ '--no-config',
52+ '--no-ignore',
53+ '--use',
54+ '"../..=repository:\\"invalid:shortcode\\""',
55+ '--use',
56+ '../sort',
57+ 'small.md'
58+ ].join(' '),
59+ onexec
60+ )
61+
62+ function onexec(err, stdout, stderr) {
63+ st.deepEqual(
64+ [err, strip(stderr)],
65+ [
66+ null,
67+ [
68+ 'small.md',
69+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
70+ '',
71+ '⚠ 1 warning',
72+ ''
73+ ].join('\n')
74+ ],
75+ 'should work'
76+ )
77+ }
78+ })
79+
80+ t.test('should throw on Gist repositories', function (st) {
81+ st.plan(1)
82+
83+ childProcess.exec(
84+ [
85+ bin,
86+ '--no-config',
87+ '--no-ignore',
88+ '--use',
89+ '"../..=repository:\\"gist:wooorm/8504606\\""',
90+ '--use',
91+ '../sort',
92+ 'small.md'
93+ ].join(' '),
94+ onexec
95+ )
96+
97+ function onexec(err, stdout, stderr) {
98+ st.deepEqual(
99+ [err, strip(stderr)],
46100 [
47− 'definitions.md',
48− ' 1:1 error Error: remark-validate-links cannot parse `repository` (`invalid:shortcode`)'
49− ].join('\n'),
50− 'should report an error'
51− );
52− });
53− });
54−
55− t.test('should throw on gist repositories', function (st) {
56− st.plan(1);
57−
58− execa(bin, [
59− '--no-config',
60− '--no-ignore',
61− '--use',
62− '../..=repository:"gist:wooorm/8504606"',
63− 'definitions.md'
64− ]).then(function () {
65− st.fail('should not be successful');
66− }, function (err) {
67− st.equal(
68− strip(err.stderr).split('\n').slice(0, 2).join('\n'),
101+ null,
102+ [
103+ 'small.md',
104+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
105+ '',
106+ '⚠ 1 warning',
107+ ''
108+ ].join('\n')
109+ ],
110+ 'should work'
111+ )
112+ }
113+ })
114+
115+ t.test('should ignore unfound files (#1)', function (st) {
116+ st.plan(1)
117+
118+ childProcess.exec(
119+ [
120+ bin,
121+ '--no-config',
122+ '--no-ignore',
123+ '--use',
124+ '../..',
125+ '--use',
126+ '../sort',
127+ 'FOOOO'
128+ ].join(' '),
129+ onexec
130+ )
131+
132+ function onexec(err, stdout, stderr) {
133+ st.deepEqual(
134+ [/command failed/i.test(err), strip(stderr)],
69135 [
70− 'definitions.md',
71− ' 1:1 error Error: remark-validate-links does not support gist repositories'
72− ].join('\n'),
73− 'should report an error'
74− );
75− });
76− });
77−
78− t.test('should ignore unfound files', function (st) {
79− st.plan(1);
80−
81− execa(bin, [
82− '--no-config',
83− '--no-ignore',
84− '--use',
85− '../..',
86− 'definitions.md',
87− 'FOOOO'
88− ]).then(function () {
89− st.fail('should not be successful');
90− }, function (err) {
91− st.equal(
92− strip(err.stderr),
136+ true,
137+ [
138+ 'FOOOO',
139+ ' 1:1 error No such file or directory',
140+ '',
141+ '✖ 1 error',
142+ ''
143+ ].join('\n')
144+ ],
145+ 'should work'
146+ )
147+ }
148+ })
149+
150+ t.test('should ignore unfound files (#2)', function (st) {
151+ st.plan(1)
152+
153+ childProcess.exec(
154+ [
155+ bin,
156+ '--no-config',
157+ '--no-ignore',
158+ '--use',
159+ '../..',
160+ '--use',
161+ '../sort',
162+ 'definitions.md',
163+ 'FOOOO'
164+ ].join(' '),
165+ onexec
166+ )
167+
168+ function onexec(err, stdout, stderr) {
169+ st.deepEqual(
170+ [/command failed/i.test(err), strip(stderr)],
93171 [
94− 'FOOOO',
95− ' 1:1 error No such file or directory',
96− '',
97− 'definitions.md',
98− ' 5:12-5:21 warning Link to unknown heading: `world`' + source,
99− '',
100− '2 messages (✖ 1 error, ⚠ 1 warning)',
101− ''
102− ].join('\n'),
103− 'should report an error'
104− );
105− });
106− });
172+ true,
173+ [
174+ 'FOOOO',
175+ ' 1:1 error No such file or directory',
176+ '',
177+ 'definitions.md',
178+ ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links',
179+ '',
180+ '2 messages (✖ 1 error, ⚠ 1 warning)',
181+ ''
182+ ].join('\n')
183+ ],
184+ 'should work'
185+ )
186+ }
187+ })
188+
189+ t.test('should work if there are no links', function (st) {
190+ st.plan(1)
191+
192+ childProcess.exec(
193+ [
194+ bin,
195+ '--no-config',
196+ '--no-ignore',
197+ '--use',
198+ '../..',
199+ '--use',
200+ '../sort',
201+ 'empty.md'
202+ ].join(' '),
203+ onexec
204+ )
205+
206+ function onexec(err, stdout, stderr) {
207+ st.deepEqual(
208+ [err, strip(stderr)],
209+ [null, 'empty.md: no issues found\n'],
210+ 'should work'
211+ )
212+ }
213+ })
214+
215+ t.test('should work with stdin', function (st) {
216+ st.plan(1)
217+
218+ var subprocess = childProcess.exec(
219+ [
220+ bin,
221+ '--no-config',
222+ '--no-ignore',
223+ '--use',
224+ '../..',
225+ '--use',
226+ '../sort'
227+ ].join(' '),
228+ onexec
229+ )
230+
231+ fs.createReadStream('github.md').pipe(subprocess.stdin)
232+
233+ function onexec(err, stdout, stderr) {
234+ st.deepEqual(
235+ [err, strip(stderr)],
236+ [
237+ null,
238+ [
239+ '<stdin>',
240+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
241+ '',
242+ '⚠ 1 warning',
243+ ''
244+ ].join('\n')
245+ ],
246+ 'should work'
247+ )
248+ }
249+ })
107250
108251 t.test('should work when not all files are given', function (st) {
109− st.plan(1);
110−
111− execa(bin, [
112− '--no-config',
113− '--no-ignore',
114− '--use',
115− '../..',
116− 'github.md'
117− ]).then(function (result) {
118− st.equal(
119− strip(result.stderr),
252+ st.plan(1)
253+
254+ childProcess.exec(
255+ [
256+ bin,
257+ '--no-config',
258+ '--no-ignore',
259+ '--use',
260+ '../..',
261+ '--use',
262+ '../sort',
263+ 'github.md'
264+ ].join(' '),
265+ onexec
266+ )
267+
268+ function onexec(err, stdout, stderr) {
269+ st.deepEqual(
270+ [err, strip(stderr)],
120271 [
121− 'github.md',
122− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
123− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` ' + source,
124− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` ' + source,
125− ' 37:10-37:41 warning Link to unknown heading in `examples/github.md`: `world`' + source,
126− ' 39:10-39:39 warning Link to unknown heading in `examples/github.md`: `world`' + source,
127− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` ' + source,
128− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
129− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` ' + source,
130− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
131− '',
132− '⚠ 9 warnings'
133− ].join('\n'),
134− 'should report'
135− );
136− }, st.error);
137− });
272+ null,
273+ [
274+ 'github.md',
275+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
276+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
277+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
278+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
279+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
280+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
281+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
282+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
283+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
284+ '',
285+ '⚠ 9 warnings',
286+ ''
287+ ].join('\n')
288+ ],
289+ 'should work'
290+ )
291+ }
292+ })
138293
139294 t.test('should work when all files are given', function (st) {
140− st.plan(1);
141−
142− execa(bin, [
143− '--no-config',
144− '--no-ignore',
145− '--use',
146− '../..',
147− 'github.md',
148− 'examples/github.md'
149− ]).then(function (result) {
150− st.equal(
151− strip(result.stderr),
295+ st.plan(1)
296+
297+ childProcess.exec(
298+ [
299+ bin,
300+ '--no-config',
301+ '--no-ignore',
302+ '--use',
303+ '../..',
304+ '--use',
305+ '../sort',
306+ 'github.md',
307+ 'examples/github.md'
308+ ].join(' '),
309+ onexec
310+ )
311+
312+ function onexec(err, stdout, stderr) {
313+ st.deepEqual(
314+ [err, strip(stderr)],
152315 [
153− 'examples/github.md',
154− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
155− ' 19:10-19:29 warning Link to unknown file: `world.md` ' + source,
156− ' 29:10-29:33 warning Link to unknown heading in `github.md`: `world` ' + source,
157− ' 35:10-35:32 warning Link to unknown file: `world.md` ' + source,
158− ' 35:10-35:32 warning Link to unknown heading in `world.md`: `hello` ' + source,
159− '',
160− 'github.md',
161− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
162− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` ' + source,
163− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` ' + source,
164− ' 37:10-37:41 warning Link to unknown heading in `examples/github.md`: `world`' + source,
165− ' 39:10-39:39 warning Link to unknown heading in `examples/github.md`: `world`' + source,
166− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` ' + source,
167− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
168− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` ' + source,
169− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
170− '',
171− '⚠ 14 warnings'
172− ].join('\n'),
173− 'should report'
174− );
175− }, st.error);
176− });
316+ null,
317+ [
318+ 'examples/github.md',
319+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
320+ ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
321+ ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
322+ ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
323+ ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
324+ '',
325+ 'github.md',
326+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
327+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
328+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
329+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
330+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
331+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
332+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
333+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
334+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
335+ '',
336+ '⚠ 14 warnings',
337+ ''
338+ ].join('\n')
339+ ],
340+ 'should work'
341+ )
342+ }
343+ })
177344
178345 t.test('should work with definitions', function (st) {
179− st.plan(1);
180−
181− execa(bin, [
182− '--no-config',
183− '--no-ignore',
184− '--use',
185− '../..',
186− 'definitions.md'
187− ]).then(function (result) {
188− st.equal(
189− strip(result.stderr),
346+ st.plan(1)
347+
348+ childProcess.exec(
349+ [
350+ bin,
351+ '--no-config',
352+ '--no-ignore',
353+ '--use',
354+ '../..',
355+ '--use',
356+ '../sort',
357+ 'definitions.md'
358+ ].join(' '),
359+ onexec
360+ )
361+
362+ function onexec(err, stdout, stderr) {
363+ st.deepEqual(
364+ [err, strip(stderr)],
190365 [
191− 'definitions.md',
192− ' 5:12-5:21 warning Link to unknown heading: `world`' + source,
193− '',
194− '⚠ 1 warning'
195− ].join('\n'),
196− 'should report'
197− );
198− }, st.error);
199− });
366+ null,
367+ [
368+ 'definitions.md',
369+ ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links',
370+ '',
371+ '⚠ 1 warning',
372+ ''
373+ ].join('\n')
374+ ],
375+ 'should work'
376+ )
377+ }
378+ })
200379
201380 t.test('should work on GitHub URLs when given a repo', function (st) {
202− st.plan(1);
203−
204− execa(bin, [
205− '--no-config',
206− '--no-ignore',
207− '--use',
208− '../..=repository:"wooorm/test"',
209− 'github.md',
210− 'examples/github.md'
211− ]).then(function (result) {
212− st.equal(
213− strip(result.stderr),
381+ st.plan(1)
382+
383+ childProcess.exec(
384+ [
385+ bin,
386+ '--no-config',
387+ '--no-ignore',
388+ '--use',
389+ '"../..=repository:\\"wooorm/test\\""',
390+ '--use',
391+ '../sort',
392+ 'github.md',
393+ 'examples/github.md'
394+ ].join(' '),
395+ onexec
396+ )
397+
398+ function onexec(err, stdout, stderr) {
399+ st.deepEqual(
400+ [err, strip(stderr)],
401+ [
402+ null,
403+ [
404+ 'examples/github.md',
405+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
406+ ' 15:34-15:91 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
407+ ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
408+ ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
409+ ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
410+ ' 31:10-31:71 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
411+ ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
412+ ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
413+ ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
414+ ' 37:10-37:70 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
415+ ' 37:10-37:70 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
416+ ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
417+ ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
418+ '',
419+ 'github.md',
420+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
421+ ' 21:34-21:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
422+ ' 23:34-23:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
423+ ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
424+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
425+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
426+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
427+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
428+ ' 45:10-45:80 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
429+ ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
430+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
431+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
432+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
433+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
434+ ' 53:10-53:79 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
435+ ' 53:10-53:79 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
436+ ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
437+ ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
438+ '',
439+ '⚠ 31 warnings',
440+ ''
441+ ].join('\n')
442+ ],
443+ 'should work'
444+ )
445+ }
446+ })
447+
448+ t.test('should work when with Git directory', function (st) {
449+ st.plan(1)
450+
451+ childProcess.exec('git init', oninit)
452+
453+ function oninit(err) {
454+ if (err) {
455+ t.ifErr(err)
456+ } else {
457+ childProcess.exec(
458+ 'git remote add origin git@github.com:wooorm/test.git',
459+ onremote
460+ )
461+ }
462+ }
463+
464+ function onremote(err) {
465+ if (err) {
466+ clean()
467+ t.ifErr(err)
468+ } else {
469+ childProcess.exec(
470+ [
471+ bin,
472+ '--no-config',
473+ '--no-ignore',
474+ '--use',
475+ '../..',
476+ '--use',
477+ '../sort',
478+ 'github.md',
479+ 'examples/github.md'
480+ ].join(' '),
481+ onexec
482+ )
483+ }
484+ }
485+
486+ function onexec(err, stdout, stderr) {
487+ clean()
488+ st.deepEqual(
489+ [err, strip(stderr)],
214490 [
215− 'examples/github.md',
216− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
217− ' 15:34-15:93 warning Link to unknown file: `world.md` ' + source,
218− ' 17:12-17:72 warning Link to unknown file: `world.md` ' + source,
219− ' 19:10-19:29 warning Link to unknown file: `world.md` ' + source,
220− ' 29:10-29:33 warning Link to unknown heading in `github.md`: `world` ' + source,
221− ' 31:10-31:73 warning Link to unknown heading in `github.md`: `world` ' + source,
222− ' 33:10-33:74 warning Link to unknown heading in `github.md`: `world` ' + source,
223− ' 35:10-35:32 warning Link to unknown file: `world.md` ' + source,
224− ' 35:10-35:32 warning Link to unknown heading in `world.md`: `hello` ' + source,
225− ' 37:10-37:72 warning Link to unknown file: `world.md` ' + source,
226− ' 37:10-37:72 warning Link to unknown heading in `world.md`: `hello` ' + source,
227− ' 39:10-39:73 warning Link to unknown heading in `world.md`: `hello` ' + source,
228− ' 39:10-39:73 warning Link to unknown file: `world.md` ' + source,
229− '',
230− 'github.md',
231− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
232− ' 19:34-19:102 warning Link to unknown file: `examples/world.md` ' + source,
233− ' 21:12-21:81 warning Link to unknown file: `examples/world.md` ' + source,
234− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` ' + source,
235− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` ' + source,
236− ' 37:10-37:41 warning Link to unknown heading in `examples/github.md`: `world`' + source,
237− ' 39:10-39:39 warning Link to unknown heading in `examples/github.md`: `world`' + source,
238− ' 41:10-41:82 warning Link to unknown heading in `examples/github.md`: `world`' + source,
239− ' 43:10-43:83 warning Link to unknown heading in `examples/github.md`: `world`' + source,
240− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` ' + source,
241− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
242− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` ' + source,
243− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
244− ' 49:10-49:81 warning Link to unknown file: `examples/world.md` ' + source,
245− ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
246− ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
247− ' 51:10-51:82 warning Link to unknown file: `examples/world.md` ' + source,
248− '',
249− '⚠ 30 warnings'
250− ].join('\n'),
251− 'should report'
252− );
253− }, st.error);
254− });
255−
256− t.test('should work on GitHub URLs when with package.json', function (st) {
257− st.plan(1);
258−
259− /* `cwd` is moved to `test/fixtures`. */
260− fs.writeFileSync('./package.json', JSON.stringify({
261− repository: 'wooorm/test'
262− }, 0, 2));
491+ null,
492+ [
493+ 'examples/github.md',
494+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
495+ ' 15:34-15:91 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
496+ ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
497+ ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
498+ ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
499+ ' 31:10-31:71 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
500+ ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
501+ ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
502+ ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
503+ ' 37:10-37:70 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
504+ ' 37:10-37:70 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
505+ ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
506+ ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
507+ '',
508+ 'github.md',
509+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
510+ ' 21:34-21:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
511+ ' 23:34-23:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
512+ ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
513+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
514+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
515+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
516+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
517+ ' 45:10-45:80 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
518+ ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
519+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
520+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
521+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
522+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
523+ ' 53:10-53:79 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
524+ ' 53:10-53:79 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
525+ ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
526+ ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
527+ '',
528+ '⚠ 31 warnings',
529+ ''
530+ ].join('\n')
531+ ],
532+ 'should work'
533+ )
534+ }
263535
264536 function clean() {
265− fs.unlinkSync('./package.json');
266− }
267−
268− execa(bin, [
269− '--no-config',
270− '--no-ignore',
271− '--use',
272− '../..',
273− 'github.md',
274− 'examples/github.md'
275− ]).then(function (result) {
276− clean();
277− st.equal(
278− strip(result.stderr),
537+ rimraf.sync('./.git')
538+ }
539+ })
540+
541+ t.test('should fail w/o Git repository', function (st) {
542+ st.plan(1)
543+
544+ fs.renameSync('../../.git', '../../.git.bak')
545+
546+ childProcess.exec(
547+ [
548+ bin,
549+ '--no-config',
550+ '--no-ignore',
551+ '--use',
552+ '../..',
553+ '--use',
554+ '../sort',
555+ 'github.md'
556+ ].join(' '),
557+ onexec
558+ )
559+
560+ function onexec(err) {
561+ fs.renameSync('../../.git.bak', '../../.git')
562+ st.ok(/not a git repository/i.test(err), 'should fail')
563+ }
564+ })
565+
566+ t.test('should fail w/o Git repository w/o remote', function (st) {
567+ st.plan(1)
568+
569+ childProcess.exec('git init', oninit)
570+
571+ function oninit(err) {
572+ if (err) {
573+ t.ifErr(err)
574+ } else {
575+ childProcess.exec(
576+ [
577+ bin,
578+ '--no-config',
579+ '--no-ignore',
580+ '--use',
581+ '../..',
582+ 'github.md'
583+ ].join(' '),
584+ onexec
585+ )
586+ }
587+ }
588+
589+ function onexec(err) {
590+ rimraf.sync('./.git')
591+ st.ok(/Could not find remote origin/.test(err), 'should fail')
592+ }
593+ })
594+
595+ t.test('should work w/o Git repository w/ repo', function (st) {
596+ st.plan(1)
597+
598+ fs.renameSync('../../.git', '../../.git.bak')
599+
600+ childProcess.exec(
601+ [
602+ bin,
603+ '--no-config',
604+ '--no-ignore',
605+ '--use',
606+ '"../..=repository:\\"wooorm/test\\""',
607+ '--use',
608+ '../sort',
609+ 'small.md'
610+ ].join(' '),
611+ onexec
612+ )
613+
614+ function onexec(err, stdout, stderr) {
615+ fs.renameSync('../../.git.bak', '../../.git')
616+ st.deepEqual(
617+ [err, strip(stderr)],
279618 [
280− 'examples/github.md',
281− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
282− ' 15:34-15:93 warning Link to unknown file: `world.md` ' + source,
283− ' 17:12-17:72 warning Link to unknown file: `world.md` ' + source,
284− ' 19:10-19:29 warning Link to unknown file: `world.md` ' + source,
285− ' 29:10-29:33 warning Link to unknown heading in `github.md`: `world` ' + source,
286− ' 31:10-31:73 warning Link to unknown heading in `github.md`: `world` ' + source,
287− ' 33:10-33:74 warning Link to unknown heading in `github.md`: `world` ' + source,
288− ' 35:10-35:32 warning Link to unknown file: `world.md` ' + source,
289− ' 35:10-35:32 warning Link to unknown heading in `world.md`: `hello` ' + source,
290− ' 37:10-37:72 warning Link to unknown file: `world.md` ' + source,
291− ' 37:10-37:72 warning Link to unknown heading in `world.md`: `hello` ' + source,
292− ' 39:10-39:73 warning Link to unknown heading in `world.md`: `hello` ' + source,
293− ' 39:10-39:73 warning Link to unknown file: `world.md` ' + source,
294− '',
295− 'github.md',
296− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
297− ' 19:34-19:102 warning Link to unknown file: `examples/world.md` ' + source,
298− ' 21:12-21:81 warning Link to unknown file: `examples/world.md` ' + source,
299− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` ' + source,
300− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` ' + source,
301− ' 37:10-37:41 warning Link to unknown heading in `examples/github.md`: `world`' + source,
302− ' 39:10-39:39 warning Link to unknown heading in `examples/github.md`: `world`' + source,
303− ' 41:10-41:82 warning Link to unknown heading in `examples/github.md`: `world`' + source,
304− ' 43:10-43:83 warning Link to unknown heading in `examples/github.md`: `world`' + source,
305− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` ' + source,
306− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
307− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` ' + source,
308− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
309− ' 49:10-49:81 warning Link to unknown file: `examples/world.md` ' + source,
310− ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
311− ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
312− ' 51:10-51:82 warning Link to unknown file: `examples/world.md` ' + source,
313− '',
314− '⚠ 30 warnings'
315− ].join('\n'),
316− 'should report'
317− );
318− }, function (err) {
319− clean();
320− st.error(err);
321− });
322− });
619+ null,
620+ [
621+ 'small.md',
622+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
623+ '',
624+ '⚠ 1 warning',
625+ ''
626+ ].join('\n')
627+ ],
628+ 'should work'
629+ )
630+ }
631+ })
632+
633+ t.test('should work w/o Git repository w/ remote', function (st) {
634+ st.plan(1)
635+
636+ fs.renameSync('../../.git', '../../.git.bak')
637+
638+ childProcess.exec(
639+ [
640+ bin,
641+ '--no-config',
642+ '--no-ignore',
643+ '--use',
644+ '"../..=repository:{remote:\\"wooorm/test\\"}"',
645+ 'small.md'
646+ ].join(' '),
647+ onexec
648+ )
649+
650+ function onexec(err, stdout, stderr) {
651+ fs.renameSync('../../.git.bak', '../../.git')
652+ st.deepEqual(
653+ [err, strip(stderr)],
654+ [
655+ null,
656+ [
657+ 'small.md',
658+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
659+ '',
660+ '⚠ 1 warning',
661+ ''
662+ ].join('\n')
663+ ],
664+ 'should work'
665+ )
666+ }
667+ })
668+
669+ t.test('should work w/o Git repository w/ remote and root', function (st) {
670+ st.plan(1)
671+
672+ fs.renameSync('../../.git', '../../.git.bak')
673+
674+ childProcess.exec(
675+ [
676+ bin,
677+ '--no-config',
678+ '--no-ignore',
679+ '--use',
680+ '"../..=repository:\\"wooorm/test\\",root:\\"../\\""',
681+ 'small.md'
682+ ].join(' '),
683+ onexec
684+ )
685+
686+ function onexec(err, stdout, stderr) {
687+ fs.renameSync('../../.git.bak', '../../.git')
688+ st.deepEqual(
689+ [err, strip(stderr)],
690+ [
691+ null,
692+ [
693+ 'small.md',
694+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
695+ '',
696+ '⚠ 1 warning',
697+ ''
698+ ].join('\n')
699+ ],
700+ 'should work'
701+ )
702+ }
703+ })
704+
705+ t.test('should work with `repository:false`', function (st) {
706+ st.plan(1)
707+
708+ fs.renameSync('../../.git', '../../.git.bak')
709+
710+ childProcess.exec(
711+ [
712+ bin,
713+ '--no-config',
714+ '--no-ignore',
715+ '--use',
716+ '"../..=repository:false"',
717+ '--use',
718+ '../sort',
719+ 'github.md',
720+ 'examples/github.md'
721+ ].join(' '),
722+ onexec
723+ )
724+
725+ function onexec(err, stdout, stderr) {
726+ fs.renameSync('../../.git.bak', '../../.git')
727+ st.deepEqual(
728+ [err, strip(stderr)],
729+ [
730+ null,
731+ [
732+ 'examples/github.md',
733+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
734+ ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
735+ ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
736+ ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
737+ ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
738+ '',
739+ 'github.md',
740+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
741+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
742+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
743+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
744+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
745+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
746+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
747+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
748+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
749+ ' 71:41-71:56 warning Link to unknown heading: `readme` missing-heading remark-validate-links',
750+ '',
751+ '⚠ 15 warnings',
752+ ''
753+ ].join('\n')
754+ ],
755+ 'should work'
756+ )
757+ }
758+ })
759+
760+ t.test('should work when finding non-hosted Git remotes', function (st) {
761+ st.plan(1)
762+
763+ childProcess.exec(
764+ [
765+ bin,
766+ '--no-config',
767+ '--no-ignore',
768+ '--use',
769+ '"../..=repository:\\"ssh://git@domain.com/user/project.git\\""',
770+ '--use',
771+ '../sort',
772+ 'small.md'
773+ ].join(' '),
774+ onexec
775+ )
776+
777+ function onexec(err, stdout, stderr) {
778+ st.deepEqual(
779+ [err, strip(stderr)],
780+ [
781+ null,
782+ [
783+ 'small.md',
784+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
785+ '',
786+ '⚠ 1 warning',
787+ ''
788+ ].join('\n')
789+ ],
790+ 'should work'
791+ )
792+ }
793+ })
323794
324795 t.test('should support a GitLab shortcode', function (st) {
325− st.plan(1);
326−
327− execa(bin, [
328− '--no-config',
329− '--no-ignore',
330− '--use',
331− '../..=repository:"gitlab:wooorm/test"',
332− 'gitlab.md'
333− ]).then(function (result) {
334− st.equal(
335− strip(result.stderr),
796+ st.plan(1)
797+
798+ childProcess.exec(
799+ [
800+ bin,
801+ '--no-config',
802+ '--no-ignore',
803+ '--use',
804+ '"../..=repository:\\"gitlab:wooorm/test\\""',
805+ '--use',
806+ '../sort',
807+ 'gitlab.md'
808+ ].join(' '),
809+ onexec
810+ )
811+
812+ function onexec(err, stdout, stderr) {
813+ st.deepEqual(
814+ [err, strip(stderr)],
336815 [
337− 'gitlab.md',
338− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
339− ' 19:34-19:102 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md`' + source,
340− ' 21:12-21:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md`' + source,
341− ' 23:10-23:37 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md`' + source,
342− ' 25:10-25:35 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md`' + source,
343− ' 37:10-37:41 warning Link to unknown heading in `examples/gitlab.md`: `world` ' + source,
344− ' 39:10-39:39 warning Link to unknown heading in `examples/gitlab.md`: `world` ' + source,
345− ' 41:10-41:82 warning Link to unknown heading in `examples/gitlab.md`: `world` ' + source,
346− ' 43:10-43:83 warning Link to unknown heading in `examples/gitlab.md`: `world` ' + source,
347− ' 45:10-45:40 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md`' + source,
348− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
349− ' 47:10-47:38 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md`' + source,
350− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
351− ' 49:10-49:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md`' + source,
352− ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
353− ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
354− ' 51:10-51:82 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md`' + source,
355− '',
356− '⚠ 17 warnings'
357− ].join('\n'),
358− 'should report'
359− );
360− }, st.error);
361− });
816+ null,
817+ [
818+ 'gitlab.md',
819+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
820+ ' 19:34-19:100 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
821+ ' 21:12-21:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
822+ ' 23:10-23:37 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
823+ ' 25:10-25:35 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
824+ ' 37:10-37:41 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
825+ ' 39:10-39:39 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
826+ ' 41:10-41:80 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
827+ ' 43:10-43:83 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
828+ ' 45:10-45:40 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
829+ ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
830+ ' 47:10-47:38 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
831+ ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
832+ ' 49:10-49:79 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
833+ ' 49:10-49:79 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
834+ ' 51:10-51:82 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
835+ ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
836+ '',
837+ '⚠ 17 warnings',
838+ ''
839+ ].join('\n')
840+ ],
841+ 'should work'
842+ )
843+ }
844+ })
362845
363846 t.test('should support a Bitbucket shortcode', function (st) {
364− st.plan(1);
365−
366− execa(bin, [
367− '--no-config',
368− '--no-ignore',
369− '--use',
370− '../..=repository:"bitbucket:wooorm/test"',
371− 'bitbucket.md'
372− ]).then(function (result) {
373− st.equal(
374− strip(result.stderr),
847+ st.plan(1)
848+
849+ childProcess.exec(
850+ [
851+ bin,
852+ '--no-config',
853+ '--no-ignore',
854+ '--use',
855+ '"../..=repository:\\"bitbucket:wooorm/test\\""',
856+ '--use',
857+ '../sort',
858+ 'bitbucket.md'
859+ ].join(' '),
860+ onexec
861+ )
862+
863+ function onexec(err, stdout, stderr) {
864+ st.deepEqual(
865+ [err, strip(stderr)],
375866 [
376− 'bitbucket.md',
377− ' 5:37-5:67 warning Link to unknown heading: `world` ' + source,
378− ' 19:34-19:104 warning Link to unknown file: `examples/world.md` ' + source,
379− ' 21:12-21:83 warning Link to unknown file: `examples/world.md` ' + source,
380− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` ' + source,
381− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` ' + source,
382− ' 37:10-37:60 warning Link to unknown heading in `examples/bitbucket.md`: `world`' + source,
383− ' 39:10-39:58 warning Link to unknown heading in `examples/bitbucket.md`: `world`' + source,
384− ' 41:10-41:103 warning Link to unknown heading in `examples/bitbucket.md`: `world`' + source,
385− ' 43:10-43:104 warning Link to unknown heading in `examples/bitbucket.md`: `world`' + source,
386− ' 45:10-45:56 warning Link to unknown file: `examples/world.md` ' + source,
387− ' 45:10-45:56 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
388− ' 47:10-47:54 warning Link to unknown file: `examples/world.md` ' + source,
389− ' 47:10-47:54 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
390− ' 49:10-49:99 warning Link to unknown file: `examples/world.md` ' + source,
391− ' 49:10-49:99 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
392− ' 51:10-51:100 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
393− ' 51:10-51:100 warning Link to unknown file: `examples/world.md` ' + source,
394− '',
395− '⚠ 17 warnings'
396− ].join('\n'),
397− 'should report'
398− );
399− }, st.error);
400− });
867+ null,
868+ [
869+ 'bitbucket.md',
870+ ' 5:37-5:67 warning Link to unknown heading: `world` missing-heading remark-validate-links',
871+ ' 21:34-21:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
872+ ' 23:12-23:83 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
873+ ' 25:10-25:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
874+ ' 27:10-27:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
875+ ' 39:10-39:60 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
876+ ' 41:10-41:58 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
877+ ' 43:10-43:101 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
878+ ' 45:10-45:104 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
879+ ' 47:10-47:56 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
880+ ' 47:10-47:56 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
881+ ' 49:10-49:54 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
882+ ' 49:10-49:54 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
883+ ' 51:10-51:97 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
884+ ' 51:10-51:97 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
885+ ' 53:10-53:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
886+ ' 53:10-53:100 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
887+ '',
888+ '⚠ 17 warnings',
889+ ''
890+ ].join('\n')
891+ ],
892+ 'should work'
893+ )
894+ }
895+ })
401896
402897 t.test('should suggest similar links', function (st) {
403− st.plan(1);
404−
405− execa(bin, [
406− '--no-config',
407− '--no-ignore',
408− '--use',
409− '../..',
410− 'suggestions.md'
411− ]).then(function (result) {
412− st.equal(
413− strip(result.stderr),
898+ st.plan(1)
899+
900+ childProcess.exec(
901+ [
902+ bin,
903+ '--no-config',
904+ '--no-ignore',
905+ '--use',
906+ '../..',
907+ '--use',
908+ '../sort',
909+ 'suggestions.md'
910+ ].join(' '),
911+ onexec
912+ )
913+
914+ function onexec(err, stdout, stderr) {
915+ st.deepEqual(
916+ [err, strip(stderr)],
414917 [
415− 'suggestions.md',
416− ' 3:22-3:37 warning Link to unknown heading: `helloo`. Did you mean `hello` ' + source,
417− ' 7:17-7:39 warning Link to unknown heading in `github.md`: `fiiiles`. Did you mean `files`' + source,
418− '',
419− '⚠ 2 warnings'
420− ].join('\n'),
421− 'should report'
422− );
423− }, st.error);
424− });
425−});
918+ null,
919+ [
920+ 'suggestions.md',
921+ ' 3:22-3:37 warning Link to unknown heading: `helloo`. Did you mean `hello` missing-heading remark-validate-links',
922+ ' 7:17-7:39 warning Link to unknown heading in `github.md`: `fiiiles`. Did you mean `files` missing-heading-in-file remark-validate-links',
923+ '',
924+ '⚠ 2 warnings',
925+ ''
926+ ].join('\n')
927+ ],
928+ 'should work'
929+ )
930+ }
931+ })
932+
933+ t.test('should recognise links to particular lines', function (st) {
934+ st.plan(1)
935+
936+ childProcess.exec(
937+ [
938+ bin,
939+ '--no-config',
940+ '--no-ignore',
941+ '--use',
942+ '"../..=repository:\\"wooorm/test\\""',
943+ '--use',
944+ '../sort',
945+ 'line-links.md'
946+ ].join(' '),
947+ onexec
948+ )
949+
950+ function onexec(err, stdout, stderr) {
951+ st.deepEqual(
952+ [err, strip(stderr)],
953+ [
954+ null,
955+ [
956+ 'line-links.md',
957+ ' 5:9-5:61 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links',
958+ ' 9:1-9:69 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links',
959+ '',
960+ '⚠ 2 warnings',
961+ ''
962+ ].join('\n')
963+ ],
964+ 'should work'
965+ )
966+ }
967+ })
968+
969+ t.test('should recognise links with encoded URLs', function (st) {
970+ st.plan(1)
971+
972+ childProcess.exec(
973+ [
974+ bin,
975+ '--no-config',
976+ '--no-ignore',
977+ '--use',
978+ '"../..=repository:\\"wooorm/test\\""',
979+ '--use',
980+ '../sort',
981+ 'weird-characters.md'
982+ ].join(' '),
983+ onexec
984+ )
985+
986+ function onexec(err, stdout, stderr) {
987+ st.deepEqual(
988+ [err, strip(stderr)],
989+ [
990+ null,
991+ [
992+ 'weird-characters.md',
993+ ' 11:17-11:87 warning Link to unknown file: `examples/missing#characters.md`. Did you mean `examples/weird#characters.md` missing-file remark-validate-links',
994+ ' 13:17-13:93 warning Link to unknown file: `examples/missing#character/readme.md`. Did you mean `examples/weird#character/readme.md` missing-file remark-validate-links',
995+ ' 15:17-15:114 warning Link to unknown heading in `examples/weird#characters.md`: `world` missing-heading-in-file remark-validate-links',
996+ ' 17:17-17:120 warning Link to unknown heading in `examples/weird#character/readme.md`: `world` missing-heading-in-file remark-validate-links',
997+ '',
998+ '⚠ 4 warnings',
999+ ''
1000+ ].join('\n')
1001+ ],
1002+ 'should work'
1003+ )
1004+ }
1005+ })
1006+
1007+ t.test('should support folders', function (st) {
1008+ st.plan(1)
1009+
1010+ childProcess.exec(
1011+ [
1012+ bin,
1013+ '--no-config',
1014+ '--no-ignore',
1015+ '--use',
1016+ '"../..=repository:\\"wooorm/test\\""',
1017+ '--use',
1018+ '../sort',
1019+ 'folder.md'
1020+ ].join(' '),
1021+ onexec
1022+ )
1023+
1024+ function onexec(err, stdout, stderr) {
1025+ st.deepEqual(
1026+ [err, strip(stderr)],
1027+ [
1028+ null,
1029+ [
1030+ 'folder.md',
1031+ ' 9:1-9:40 warning Link to unknown heading in `folder/readme.markdown`: `missing` missing-heading-in-file remark-validate-links',
1032+ ' 17:1-17:24 warning Link to unknown heading in `folder`: `missing` missing-heading-in-file remark-validate-links',
1033+ ' 21:1-21:25 warning Link to unknown file: `missing` missing-file remark-validate-links',
1034+ ' 21:1-21:25 warning Link to unknown heading in `missing`: `missing` missing-heading-in-file remark-validate-links',
1035+ ' 23:1-23:39 warning Link to unknown heading in `folder-without-readme`: `missing` missing-heading-in-file remark-validate-links',
1036+ '',
1037+ '⚠ 5 warnings',
1038+ ''
1039+ ].join('\n')
1040+ ],
1041+ 'should work'
1042+ )
1043+ }
1044+ })
1045+
1046+ t.test('should warn on files as folders', function (st) {
1047+ st.plan(1)
1048+
1049+ childProcess.exec(
1050+ [
1051+ bin,
1052+ '--no-config',
1053+ '--no-ignore',
1054+ '--use',
1055+ '../..',
1056+ '--use',
1057+ '../sort',
1058+ 'file-as-folder.md'
1059+ ].join(' '),
1060+ onexec
1061+ )
1062+
1063+ function onexec(err, stdout, stderr) {
1064+ st.deepEqual(
1065+ [err, strip(stderr)],
1066+ [
1067+ null,
1068+ [
1069+ 'file-as-folder.md',
1070+ ' 1:1-1:28 warning Link to unknown file: `file-as-folder.md/other`. Did you mean `file-as-folder.md` missing-file remark-validate-links',
1071+ '',
1072+ '⚠ 1 warning',
1073+ ''
1074+ ].join('\n')
1075+ ],
1076+ 'should work'
1077+ )
1078+ }
1079+ })
1080+
1081+ t.test('should check images', function (st) {
1082+ st.plan(1)
1083+
1084+ childProcess.exec(
1085+ [
1086+ bin,
1087+ '--no-config',
1088+ '--no-ignore',
1089+ '--use',
1090+ '"../..=repository:\\"wooorm/test\\""',
1091+ '--use',
1092+ '../sort',
1093+ 'images.md'
1094+ ].join(' '),
1095+ onexec
1096+ )
1097+
1098+ function onexec(err, stdout, stderr) {
1099+ st.deepEqual(
1100+ [err, strip(stderr)],
1101+ [
1102+ null,
1103+ [
1104+ 'images.md',
1105+ ' 19:10-19:50 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1106+ ' 21:12-21:42 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1107+ ' 23:10-23:89 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1108+ ' 35:1-35:38 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1109+ ' 37:1-37:77 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1110+ '',
1111+ '⚠ 5 warnings',
1112+ ''
1113+ ].join('\n')
1114+ ],
1115+ 'should work'
1116+ )
1117+ }
1118+ })
1119+
1120+ t.test('should support query parameters', function (st) {
1121+ st.plan(1)
1122+
1123+ childProcess.exec(
1124+ [
1125+ bin,
1126+ '--no-config',
1127+ '--no-ignore',
1128+ '--use',
1129+ '"../..=repository:\\"wooorm/test\\""',
1130+ '--use',
1131+ '../sort',
1132+ 'query-params.md'
1133+ ].join(' '),
1134+ onexec
1135+ )
1136+
1137+ function onexec(err, stdout, stderr) {
1138+ st.deepEqual(
1139+ [err, strip(stderr)],
1140+ [
1141+ null,
1142+ [
1143+ 'query-params.md',
1144+ ' 9:33-9:55 warning Link to unknown heading: `query-params?`. Did you mean `query-params` missing-heading remark-validate-links',
1145+ '',
1146+ '⚠ 1 warning',
1147+ ''
1148+ ].join('\n')
1149+ ],
1150+ 'should work'
1151+ )
1152+ }
1153+ })
1154+
1155+ t.test('should support case insensitive headings', function (st) {
1156+ st.plan(1)
1157+
1158+ childProcess.exec(
1159+ [
1160+ bin,
1161+ '--no-config',
1162+ '--no-ignore',
1163+ '--use',
1164+ '../..',
1165+ '--use',
1166+ '../sort',
1167+ 'case-insensitive-headings.md'
1168+ ].join(' '),
1169+ onexec
1170+ )
1171+
1172+ function onexec(err, stdout, stderr) {
1173+ st.deepEqual(
1174+ [err, strip(stderr)],
1175+ [
1176+ null,
1177+ [
1178+ 'case-insensitive-headings.md',
1179+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
1180+ ' 9:16-9:48 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
1181+ '',
1182+ '⚠ 2 warnings',
1183+ ''
1184+ ].join('\n')
1185+ ],
1186+ 'should work'
1187+ )
1188+ }
1189+ })
1190+
1191+ t.test('should ignore external links', function (st) {
1192+ st.plan(1)
1193+
1194+ childProcess.exec(
1195+ [
1196+ bin,
1197+ '--no-config',
1198+ '--no-ignore',
1199+ '--use',
1200+ '"../..=repository:\\"wooorm/test\\""',
1201+ '--use',
1202+ '../sort',
1203+ 'external.md'
1204+ ].join(' '),
1205+ onexec
1206+ )
1207+
1208+ function onexec(err, stdout, stderr) {
1209+ st.deepEqual(
1210+ [err, strip(stderr)],
1211+ [null, 'external.md: no issues found\n'],
1212+ 'should work'
1213+ )
1214+ }
1215+ })
1216+
1217+ t.test('should ignore external links (without repo)', function (st) {
1218+ st.plan(1)
1219+
1220+ childProcess.exec(
1221+ [
1222+ bin,
1223+ '--no-config',
1224+ '--no-ignore',
1225+ '--use',
1226+ '../..=repository:false',
1227+ '--use',
1228+ '../sort',
1229+ 'external.md'
1230+ ].join(' '),
1231+ onexec
1232+ )
1233+
1234+ function onexec(err, stdout, stderr) {
1235+ st.deepEqual(
1236+ [err, strip(stderr)],
1237+ [null, 'external.md: no issues found\n'],
1238+ 'should work'
1239+ )
1240+ }
1241+ })
1242+
1243+ t.test('should support self-hosted Git solutions', function (st) {
1244+ st.plan(1)
1245+
1246+ childProcess.exec('git init', oninit)
1247+
1248+ function oninit(err) {
1249+ if (err) {
1250+ t.ifErr(err)
1251+ } else {
1252+ childProcess.exec(
1253+ 'git remote add origin git@gitlab.acme.company:acme/project.git',
1254+ onremote
1255+ )
1256+ }
1257+ }
1258+
1259+ function onremote(err) {
1260+ if (err) {
1261+ clean()
1262+ t.ifErr(err)
1263+ } else {
1264+ childProcess.exec(
1265+ [
1266+ bin,
1267+ '--no-config',
1268+ '--no-ignore',
1269+ '--use',
1270+ '"../..=urlConfig:{hostname:\\"gitlab.acme.com\\",prefix:\\"/acme/project/blob/\\",headingPrefix:\\"#\\",lines:true}"',
1271+ 'self-hosted.md'
1272+ ].join(' '),
1273+ onexec
1274+ )
1275+ }
1276+ }
1277+
1278+ function onexec(err, stdout, stderr) {
1279+ clean()
1280+ st.deepEqual(
1281+ [err, strip(stderr)],
1282+ [
1283+ null,
1284+ [
1285+ 'self-hosted.md',
1286+ ' 5:1-5:80 warning Link to unknown heading: `world` missing-heading remark-validate-links',
1287+ '',
1288+ '⚠ 1 warning',
1289+ ''
1290+ ].join('\n')
1291+ ],
1292+ 'should work'
1293+ )
1294+ }
1295+
1296+ function clean() {
1297+ rimraf.sync('./.git')
1298+ }
1299+ })
1300+
1301+ t.end()
1302+})