git.iko.soy/typeable/remark-validate-links
on main help sign in
25 files changed+1288−882
since splitsnapshots
unifiedsplit
.prettierignore+2 .travis.yml+1−1 lib/check/check-files.js+1−1 lib/find/find.js+119−22 lib/find/index.js+1−4 lib/index.js+1−1 package.json+21−15 readme.md+39−27 test/fixtures/bitbucket.md+5−5 test/fixtures/examples/bitbucket.md+5−5 test/fixtures/examples/github.md+5−5 test/fixtures/examples/gitlab.md+5−5 test/fixtures/file-as-folder.md+1 test/fixtures/folder-without-readme/example.md+1 test/fixtures/folder.md+23 test/fixtures/folder/example.md+1 test/fixtures/folder/readme.asc+9 test/fixtures/folder/readme.markdown+5 test/fixtures/folder/readme.md+1 test/fixtures/github.md+7−7 test/fixtures/gitlab.md+5−5 test/fixtures/images.md+4−4 test/fixtures/line-links.md+2−2 test/fixtures/self-hosted.md+2−2 test/index.js+1022−771
.prettierignore+2
@@ -1 +1,3 @@
11coverage/
2+*.json
3+*.md
.travis.yml+1−1
@@ -1,5 +1,5 @@
11language: node_js
22node_js:
3− - lts/carbon
3+ - lts/dubnium
44 - node
55after_success: bash <(curl -s https://codecov.io/bash)
lib/check/check-files.js+1−1
@@ -30,7 +30,7 @@ function checkIfReferencedFilesExist(ctx, next) {
3030 fs.access(filePath, fs.F_OK, onaccess)
3131
3232 function onaccess(err) {
33− var noEntry = err && err.code === 'ENOENT'
33+ var noEntry = err && (err.code === 'ENOENT' || err.code === 'ENOTDIR')
3434
3535 landmarks[filePath] = {'': !noEntry}
3636
lib/find/find.js+119−22
@@ -1,5 +1,6 @@
11'use strict'
22
3+var fs = require('fs')
34var path = require('path')
45var URL = require('url').URL // Node 8 support
56var vfile = require('to-vfile')
@@ -21,14 +22,21 @@ var slashes = '//'
2122
2223var lineExpression = /^#l\d/i
2324
24−function find(ctx) {
25+// List from: https://github.com/github/markup#markups
26+var readmeExtensions = ['.markdown', '.mdown', '.mkdn', '.md']
27+var readmeBasename = /^readme$/i
28+
29+function find(ctx, next) {
2530 var file = ctx.file
2631 var fileSet = ctx.fileSet
2732 var absolute = file.path ? path.resolve(file.cwd, file.path) : ''
2833 var space = file.data
2934 var references = {}
3035 var landmarks = {}
31− var alreadyAdded = []
36+ var actual = 0
37+ var expected = 0
38+ var statted = []
39+ var added = []
3240 var config = xtend(ctx.urlConfig, {
3341 path: absolute,
3442 base: absolute ? path.dirname(absolute) : file.cwd,
@@ -38,18 +46,21 @@ function find(ctx) {
3846 space[constants.referenceId] = references
3947 space[constants.landmarkId] = landmarks
4048
41− landmarks[absolute] = {'': true}
49+ addLandmarks(absolute, '')
4250
4351 slugs.reset()
4452
4553 visit(ctx.tree, mark)
4654
55+ if (expected === 0) {
56+ next()
57+ }
58+
4759 function mark(node) {
4860 var data = node.data || {}
4961 var props = data.hProperties || {}
5062 var id = props.name || props.id || data.id
5163 var info = node.url ? urlToPath(node.url, config) : null
52− var refs
5364 var fp
5465 var hash
5566
@@ -58,34 +69,114 @@ function find(ctx) {
5869 }
5970
6071 if (id) {
61− landmarks[absolute][id] = true
72+ addLandmarks(absolute, id)
6273 }
6374
6475 if (info) {
6576 fp = info.filePath
6677 hash = info.hash
67− refs = references[fp] || (references[fp] = {})
6878
69− add('', node)
79+ addReference(fp, '', node)
7080
71− // With a heading
7281 if (hash) {
7382 if (fileSet || fp === absolute) {
74− add(hash, node)
83+ addReference(fp, hash, node)
7584 }
7685
77− if (fileSet && fp && alreadyAdded.indexOf(fp) === -1) {
78− alreadyAdded.push(fp)
79− fileSet.add(vfile({cwd: file.cwd, path: path.relative(file.cwd, fp)}))
86+ if (fileSet && fp && statted.indexOf(fp) === -1) {
87+ addFile(fp)
8088 }
8189 }
8290 }
91+ }
92+
93+ function addLandmarks(filePath, hash) {
94+ addLandmark(filePath, hash)
95+
96+ // Note: this may add marks too many anchors as defined.
97+ // For example, if there is both a `readme.md` and a `readme.markdown` in a
98+ // folder, both their landmarks will be defined for their parent folder.
99+ // To solve this, we could check whichever sorts first, and ignore the
100+ // others.
101+ // This is an unlikely scenario though, and adds a lot of complexity, so
102+ // we’re ignoring it.
103+ if (readme(filePath)) {
104+ addLandmark(path.dirname(filePath), hash)
105+ }
106+ }
107+
108+ function addLandmark(filePath, hash) {
109+ var marks = landmarks[filePath] || (landmarks[filePath] = {})
110+
111+ marks[hash] = true
112+ }
113+
114+ function addReference(filePath, hash, node) {
115+ var refs = references[filePath] || (references[filePath] = {})
116+ var hashes = refs[hash] || (refs[hash] = [])
117+
118+ hashes.push(node)
119+ }
120+
121+ function addFile(fileOrFolderPath) {
122+ expected++
83123
84− function add(hash, node) {
85− if (refs[hash]) {
86− refs[hash].push(node)
124+ statted.push(fileOrFolderPath)
125+
126+ fs.stat(fileOrFolderPath, onstat)
127+
128+ function onstat(_, stats) {
129+ if (stats && stats.isDirectory()) {
130+ fs.readdir(fileOrFolderPath, onreaddir)
87131 } else {
88− refs[hash] = [node]
132+ done(fileOrFolderPath)
133+ }
134+ }
135+
136+ function onreaddir(_, entries) {
137+ /* istanbul ignore next - unlikely that it is an unreadable directory. */
138+ var files = (entries || []).sort()
139+ var length = files.length
140+ var index = -1
141+ var entry
142+ var file
143+ var filePath
144+
145+ while (++index < length) {
146+ entry = entries[index]
147+
148+ if (readme(entry)) {
149+ file = entry
150+ break
151+ }
152+ }
153+
154+ // If there is no readme that we can parse, add the directory.
155+ filePath = fileOrFolderPath
156+
157+ // To do: test for no readme in directory.
158+
159+ if (file) {
160+ filePath = path.join(fileOrFolderPath, file)
161+ statted.push(filePath)
162+ }
163+
164+ done(filePath)
165+ }
166+
167+ function done(filePath) {
168+ if (added.indexOf(filePath) === -1) {
169+ added.push(filePath)
170+
171+ fileSet.add(
172+ vfile({cwd: file.cwd, path: path.relative(file.cwd, filePath)})
173+ )
174+ }
175+
176+ actual++
177+
178+ if (actual === expected) {
179+ next()
89180 }
90181 }
91182 }
@@ -96,7 +187,7 @@ function urlToPath(value, config) {
96187 var questionMarkIndex
97188 var numberSignIndex
98189
99− // Absolute paths: `/wooorm/test/blob/master/directory/example.md`.
190+ // Absolute paths: `/wooorm/test/blob/main/directory/example.md`.
100191 if (value.charAt(0) === slash) {
101192 if (!config.hostname) {
102193 return
@@ -110,7 +201,7 @@ function urlToPath(value, config) {
110201 url = new URL(value)
111202 } catch (_) {}
112203
113− // URLs: `https://github.com/wooorm/test/blob/master/directory/example.md`.
204+ // URLs: `https://github.com/wooorm/test/blob/main/directory/example.md`.
114205 if (url) {
115206 // Exit if we don’t have hosted Git info or this is not a URL to the repo.
116207 if (
@@ -129,10 +220,7 @@ function urlToPath(value, config) {
129220 // the `foo/bar` branch, or, `baz` in the `bar` directory on the `foo`
130221 // branch.
131222 // Currently, we’re ignoring this and just not supporting branches.
132− value = value
133− .split(slash)
134− .slice(1)
135− .join(slash)
223+ value = value.split(slash).slice(1).join(slash)
136224
137225 return normalize(path.resolve(config.root, value + url.hash), config)
138226 }
@@ -197,3 +285,12 @@ function normalize(url, config) {
197285
198286 return {filePath: decodeURIComponent(filePath), hash: hash}
199287}
288+
289+function readme(filePath) {
290+ var ext = path.extname(filePath)
291+
292+ return (
293+ readmeExtensions.indexOf(ext) !== -1 &&
294+ readmeBasename.test(path.basename(filePath, ext))
295+ )
296+}
lib/find/index.js+1−4
@@ -5,7 +5,4 @@ var findRepo = require('./find-repo')
55var config = require('./config')
66var find = require('./find')
77
8−module.exports = trough()
9− .use(findRepo)
10− .use(config)
11− .use(find)
8+module.exports = trough().use(findRepo).use(config).use(find)
lib/index.js+1−1
@@ -42,7 +42,7 @@ function cliCompleter(set, next) {
4242
4343function checkAll(files, next) {
4444 // Check all references and landmarks.
45− check.run({files: files}, function(err) {
45+ check.run({files: files}, function (err) {
4646 next(err)
4747 })
4848}
package.json+21−15
@@ -1,11 +1,12 @@
11{
22 "name": "remark-validate-links",
3− "version": "9.0.1",
3+ "version": "10.0.2",
44 "description": "remark plugin to validate links to headings and files",
55 "license": "MIT",
66 "keywords": [
77 "unified",
88 "remark",
9+ "remark-plugin",
910 "plugin",
1011 "mdast",
1112 "markdown",
@@ -17,6 +18,10 @@
1718 ],
1819 "repository": "remarkjs/remark-validate-links",
1920 "bugs": "https://github.com/remarkjs/remark-validate-links/issues",
21+ "funding": {
22+ "type": "opencollective",
23+ "url": "https://opencollective.com/unified"
24+ },
2025 "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
2126 "contributors": [
2227 "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
@@ -28,38 +33,37 @@
2833 "Anton Rybochkin <anton.rybochkin@axibase.com>"
2934 ],
3035 "browser": {
31− "lib/check/check-files.js": "lib/check/check-files.browser.js",
32− "lib/find/find-repo.js": "lib/find/find-repo.browser.js"
36+ "./lib/check/check-files.js": "./lib/check/check-files.browser.js",
37+ "./lib/find/find-repo.js": "./lib/find/find-repo.browser.js"
3338 },
3439 "files": [
3540 "lib/",
3641 "index.js"
3742 ],
3843 "dependencies": {
39− "github-slugger": "^1.2.0",
40− "hosted-git-info": "^2.5.0",
41− "mdast-util-to-string": "^1.0.4",
44+ "github-slugger": "^1.0.0",
45+ "hosted-git-info": "^3.0.0",
46+ "mdast-util-to-string": "^1.0.0",
4247 "propose": "0.0.5",
4348 "to-vfile": "^6.0.0",
4449 "trough": "^1.0.0",
45− "unist-util-visit": "^1.0.0",
50+ "unist-util-visit": "^2.0.0",
4651 "xtend": "^4.0.0"
4752 },
4853 "devDependencies": {
49− "execa": "^4.0.0",
5054 "nyc": "^15.0.0",
51− "prettier": "^1.0.0",
52− "remark": "^11.0.0",
53− "remark-cli": "^7.0.0",
54− "remark-preset-wooorm": "^6.0.0",
55+ "prettier": "^2.0.0",
56+ "remark": "^12.0.0",
57+ "remark-cli": "^8.0.0",
58+ "remark-preset-wooorm": "^7.0.0",
5559 "rimraf": "^3.0.0",
5660 "strip-ansi": "^6.0.0",
57− "tape": "^4.0.0",
61+ "tape": "^5.0.0",
5862 "vfile-sort": "^2.0.0",
59− "xo": "^0.25.0"
63+ "xo": "^0.32.0"
6064 },
6165 "scripts": {
62− "format": "remark *.md -qfo && prettier --write \"**/*.js\" && xo --fix",
66+ "format": "remark . -qfo --ignore-pattern test/ && prettier . --write && xo --fix",
6367 "test-api": "node test",
6468 "test-coverage": "nyc --reporter lcov tape test/index.js",
6569 "test": "npm run format && npm run test-coverage"
@@ -82,6 +86,8 @@
8286 "prettier": true,
8387 "esnext": false,
8488 "rules": {
89+ "unicorn/prefer-optional-catch-binding": "off",
90+ "unicorn/no-fn-reference-in-iterator": "off",
8591 "unicorn/prefer-includes": "off",
8692 "guard-for-in": "off"
8793 }
readme.md+39−27
@@ -10,20 +10,22 @@
1010
1111[**remark**][remark] plugin to validate that Markdown links and images reference
1212existing local files and headings.
13−It does not check external URLs (see [`remark-lint-no-dead-urls`][no-dead-urls]
14−for that).
1513
1614For example, this document does not have a heading named `Hello`.
17−So if we link to that (`[welcome](#hello)`), this plugin will warn about it.
15+So if we’d link to it (`[welcome](#hello)`), we’d get a warning.
1816
1917In addition, when there’s a link to a heading in another document
20−(`examples/foo.md#hello`), if this file exists but the heading does not, or if
21−the file does not exist, this plugin will also warn.
18+(`examples/foo.md#hello`), if that file exists but the heading does not, or if
19+that file does not exist, we’d also get a warning.
2220
2321Linking to other files, such as `license` or `index.js` (when they exist) is
2422fine.
2523
26−## Table of Contents
24+This plugin does not check external URLs (see
25+[`remark-lint-no-dead-urls`][no-dead-urls]) or undefined references
26+(see [`remark-lint-no-undefined-references`][no-undef-refs]).
27+
28+## Contents
2729
2830* [Install](#install)
2931* [Use](#use)
@@ -63,7 +65,7 @@ Read more [whoops, this does not exist](#world).
6365
6466This doesn’t exist either [whoops!](readme.md#foo).
6567
66−But this does exist: [LICENSE](LICENSE).
68+But this does exist: [license](license).
6769
6870So does this: [README](readme.md#installation).
6971```
@@ -94,17 +96,22 @@ Say we have the following file, `example.md`:
9496```markdown
9597# Alpha
9698
99+Links are checked:
100+
97101This [exists](#alpha).
98102This [one does not](#does-not).
99−References and definitions are [checked][alpha] [too][charlie].
100103
101104# Bravo
102105
103−Headings in `readme.md` are [not checked](readme.md#bravo).
104−But [missing files are reported](missing-example.js).
106+Headings in `readme.md` are [checked](readme.md#nosuchheading).
107+And [missing files are reported](missing-example.js).
108+
109+Definitions are also checked:
105110
106111[alpha]: #alpha
107112[charlie]: #charlie
113+
114+References w/o definitions are not checked: [delta]
108115```
109116
110117And our script, `example.js`, looks as follows:
@@ -117,7 +124,7 @@ var links = require('remark-validate-links')
117124
118125remark()
119126 .use(links)
120− .process(vfile.readSync('example.md'), function(err, file) {
127+ .process(vfile.readSync('example.md'), function (err, file) {
121128 console.error(report(err || file))
122129 })
123130```
@@ -126,25 +133,28 @@ Now, running `node example` yields:
126133
127134```markdown
128135example.md
129− 4:6-4:31 warning Link to unknown heading: `does-not` missing-heading remark-validate-links
130− 10:5-10:53 warning Link to unknown file: `missing-example.js` missing-file remark-validate-links
131− 13:1-13:20 warning Link to unknown heading: `charlie` missing-heading remark-validate-links
136+ 6:6-6:31 warning Link to unknown heading: `does-not` missing-heading remark-validate-links
137+ 11:5-11:53 warning Link to unknown file: `missing-example.js` missing-file remark-validate-links
138+ 16:1-16:20 warning Link to unknown heading: `charlie` missing-heading remark-validate-links
132139
133140⚠ 3 warnings
134141```
135142
143+(Note that `readme.md#nosuchheading` is not warned about, because the API
144+does not check headings in other Markdown files).
145+
136146## Configuration
137147
138148Typically, you don’t need to configure `remark-validate-links`, as it detects
139149local Git repositories.
140−If one is detected that references a known Git host, some extra links can be
141−checked.
150+If one is detected that references a known Git host (GitHub, GitLab,
151+or Bitbucket), some extra links can be checked.
142152If one is detected that does not reference a known Git host, local links still
143153work as expected.
144154If you’re not in a Git repository, you must pass `repository: false` explicitly.
145155
146156You can pass a `repository` (`string?`, `false`).
147−If `repository` is nully, the Git origin remote is detected.
157+If `repository` is nullish, the Git origin remote is detected.
148158If the repository resolves to something [npm understands][package-repository]
149159as a Git host such as GitHub, GitLab, or Bitbucket, full URLs to that host
150160(say, `https://github.com/remarkjs/remark-validate-links/readme.md#install`)
@@ -156,7 +166,7 @@ remark --use 'validate-links=repository:"foo/bar"' example.md
156166
157167For this to work, a `root` (`string?`) is also used, referencing the local Git
158168root directory (the place where `.git` is).
159−If both `root` and `repository` are nully, the Git root is detected.
169+If both `root` and `repository` are nullish, the Git root is detected.
160170If `root` is not given but `repository` is, [`file.cwd`][cwd] is used.
161171
162172You can define this repository in [configuration files][cli] too.
@@ -236,8 +246,8 @@ See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways
236246to get started.
237247See [`support.md`][support] for ways to get help.
238248
239−This project has a [Code of Conduct][coc].
240−By interacting with this repository, organisation, or community you agree to
249+This project has a [code of conduct][coc].
250+By interacting with this repository, organization, or community you agree to
241251abide by its terms.
242252
243253## License
@@ -246,7 +256,7 @@ abide by its terms.
246256
247257<!-- Definitions -->
248258
249−[build-badge]: https://img.shields.io/travis/remarkjs/remark-validate-links/master.svg
259+[build-badge]: https://img.shields.io/travis/remarkjs/remark-validate-links/main.svg
250260
251261[build]: https://travis-ci.org/remarkjs/remark-validate-links
252262
@@ -268,19 +278,19 @@ abide by its terms.
268278
269279[collective]: https://opencollective.com/unified
270280
271−[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
281+[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
272282
273−[chat]: https://spectrum.chat/unified/remark
283+[chat]: https://github.com/remarkjs/remark/discussions
274284
275285[npm]: https://docs.npmjs.com/cli/install
276286
277287[health]: https://github.com/remarkjs/.github
278288
279−[contributing]: https://github.com/remarkjs/.github/blob/master/contributing.md
289+[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md
280290
281−[support]: https://github.com/remarkjs/.github/blob/master/support.md
291+[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md
282292
283−[coc]: https://github.com/remarkjs/.github/blob/master/code-of-conduct.md
293+[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md
284294
285295[license]: license
286296
@@ -288,7 +298,7 @@ abide by its terms.
288298
289299[remark]: https://github.com/remarkjs/remark
290300
291−[cli]: https://github.com/remarkjs/remark/tree/master/packages/remark-cli#readme
301+[cli]: https://github.com/remarkjs/remark/tree/HEAD/packages/remark-cli#readme
292302
293303[remark-lint]: https://github.com/remarkjs/remark-lint
294304
@@ -296,6 +306,8 @@ abide by its terms.
296306
297307[no-dead-urls]: https://github.com/davidtheclark/remark-lint-no-dead-urls
298308
309+[no-undef-refs]: https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-no-undefined-references
310+
299311[package-repository]: https://docs.npmjs.com/files/package.json#repository
300312
301313[cwd]: https://github.com/vfile/vfile#vfilecwd
test/fixtures/bitbucket.md+5−5
@@ -8,7 +8,7 @@ This is an ignored hash [link](#world).
88
99## Files
1010
11−This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/master/examples/bitbucket.md).
11+This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/main/examples/bitbucket.md).
1212
1313So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md).
1414
@@ -18,7 +18,7 @@ And this [link](examples/bitbucket.md).
1818
1919This is a valid external [file](../index.js).
2020
21−This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/master/examples/world.md).
21+This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/main/examples/world.md).
2222
2323So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/examples/world.md).
2424
@@ -32,7 +32,7 @@ Valid: [a](./examples/bitbucket.md#markdown-header-hello).
3232
3333Valid: [b](examples/bitbucket.md#markdown-header-hello).
3434
35−Valid: [c](https://bitbucket.org/wooorm/test/src/master/examples/bitbucket.md#markdown-header-hello).
35+Valid: [c](https://bitbucket.org/wooorm/test/src/main/examples/bitbucket.md#markdown-header-hello).
3636
3737Valid: [d](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md#markdown-header-hello).
3838
@@ -40,7 +40,7 @@ Invalid: [e](./examples/bitbucket.md#markdown-header-world).
4040
4141Invalid: [f](examples/bitbucket.md#markdown-header-world).
4242
43−Invalid: [g](https://bitbucket.org/wooorm/test/src/master/examples/bitbucket.md#markdown-header-world).
43+Invalid: [g](https://bitbucket.org/wooorm/test/src/main/examples/bitbucket.md#markdown-header-world).
4444
4545Invalid: [h](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md#markdown-header-world).
4646
@@ -48,7 +48,7 @@ Invalid: [i](./examples/world.md#markdown-header-hello).
4848
4949Invalid: [j](examples/world.md#markdown-header-hello).
5050
51−Invalid: [k](https://bitbucket.org/wooorm/test/src/master/examples/world.md#markdown-header-hello).
51+Invalid: [k](https://bitbucket.org/wooorm/test/src/main/examples/world.md#markdown-header-hello).
5252
5353Invalid: [l](https://bitbucket.org/wooorm/test/src/foo-bar/examples/world.md#markdown-header-hello).
5454
test/fixtures/examples/bitbucket.md+5−5
@@ -6,13 +6,13 @@ This is an invalid relative heading [link](#markdown-header-world).
66
77## Files
88
9−This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/master/bitbucket.md).
9+This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/main/bitbucket.md).
1010
1111So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/bitbucket.md).
1212
1313And this [link](../bitbucket.md).
1414
15−This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/master/world.md).
15+This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/main/world.md).
1616
1717So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/world.md).
1818
@@ -22,18 +22,18 @@ And this [link](../world.md).
2222
2323Valid: [a](../bitbucket.md#markdown-header-hello).
2424
25−Valid: [b](https://bitbucket.org/wooorm/test/src/master/bitbucket.md#markdown-header-hello).
25+Valid: [b](https://bitbucket.org/wooorm/test/src/main/bitbucket.md#markdown-header-hello).
2626
2727Valid: [c](https://bitbucket.org/wooorm/test/src/foo-bar/bitbucket.md#markdown-header-hello).
2828
2929Invalid: [d](../bitbucket.md#markdown-header-world).
3030
31−Invalid: [e](https://bitbucket.org/wooorm/test/src/master/bitbucket.md#markdown-header-world).
31+Invalid: [e](https://bitbucket.org/wooorm/test/src/main/bitbucket.md#markdown-header-world).
3232
3333Invalid: [f](https://bitbucket.org/wooorm/test/src/foo-bar/bitbucket.md#markdown-header-world).
3434
3535Invalid: [g](../world.md#markdown-header-hello).
3636
37−Invalid: [h](https://bitbucket.org/wooorm/test/src/master/world.md#markdown-header-hello).
37+Invalid: [h](https://bitbucket.org/wooorm/test/src/main/world.md#markdown-header-hello).
3838
3939Invalid: [i](https://bitbucket.org/wooorm/test/src/foo-bar/world.md#markdown-header-hello).
test/fixtures/examples/github.md+5−5
@@ -6,13 +6,13 @@ This is an invalid relative heading [link](#world).
66
77## Files
88
9−This is a valid relative file [link](https://github.com/wooorm/test/blob/master/github.md).
9+This is a valid relative file [link](https://github.com/wooorm/test/blob/main/github.md).
1010
1111So is this [link](https://github.com/wooorm/test/blob/foo-bar/github.md).
1212
1313And this [link](../github.md).
1414
15−This is an invalid relative file [link](https://github.com/wooorm/test/blob/master/world.md).
15+This is an invalid relative file [link](https://github.com/wooorm/test/blob/main/world.md).
1616
1717So is this [link](https://github.com/wooorm/test/blob/foo-bar/world.md).
1818
@@ -22,18 +22,18 @@ And this [link](../world.md).
2222
2323Valid: [a](../github.md#hello).
2424
25−Valid: [b](https://github.com/wooorm/test/blob/master/github.md#hello).
25+Valid: [b](https://github.com/wooorm/test/blob/main/github.md#hello).
2626
2727Valid: [c](https://github.com/wooorm/test/blob/foo-bar/github.md#hello).
2828
2929Invalid: [d](../github.md#world).
3030
31−Invalid: [e](https://github.com/wooorm/test/blob/master/github.md#world).
31+Invalid: [e](https://github.com/wooorm/test/blob/main/github.md#world).
3232
3333Invalid: [f](https://github.com/wooorm/test/blob/foo-bar/github.md#world).
3434
3535Invalid: [g](../world.md#hello).
3636
37−Invalid: [h](https://github.com/wooorm/test/blob/master/world.md#hello).
37+Invalid: [h](https://github.com/wooorm/test/blob/main/world.md#hello).
3838
3939Invalid: [i](https://github.com/wooorm/test/blob/foo-bar/world.md#hello).
test/fixtures/examples/gitlab.md+5−5
@@ -6,13 +6,13 @@ This is an invalid relative heading [link](#world).
66
77## Files
88
9−This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/master/gitlab.md).
9+This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/main/gitlab.md).
1010
1111So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/gitlab.md).
1212
1313And this [link](../gitlab.md).
1414
15−This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/master/world.md).
15+This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/main/world.md).
1616
1717So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/world.md).
1818
@@ -22,18 +22,18 @@ And this [link](../world.md).
2222
2323Valid: [a](../gitlab.md#hello).
2424
25−Valid: [b](https://gitlab.com/wooorm/test/blob/master/gitlab.md#hello).
25+Valid: [b](https://gitlab.com/wooorm/test/blob/main/gitlab.md#hello).
2626
2727Valid: [c](https://gitlab.com/wooorm/test/blob/foo-bar/gitlab.md#hello).
2828
2929Invalid: [d](../gitlab.md#world).
3030
31−Invalid: [e](https://gitlab.com/wooorm/test/blob/master/gitlab.md#world).
31+Invalid: [e](https://gitlab.com/wooorm/test/blob/main/gitlab.md#world).
3232
3333Invalid: [f](https://gitlab.com/wooorm/test/blob/foo-bar/gitlab.md#world).
3434
3535Invalid: [g](../world.md#hello).
3636
37−Invalid: [h](https://gitlab.com/wooorm/test/blob/master/world.md#hello).
37+Invalid: [h](https://gitlab.com/wooorm/test/blob/main/world.md#hello).
3838
3939Invalid: [i](https://gitlab.com/wooorm/test/blob/foo-bar/world.md#hello).
test/fixtures/file-as-folder.mdnew file+1
@@ -0,0 +1 @@
1+[](file-as-folder.md/other)
test/fixtures/folder-without-readme/example.mdnew file+1
@@ -0,0 +1 @@
1+This file isn’t used when linking to the folder: it has to be a `readme`.
test/fixtures/folder.mdnew file+23
@@ -0,0 +1,23 @@
1+Here we link to a folder:
2+
3+Explicit:
4+
5+[OK](./folder/readme.markdown#this)
6+
7+[OK](./folder/readme.markdown#that)
8+
9+[NOK](./folder/readme.markdown#missing)
10+
11+Implicit:
12+
13+[OK](./folder#this)
14+
15+[OK](./folder#that)
16+
17+[NOK](./folder#missing)
18+
19+Other:
20+
21+[NOK](./missing#missing)
22+
23+[NOK](./folder-without-readme#missing)
test/fixtures/folder/example.mdnew file+1
@@ -0,0 +1 @@
1+This file isn’t used when linking to the folder: it has to be a `readme`.
test/fixtures/folder/readme.ascnew file+9
@@ -0,0 +1,9 @@
1+readme
2+------
3+
4+While GitHub would pick up on this readme for the folder,
5+`remark-validate-links` is for Markdown, so we ignore AsciiDoc.
6+
7+== This
8+
9+== That
test/fixtures/folder/readme.markdownnew file+5
@@ -0,0 +1,5 @@
1+# readme
2+
3+## This
4+
5+## That
test/fixtures/folder/readme.mdnew file+1
@@ -0,0 +1 @@
1+This one isn’t used (`readme.markdown` sorts before `readme.md`).
test/fixtures/github.md+7−7
@@ -6,9 +6,9 @@ This is an invalid relative heading [link](#world).
66
77## Files
88
9−This is a valid relative file [link](https://github.com/wooorm/test/blob/master/examples/github.md).
9+This is a valid relative file [link](https://github.com/wooorm/test/blob/main/examples/github.md).
1010
11−This is a valid absolute file [link](/wooorm/test/blob/master/examples/github.md).
11+This is a valid absolute file [link](/wooorm/test/blob/main/examples/github.md).
1212
1313So is this [link](https://github.com/wooorm/test/blob/foo-bar/examples/github.md).
1414
@@ -18,9 +18,9 @@ And this [link](examples/github.md).
1818
1919This is a valid external [file](../index.js).
2020
21−This is an invalid relative file [link](https://github.com/wooorm/test/blob/master/examples/world.md).
21+This is an invalid relative file [link](https://github.com/wooorm/test/blob/main/examples/world.md).
2222
23−This is an invalid absolute file [link](/wooorm/test/blob/master/examples/world.md).
23+This is an invalid absolute file [link](/wooorm/test/blob/main/examples/world.md).
2424
2525So is this [link](https://github.com/wooorm/test/blob/foo-bar/examples/world.md).
2626
@@ -34,7 +34,7 @@ Valid: [a](./examples/github.md#hello).
3434
3535Valid: [b](examples/github.md#hello).
3636
37−Valid: [c](https://github.com/wooorm/test/blob/master/examples/github.md#hello).
37+Valid: [c](https://github.com/wooorm/test/blob/main/examples/github.md#hello).
3838
3939Valid: [d](https://github.com/wooorm/test/blob/foo-bar/examples/github.md#hello).
4040
@@ -42,7 +42,7 @@ Invalid: [e](./examples/github.md#world).
4242
4343Invalid: [f](examples/github.md#world).
4444
45−Invalid: [g](https://github.com/wooorm/test/blob/master/examples/github.md#world).
45+Invalid: [g](https://github.com/wooorm/test/blob/main/examples/github.md#world).
4646
4747Invalid: [h](https://github.com/wooorm/test/blob/foo-bar/examples/github.md#world).
4848
@@ -50,7 +50,7 @@ Invalid: [i](./examples/world.md#hello).
5050
5151Invalid: [j](examples/world.md#hello).
5252
53−Invalid: [k](https://github.com/wooorm/test/blob/master/examples/world.md#hello).
53+Invalid: [k](https://github.com/wooorm/test/blob/main/examples/world.md#hello).
5454
5555Invalid: [l](https://github.com/wooorm/test/blob/foo-bar/examples/world.md#hello).
5656
test/fixtures/gitlab.md+5−5
@@ -6,7 +6,7 @@ This is an invalid relative heading [link](#world).
66
77## Files
88
9−This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/master/examples/gitlab.md).
9+This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/main/examples/gitlab.md).
1010
1111So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/examples/gitlab.md).
1212
@@ -16,7 +16,7 @@ And this [link](examples/gitlab.md).
1616
1717This is a valid external [file](../index.js).
1818
19−This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/master/examples/world.md).
19+This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/main/examples/world.md).
2020
2121So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/examples/world.md).
2222
@@ -30,7 +30,7 @@ Valid: [a](./examples/gitlab.md#hello).
3030
3131Valid: [b](examples/gitlab.md#hello).
3232
33−Valid: [c](https://gitlab.com/wooorm/test/blob/master/examples/gitlab.md#hello).
33+Valid: [c](https://gitlab.com/wooorm/test/blob/main/examples/gitlab.md#hello).
3434
3535Valid: [d](https://gitlab.com/wooorm/test/blob/foo-bar/examples/gitlab.md#hello).
3636
@@ -38,7 +38,7 @@ Invalid: [e](./examples/gitlab.md#world).
3838
3939Invalid: [f](examples/gitlab.md#world).
4040
41−Invalid: [g](https://gitlab.com/wooorm/test/blob/master/examples/gitlab.md#world).
41+Invalid: [g](https://gitlab.com/wooorm/test/blob/main/examples/gitlab.md#world).
4242
4343Invalid: [h](https://gitlab.com/wooorm/test/blob/foo-bar/examples/gitlab.md#world).
4444
@@ -46,7 +46,7 @@ Invalid: [i](./examples/world.md#hello).
4646
4747Invalid: [j](examples/world.md#hello).
4848
49−Invalid: [k](https://gitlab.com/wooorm/test/blob/master/examples/world.md#hello).
49+Invalid: [k](https://gitlab.com/wooorm/test/blob/main/examples/world.md#hello).
5050
5151Invalid: [l](https://gitlab.com/wooorm/test/blob/foo-bar/examples/world.md#hello).
5252
test/fixtures/images.md+4−4
@@ -6,7 +6,7 @@ Relative ![image](./examples/image.jpg)
66
77No `./` in ![image](examples/image.jpg)
88
9−Absolute ![image](https://github.com/wooorm/test/blob/master/examples/image.jpg)
9+Absolute ![image](https://github.com/wooorm/test/blob/main/examples/image.jpg)
1010
1111Relative ![image reference][rel]
1212
@@ -20,7 +20,7 @@ Relative ![missing image](./examples/missing.jpg)
2020
2121No `./` in ![image](examples/missing.jpg)
2222
23−Absolute ![missing image](https://github.com/wooorm/test/blob/master/examples/missing.jpg)
23+Absolute ![missing image](https://github.com/wooorm/test/blob/main/examples/missing.jpg)
2424
2525Relative ![missing image reference][rel-missing]
2626
@@ -30,10 +30,10 @@ Absolute ![missing image reference][abs-missing]
3030
3131[rel]: ./examples/image.jpg
3232
33−[abs]: https://github.com/wooorm/test/blob/master/examples/image.jpg
33+[abs]: https://github.com/wooorm/test/blob/main/examples/image.jpg
3434
3535[rel-missing]: ./examples/missing.jpg
3636
37−[abs-missing]: https://github.com/wooorm/test/blob/master/examples/missing.jpg
37+[abs-missing]: https://github.com/wooorm/test/blob/main/examples/missing.jpg
3838
3939[rel-whitespace]: "./examples/image with space.jpg"
test/fixtures/line-links.md+2−2
@@ -4,6 +4,6 @@ Link to [a line](./examples/example.js#L1)
44
55Link to [a line in a missing file](./examples/missing.js#L1)
66
7−[a](https://github.com/wooorm/test/blob/master/examples/example.js#L1).
7+[a](https://github.com/wooorm/test/blob/main/examples/example.js#L1).
88
9−[b](https://github.com/wooorm/test/blob/master/examples/missing.js#L1).
9+[b](https://github.com/wooorm/test/blob/main/examples/missing.js#L1).
test/fixtures/self-hosted.md+2−2
@@ -1,5 +1,5 @@
11# Hello
22
3−[Fine](https://gitlab.acme.com/acme/project/blob/master/self-hosted.md#hello);
3+[Fine](https://gitlab.acme.com/acme/project/blob/main/self-hosted.md#hello);
44
5−[Not fine](https://gitlab.acme.com/acme/project/blob/master/self-hosted.md#world);
5+[Not fine](https://gitlab.acme.com/acme/project/blob/main/self-hosted.md#world);
test/index.js+1022−771
@@ -2,8 +2,8 @@
22
33var fs = require('fs')
44var path = require('path')
5+var childProcess = require('child_process')
56var test = require('tape')
6−var execa = require('execa')
77var vfile = require('to-vfile')
88var remark = require('remark')
99var strip = require('strip-ansi')
@@ -13,20 +13,20 @@ var links = require('..')
1313
1414process.chdir(path.resolve(process.cwd(), 'test', 'fixtures'))
1515
16−test.onFinish(function() {
16+test.onFinish(function () {
1717 process.chdir(path.resolve(process.cwd(), '..', '..'))
1818})
1919
2020var bin = path.join('..', '..', 'node_modules', '.bin', 'remark')
2121
22−test('remark-validate-links', function(t) {
23− t.test('should work on the API', function(st) {
22+test('remark-validate-links', function (t) {
23+ t.test('should work on the API', function (st) {
2424 st.plan(1)
2525
2626 remark()
2727 .use(links)
2828 .use(sort)
29− .process(vfile.readSync('github.md'), function(err, file) {
29+ .process(vfile.readSync('github.md'), function (err, file) {
3030 st.deepEqual(
3131 [err].concat(file.messages.map(String)),
3232 [
@@ -42,115 +42,134 @@ test('remark-validate-links', function(t) {
4242 })
4343 })
4444
45− t.test('should ignore invalid repositories', function(st) {
45+ t.test('should ignore invalid repositories', function (st) {
4646 st.plan(1)
4747
48− execa(bin, [
49− '--no-config',
50− '--no-ignore',
51− '--use',
52− '../..=repository:"invalid:shortcode"',
53− '--use',
54− '../sort',
55− 'small.md'
56− ]).then(
57− function(result) {
58− st.equal(
59− strip(result.stderr),
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,
6067 [
6168 'small.md',
6269 ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
6370 '',
64− '⚠ 1 warning'
65− ].join('\n'),
66− 'should work'
67− )
68− },
69− function(err) {
70− st.error(err)
71− }
72− )
71+ '⚠ 1 warning',
72+ ''
73+ ].join('\n')
74+ ],
75+ 'should work'
76+ )
77+ }
7378 })
7479
75− t.test('should throw on Gist repositories', function(st) {
80+ t.test('should throw on Gist repositories', function (st) {
7681 st.plan(1)
7782
78− execa(bin, [
79− '--no-config',
80− '--no-ignore',
81− '--use',
82− '../..=repository:"gist:wooorm/8504606"',
83− '--use',
84− '../sort',
85− 'small.md'
86− ]).then(
87− function(result) {
88− st.equal(
89− strip(result.stderr),
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)],
100+ [
101+ null,
90102 [
91103 'small.md',
92104 ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
93105 '',
94− '⚠ 1 warning'
95− ].join('\n'),
96− 'should work'
97− )
98− },
99− function(err) {
100− st.error(err, 'should not fail')
101− }
102− )
106+ '⚠ 1 warning',
107+ ''
108+ ].join('\n')
109+ ],
110+ 'should work'
111+ )
112+ }
103113 })
104114
105− t.test('should ignore unfound files (#1)', function(st) {
115+ t.test('should ignore unfound files (#1)', function (st) {
106116 st.plan(1)
107117
108− execa(bin, [
109− '--no-config',
110− '--no-ignore',
111− '--use',
112− '../..',
113− '--use',
114− '../sort',
115− 'FOOOO'
116− ]).then(
117− function() {
118− st.fail('should not be successful')
119− },
120− function(err) {
121− st.equal(
122− strip(err.stderr),
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)],
135+ [
136+ true,
123137 [
124138 'FOOOO',
125139 ' 1:1 error No such file or directory',
126140 '',
127− '✖ 1 error'
128− ].join('\n'),
129− 'should report an error'
130− )
131− }
132− )
141+ '✖ 1 error',
142+ ''
143+ ].join('\n')
144+ ],
145+ 'should work'
146+ )
147+ }
133148 })
134149
135− t.test('should ignore unfound files (#2)', function(st) {
150+ t.test('should ignore unfound files (#2)', function (st) {
136151 st.plan(1)
137152
138− execa(bin, [
139− '--no-config',
140− '--no-ignore',
141− '--use',
142− '../..',
143− '--use',
144− '../sort',
145− 'definitions.md',
146− 'FOOOO'
147− ]).then(
148− function() {
149− st.fail('should not be successful')
150− },
151− function(err) {
152− st.equal(
153− strip(err.stderr),
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)],
171+ [
172+ true,
154173 [
155174 'FOOOO',
156175 ' 1:1 error No such file or directory',
@@ -158,493 +177,557 @@ test('remark-validate-links', function(t) {
158177 'definitions.md',
159178 ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links',
160179 '',
161− '2 messages (✖ 1 error, ⚠ 1 warning)'
162− ].join('\n'),
163− 'should report an error'
164− )
165− }
166− )
180+ '2 messages (✖ 1 error, ⚠ 1 warning)',
181+ ''
182+ ].join('\n')
183+ ],
184+ 'should work'
185+ )
186+ }
167187 })
168188
169− t.test('should work if there are no links', function(st) {
189+ t.test('should work if there are no links', function (st) {
170190 st.plan(1)
171191
172− execa(bin, [
173− '--no-config',
174− '--no-ignore',
175− '--use',
176− '../..',
177− '--use',
178− '../sort',
179− 'empty.md'
180− ]).then(function(result) {
181− st.equal(
182− strip(result.stderr),
183− 'empty.md: no issues found',
184− 'should report'
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'
185211 )
186− }, st.error)
212+ }
187213 })
188214
189− t.test('should work with stdin', function(st) {
215+ t.test('should work with stdin', function (st) {
190216 st.plan(1)
191217
192− var subprocess = execa(bin, [
193− '--no-config',
194− '--no-ignore',
195− '--use',
196− '../..',
197− '--use',
198− '../sort'
199− ])
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+ )
200230
201231 fs.createReadStream('github.md').pipe(subprocess.stdin)
202232
203− subprocess.then(function(result) {
204− st.equal(
205− strip(result.stderr),
233+ function onexec(err, stdout, stderr) {
234+ st.deepEqual(
235+ [err, strip(stderr)],
206236 [
207− '<stdin>',
208− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
209− '',
210− '⚠ 1 warning'
211− ].join('\n'),
212− 'should report an error'
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'
213247 )
214− }, st.error)
248+ }
215249 })
216250
217− t.test('should work when not all files are given', function(st) {
251+ t.test('should work when not all files are given', function (st) {
218252 st.plan(1)
219253
220− execa(bin, [
221− '--no-config',
222− '--no-ignore',
223− '--use',
224− '../..',
225− '--use',
226− '../sort',
227− 'github.md'
228− ]).then(function(result) {
229− st.equal(
230− strip(result.stderr),
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)],
231271 [
232− 'github.md',
233− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
234− ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
235− ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
236− ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
237− ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
238− ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
239− ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
240− ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
241− ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
242− '',
243− '⚠ 9 warnings'
244− ].join('\n'),
245− 'should report'
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'
246290 )
247− }, st.error)
291+ }
248292 })
249293
250− t.test('should work when all files are given', function(st) {
294+ t.test('should work when all files are given', function (st) {
251295 st.plan(1)
252296
253− execa(bin, [
254− '--no-config',
255− '--no-ignore',
256− '--use',
257− '../..',
258− '--use',
259− '../sort',
260− 'github.md',
261− 'examples/github.md'
262− ]).then(function(result) {
263− st.equal(
264− strip(result.stderr),
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)],
265315 [
266− 'examples/github.md',
267− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
268− ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
269− ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
270− ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
271− ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
272− '',
273− 'github.md',
274− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
275− ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
276− ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
277− ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
278− ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
279− ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
280− ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
281− ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
282− ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
283− '',
284− '⚠ 14 warnings'
285− ].join('\n'),
286− 'should report'
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'
287341 )
288− }, st.error)
342+ }
289343 })
290344
291− t.test('should work with definitions', function(st) {
345+ t.test('should work with definitions', function (st) {
292346 st.plan(1)
293347
294− execa(bin, [
295− '--no-config',
296− '--no-ignore',
297− '--use',
298− '../..',
299− '--use',
300− '../sort',
301− 'definitions.md'
302− ]).then(function(result) {
303− st.equal(
304− strip(result.stderr),
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)],
305365 [
306− 'definitions.md',
307− ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links',
308− '',
309− '⚠ 1 warning'
310− ].join('\n'),
311− 'should report'
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'
312376 )
313− }, st.error)
377+ }
314378 })
315379
316− t.test('should work on GitHub URLs when given a repo', function(st) {
380+ t.test('should work on GitHub URLs when given a repo', function (st) {
317381 st.plan(1)
318382
319− execa(bin, [
320− '--no-config',
321− '--no-ignore',
322− '--use',
323− '../..=repository:"wooorm/test"',
324− '--use',
325− '../sort',
326− 'github.md',
327− 'examples/github.md'
328− ]).then(function(result) {
329− st.equal(
330− strip(result.stderr),
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)],
331401 [
332− 'examples/github.md',
333− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
334− ' 15:34-15:93 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
335− ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
336− ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
337− ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
338− ' 31:10-31:73 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
339− ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
340− ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
341− ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
342− ' 37:10-37:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
343− ' 37:10-37:72 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
344− ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
345− ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
346− '',
347− 'github.md',
348− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
349− ' 21:34-21:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
350− ' 23:34-23:84 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
351− ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
352− ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
353− ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
354− ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
355− ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
356− ' 45:10-45:82 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
357− ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
358− ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
359− ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
360− ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
361− ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
362− ' 53:10-53:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
363− ' 53:10-53:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
364− ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
365− ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
366− '',
367− '⚠ 31 warnings'
368− ].join('\n'),
369− 'should report'
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'
370444 )
371− }, st.error)
445+ }
372446 })
373447
374− t.test('should work when with Git directory', function(st) {
448+ t.test('should work when with Git directory', function (st) {
375449 st.plan(1)
376450
377− Promise.resolve()
378− .then(function() {
379− return execa('git', ['init'])
380− })
381− .then(function() {
382− return execa('git', [
383− 'remote',
384− 'add',
385− 'origin',
386− 'git@github.com:wooorm/test.git'
387− ])
388− })
389− .then(function() {
390− return execa(bin, [
391− '--no-config',
392− '--no-ignore',
393− '--use',
394− '../..',
395− '--use',
396− '../sort',
397− 'github.md',
398− 'examples/github.md'
399− ])
400− })
401− .then(
402− function(result) {
403− clean()
404− st.equal(
405− strip(result.stderr),
406− [
407− 'examples/github.md',
408− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
409− ' 15:34-15:93 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
410− ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
411− ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
412− ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
413− ' 31:10-31:73 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
414− ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
415− ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
416− ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
417− ' 37:10-37:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
418− ' 37:10-37:72 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
419− ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
420− ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
421− '',
422− 'github.md',
423− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
424− ' 21:34-21:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
425− ' 23:34-23:84 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
426− ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
427− ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
428− ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
429− ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
430− ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
431− ' 45:10-45:82 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
432− ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
433− ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
434− ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
435− ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
436− ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
437− ' 53:10-53:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
438− ' 53:10-53:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
439− ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
440− ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
441− '',
442− '⚠ 31 warnings'
443− ].join('\n'),
444− 'should report'
445− )
446− },
447− function(err) {
448− clean()
449− st.error(err)
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)],
490+ [
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'
451533 )
534+ }
452535
453536 function clean() {
454537 rimraf.sync('./.git')
455538 }
456539 })
457540
458− t.test('should fail w/o Git repository', function(st) {
541+ t.test('should fail w/o Git repository', function (st) {
459542 st.plan(1)
460543
461544 fs.renameSync('../../.git', '../../.git.bak')
462545
463− execa(bin, [
464− '--no-config',
465− '--no-ignore',
466− '--use',
467− '../..',
468− '--use',
469− '../sort',
470− 'github.md'
471− ]).then(
472− function() {
473− clean()
474− st.fail('should not work')
475− },
476− function(err) {
477− clean()
478− st.ok(/not a git repository/i.test(err.stderr), 'should fail')
479− }
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
480558 )
481559
482− function clean() {
560+ function onexec(err) {
483561 fs.renameSync('../../.git.bak', '../../.git')
562+ st.ok(/not a git repository/i.test(err), 'should fail')
484563 }
485564 })
486565
487− t.test('should fail w/o Git repository w/o remote', function(st) {
566+ t.test('should fail w/o Git repository w/o remote', function (st) {
488567 st.plan(1)
489568
490− Promise.resolve()
491− .then(function() {
492− return execa('git', ['init'])
493− })
494− .then(function() {
495− return execa(bin, [
496− '--no-config',
497− '--no-ignore',
498− '--use',
499− '../..',
500− 'github.md'
501− ])
502− })
503− .then(
504− function() {
505− clean()
506− st.fail('should not work')
507− },
508− function(err) {
509− clean()
510− st.ok(/Could not find remote origin/.test(err.stderr), 'should fail')
511− }
512− )
569+ childProcess.exec('git init', oninit)
513570
514− function clean() {
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) {
515590 rimraf.sync('./.git')
591+ st.ok(/Could not find remote origin/.test(err), 'should fail')
516592 }
517593 })
518594
519− t.test('should work w/o Git repository w/ repo', function(st) {
595+ t.test('should work w/o Git repository w/ repo', function (st) {
520596 st.plan(1)
521597
522598 fs.renameSync('../../.git', '../../.git.bak')
523599
524− execa(bin, [
525− '--no-config',
526− '--no-ignore',
527− '--use',
528− '../..=repository:"wooorm/test"',
529− '--use',
530− '../sort',
531− 'small.md'
532− ]).then(
533− function(result) {
534− clean()
535− st.equal(
536− strip(result.stderr),
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)],
618+ [
619+ null,
537620 [
538621 'small.md',
539622 ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
540623 '',
541− '⚠ 1 warning'
542− ].join('\n'),
543− 'should work'
544− )
545− },
546− function(err) {
547− clean()
548− st.error(err, 'shoult not fail')
549− }
550− )
551−
552− function clean() {
553− fs.renameSync('../../.git.bak', '../../.git')
624+ '⚠ 1 warning',
625+ ''
626+ ].join('\n')
627+ ],
628+ 'should work'
629+ )
554630 }
555631 })
556632
557− t.test('should work w/o Git repository w/ remote', function(st) {
633+ t.test('should work w/o Git repository w/ remote', function (st) {
558634 st.plan(1)
559635
560636 fs.renameSync('../../.git', '../../.git.bak')
561637
562− execa(bin, [
563− '--no-config',
564− '--no-ignore',
565− '--use',
566− '../..=repository:{remote:"wooorm/test"}',
567− 'small.md'
568− ]).then(
569− function(result) {
570− clean()
571− st.equal(
572− strip(result.stderr),
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,
573656 [
574657 'small.md',
575658 ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
576659 '',
577− '⚠ 1 warning'
578− ].join('\n'),
579− 'should work'
580− )
581− },
582− function(err) {
583− clean()
584− st.error(err, 'shoult not fail')
585− }
586− )
587−
588− function clean() {
589− fs.renameSync('../../.git.bak', '../../.git')
660+ '⚠ 1 warning',
661+ ''
662+ ].join('\n')
663+ ],
664+ 'should work'
665+ )
590666 }
591667 })
592668
593− t.test('should work w/o Git repository w/ remote and root', function(st) {
669+ t.test('should work w/o Git repository w/ remote and root', function (st) {
594670 st.plan(1)
595671
596672 fs.renameSync('../../.git', '../../.git.bak')
597673
598− execa(bin, [
599− '--no-config',
600− '--no-ignore',
601− '--use',
602− '../..=repository:"wooorm/test",root:"../"',
603− 'small.md'
604− ]).then(
605− function(result) {
606− clean()
607− st.equal(
608− strip(result.stderr),
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,
609692 [
610693 'small.md',
611694 ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
612695 '',
613− '⚠ 1 warning'
614− ].join('\n'),
615− 'should work'
616− )
617− },
618− function(err) {
619− clean()
620− st.error(err, 'shoult not fail')
621− }
622− )
623−
624− function clean() {
625− fs.renameSync('../../.git.bak', '../../.git')
696+ '⚠ 1 warning',
697+ ''
698+ ].join('\n')
699+ ],
700+ 'should work'
701+ )
626702 }
627703 })
628704
629− t.test('should work with `repository:false`', function(st) {
705+ t.test('should work with `repository:false`', function (st) {
630706 st.plan(1)
631707
632708 fs.renameSync('../../.git', '../../.git.bak')
633709
634− execa(bin, [
635− '--no-config',
636− '--no-ignore',
637− '--use',
638− '../..=repository:false',
639− '--use',
640− '../sort',
641− 'github.md',
642− 'examples/github.md'
643− ]).then(
644− function(result) {
645− clean()
646− st.equal(
647− strip(result.stderr),
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,
648731 [
649732 'examples/github.md',
650733 ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
@@ -665,382 +748,550 @@ test('remark-validate-links', function(t) {
665748 ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
666749 ' 71:41-71:56 warning Link to unknown heading: `readme` missing-heading remark-validate-links',
667750 '',
668− '⚠ 15 warnings'
669− ].join('\n'),
670− 'should report'
671− )
672− },
673− function(err) {
674− clean()
675− st.error(err)
676− }
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
677775 )
678776
679− function clean() {
680− fs.renameSync('../../.git.bak', '../../.git')
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+ })
794+
795+ t.test('should support a GitLab shortcode', function (st) {
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)],
815+ [
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+ )
681843 }
682844 })
683845
684− t.test('should work when finding non-hosted Git remotes', function(st) {
846+ t.test('should support a Bitbucket shortcode', function (st) {
685847 st.plan(1)
686848
687− execa(bin, [
688− '--no-config',
689− '--no-ignore',
690− '--use',
691− '../..=repository:"ssh://git@domain.com/user/project.git"',
692− '--use',
693− '../sort',
694− 'small.md'
695− ]).then(function(result) {
696− st.equal(
697− strip(result.stderr),
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)],
698866 [
699− 'small.md',
700− ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
701− '',
702− '⚠ 1 warning'
703− ].join('\n'),
704− 'should report'
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'
705893 )
706− }, st.error)
894+ }
707895 })
708896
709− t.test('should support a GitLab shortcode', function(st) {
897+ t.test('should suggest similar links', function (st) {
710898 st.plan(1)
711899
712− execa(bin, [
713− '--no-config',
714− '--no-ignore',
715− '--use',
716− '../..=repository:"gitlab:wooorm/test"',
717− '--use',
718− '../sort',
719− 'gitlab.md'
720− ]).then(function(result) {
721− st.equal(
722− strip(result.stderr),
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)],
723917 [
724− 'gitlab.md',
725− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
726− ' 19:34-19:102 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
727− ' 21:12-21:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
728− ' 23:10-23:37 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
729− ' 25:10-25:35 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
730− ' 37:10-37:41 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
731− ' 39:10-39:39 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
732− ' 41:10-41:82 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
733− ' 43:10-43:83 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
734− ' 45:10-45:40 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
735− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
736− ' 47:10-47:38 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
737− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
738− ' 49:10-49:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
739− ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
740− ' 51:10-51:82 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
741− ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
742− '',
743− '⚠ 17 warnings'
744− ].join('\n'),
745− 'should report'
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'
746929 )
747− }, st.error)
930+ }
748931 })
749932
750− t.test('should support a Bitbucket shortcode', function(st) {
933+ t.test('should recognise links to particular lines', function (st) {
751934 st.plan(1)
752935
753− execa(bin, [
754− '--no-config',
755− '--no-ignore',
756− '--use',
757− '../..=repository:"bitbucket:wooorm/test"',
758− '--use',
759− '../sort',
760− 'bitbucket.md'
761− ]).then(function(result) {
762− st.equal(
763− strip(result.stderr),
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)],
764953 [
765− 'bitbucket.md',
766− ' 5:37-5:67 warning Link to unknown heading: `world` missing-heading remark-validate-links',
767− ' 21:34-21:104 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
768− ' 23:12-23:83 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
769− ' 25:10-25:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
770− ' 27:10-27:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
771− ' 39:10-39:60 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
772− ' 41:10-41:58 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
773− ' 43:10-43:103 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
774− ' 45:10-45:104 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
775− ' 47:10-47:56 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
776− ' 47:10-47:56 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
777− ' 49:10-49:54 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
778− ' 49:10-49:54 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
779− ' 51:10-51:99 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
780− ' 51:10-51:99 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
781− ' 53:10-53:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
782− ' 53:10-53:100 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
783− '',
784− '⚠ 17 warnings'
785− ].join('\n'),
786− 'should report'
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'
787965 )
788− }, st.error)
966+ }
789967 })
790968
791− t.test('should suggest similar links', function(st) {
969+ t.test('should recognise links with encoded URLs', function (st) {
792970 st.plan(1)
793971
794− execa(bin, [
795− '--no-config',
796− '--no-ignore',
797− '--use',
798− '../..',
799− '--use',
800− '../sort',
801− 'suggestions.md'
802− ]).then(function(result) {
803− st.equal(
804− strip(result.stderr),
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)],
805989 [
806− 'suggestions.md',
807− ' 3:22-3:37 warning Link to unknown heading: `helloo`. Did you mean `hello` missing-heading remark-validate-links',
808− ' 7:17-7:39 warning Link to unknown heading in `github.md`: `fiiiles`. Did you mean `files` missing-heading-in-file remark-validate-links',
809− '',
810− '⚠ 2 warnings'
811− ].join('\n'),
812− 'should report'
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'
8131003 )
814− }, st.error)
1004+ }
8151005 })
8161006
817− t.test('should recognise links to particular lines', function(st) {
1007+ t.test('should support folders', function (st) {
8181008 st.plan(1)
8191009
820− execa(bin, [
821− '--no-config',
822− '--no-ignore',
823− '--use',
824− '../..=repository:"wooorm/test"',
825− '--use',
826− '../sort',
827− 'line-links.md'
828− ]).then(function(result) {
829− st.equal(
830− strip(result.stderr),
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)],
8311027 [
832− 'line-links.md',
833− ' 5:9-5:61 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links',
834− ' 9:1-9:71 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links',
835− '',
836− '⚠ 2 warnings'
837− ].join('\n'),
838− 'should report'
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'
8391042 )
840− }, st.error)
1043+ }
8411044 })
8421045
843− t.test('should recognise links with encoded URLs', function(st) {
1046+ t.test('should warn on files as folders', function (st) {
8441047 st.plan(1)
8451048
846− execa(bin, [
847− '--no-config',
848− '--no-ignore',
849− '--use',
850− '../..=repository:"wooorm/test"',
851− '--use',
852− '../sort',
853− 'weird-characters.md'
854− ]).then(function(result) {
855− st.equal(
856− strip(result.stderr),
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)],
8571066 [
858− 'weird-characters.md',
859− ' 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',
860− ' 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',
861− ' 15:17-15:114 warning Link to unknown heading in `examples/weird#characters.md`: `world` missing-heading-in-file remark-validate-links',
862− ' 17:17-17:120 warning Link to unknown heading in `examples/weird#character/readme.md`: `world` missing-heading-in-file remark-validate-links',
863− '',
864− '⚠ 4 warnings'
865− ].join('\n'),
866− 'should report'
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'
8671077 )
868− }, st.error)
1078+ }
8691079 })
8701080
871− t.test('should check images', function(st) {
1081+ t.test('should check images', function (st) {
8721082 st.plan(1)
8731083
874− execa(bin, [
875− '--no-config',
876− '--no-ignore',
877− '--use',
878− '../..=repository:"wooorm/test"',
879− '--use',
880− '../sort',
881− 'images.md'
882− ]).then(function(result) {
883− st.equal(
884− strip(result.stderr),
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)],
8851101 [
886− 'images.md',
887− ' 19:10-19:50 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
888− ' 21:12-21:42 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
889− ' 23:10-23:91 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
890− ' 35:1-35:38 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
891− ' 37:1-37:79 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
892− '',
893− '⚠ 5 warnings'
894− ].join('\n'),
895− 'should report'
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'
8961116 )
897− }, st.error)
1117+ }
8981118 })
8991119
900− t.test('should support query parameters', function(st) {
1120+ t.test('should support query parameters', function (st) {
9011121 st.plan(1)
9021122
903− execa(bin, [
904− '--no-config',
905− '--no-ignore',
906− '--use',
907− '../..=repository:"wooorm/test"',
908− '--use',
909− '../sort',
910− 'query-params.md'
911− ]).then(
912− function(result) {
913− st.equal(
914− strip(result.stderr),
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,
9151142 [
9161143 'query-params.md',
9171144 ' 9:33-9:55 warning Link to unknown heading: `query-params?`. Did you mean `query-params` missing-heading remark-validate-links',
9181145 '',
919− '⚠ 1 warning'
920− ].join('\n'),
921− 'should report'
922− )
923− },
924− function(err) {
925− st.error(err, 'should not fail')
926− }
927− )
1146+ '⚠ 1 warning',
1147+ ''
1148+ ].join('\n')
1149+ ],
1150+ 'should work'
1151+ )
1152+ }
9281153 })
9291154
930− t.test('should support case insensitive headings', function(st) {
1155+ t.test('should support case insensitive headings', function (st) {
9311156 st.plan(1)
9321157
933− execa(bin, [
934− '--no-config',
935− '--no-ignore',
936− '--use',
937− '../..',
938− '--use',
939− '../sort',
940− 'case-insensitive-headings.md'
941− ]).then(
942− function(result) {
943− st.equal(
944− strip(result.stderr),
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,
9451177 [
9461178 'case-insensitive-headings.md',
9471179 ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
9481180 ' 9:16-9:48 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
9491181 '',
950− '⚠ 2 warnings'
951− ].join('\n'),
952− 'should report'
953− )
954− },
955− function(err) {
956− st.error(err, 'should not fail')
957− }
958− )
1182+ '⚠ 2 warnings',
1183+ ''
1184+ ].join('\n')
1185+ ],
1186+ 'should work'
1187+ )
1188+ }
9591189 })
9601190
961− t.test('should ignore external links', function(st) {
1191+ t.test('should ignore external links', function (st) {
9621192 st.plan(1)
9631193
964− execa(bin, [
965− '--no-config',
966− '--no-ignore',
967− '--use',
968− '../..=repository:"wooorm/test"',
969− '--use',
970− '../sort',
971− 'external.md'
972− ]).then(function(result) {
973− st.equal(
974− strip(result.stderr),
975− 'external.md: no issues found',
976− 'should report'
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'
9771213 )
978− }, st.error)
1214+ }
9791215 })
9801216
981− t.test('should ignore external links (without repo)', function(st) {
1217+ t.test('should ignore external links (without repo)', function (st) {
9821218 st.plan(1)
9831219
984− execa(bin, [
985− '--no-config',
986− '--no-ignore',
987− '--use',
988− '../..=repository:false',
989− '--use',
990− '../sort',
991− 'external.md'
992− ]).then(function(result) {
993− st.equal(
994− strip(result.stderr),
995− 'external.md: no issues found',
996− 'should report'
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'
9971239 )
998− }, st.error)
1240+ }
9991241 })
10001242
1001− t.test('should support self-hosted Git solutions', function(st) {
1243+ t.test('should support self-hosted Git solutions', function (st) {
10021244 st.plan(1)
10031245
1004− Promise.resolve()
1005− .then(function() {
1006− return execa('git', ['init'])
1007− })
1008− .then(function() {
1009− return execa('git', [
1010− 'remote',
1011− 'add',
1012− 'origin',
1013− 'git@gitlab.acme.company:acme/project.git'
1014− ])
1015− })
1016− .then(function() {
1017− return execa(bin, [
1018− '--no-config',
1019− '--no-ignore',
1020− '--use',
1021− '../..=urlConfig:{hostname:"gitlab.acme.com",prefix:"/acme/project/blob/",headingPrefix:"#",lines:true}',
1022− 'self-hosted.md'
1023− ])
1024− })
1025− .then(
1026− function(result) {
1027− clean()
1028− st.equal(
1029− strip(result.stderr),
1030− [
1031− 'self-hosted.md',
1032− ' 5:1-5:82 warning Link to unknown heading: `world` missing-heading remark-validate-links',
1033− '',
1034− '⚠ 1 warning'
1035− ].join('\n'),
1036− 'should report'
1037− )
1038− },
1039− function(err) {
1040− clean()
1041− st.error(err)
1042− }
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'
10431293 )
1294+ }
10441295
10451296 function clean() {
10461297 rimraf.sync('./.git')