diff --git a/package.json b/package.json index 0173b3d..5f44fe4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "xtend": "^4.0.0" }, "devDependencies": { - "execa": "^4.0.0", "nyc": "^15.0.0", "prettier": "^1.0.0", "remark": "^11.0.0", diff --git a/test/index.js b/test/index.js index c8da2d6..5ee556a 100644 --- a/test/index.js +++ b/test/index.js @@ -2,8 +2,8 @@ var fs = require('fs') var path = require('path') +var childProcess = require('child_process') var test = require('tape') -var execa = require('execa') var vfile = require('to-vfile') var remark = require('remark') var strip = require('strip-ansi') @@ -45,112 +45,131 @@ test('remark-validate-links', function(t) { t.test('should ignore invalid repositories', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"invalid:shortcode"', - '--use', - '../sort', - 'small.md' - ]).then( - function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"invalid:shortcode\\""', + '--use', + '../sort', + 'small.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], + [ + null, [ 'small.md', ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links', '', - '⚠ 1 warning' - ].join('\n'), - 'should work' - ) - }, - function(err) { - st.error(err) - } - ) + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' + ) + } }) t.test('should throw on Gist repositories', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"gist:wooorm/8504606"', - '--use', - '../sort', - 'small.md' - ]).then( - function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"gist:wooorm/8504606\\""', + '--use', + '../sort', + 'small.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], + [ + null, [ 'small.md', ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links', '', - '⚠ 1 warning' - ].join('\n'), - 'should work' - ) - }, - function(err) { - st.error(err, 'should not fail') - } - ) + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' + ) + } }) t.test('should ignore unfound files (#1)', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'FOOOO' - ]).then( - function() { - st.fail('should not be successful') - }, - function(err) { - st.equal( - strip(err.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'FOOOO' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [/command failed/i.test(err), strip(stderr)], + [ + true, [ 'FOOOO', ' 1:1 error No such file or directory', '', - '✖ 1 error' - ].join('\n'), - 'should report an error' - ) - } - ) + '✖ 1 error', + '' + ].join('\n') + ], + 'should work' + ) + } }) t.test('should ignore unfound files (#2)', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'definitions.md', - 'FOOOO' - ]).then( - function() { - st.fail('should not be successful') - }, - function(err) { - st.equal( - strip(err.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'definitions.md', + 'FOOOO' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [/command failed/i.test(err), strip(stderr)], + [ + true, [ 'FOOOO', ' 1:1 error No such file or directory', @@ -158,297 +177,361 @@ test('remark-validate-links', function(t) { 'definitions.md', ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links', '', - '2 messages (✖ 1 error, ⚠ 1 warning)' - ].join('\n'), - 'should report an error' - ) - } - ) + '2 messages (✖ 1 error, ⚠ 1 warning)', + '' + ].join('\n') + ], + 'should work' + ) + } }) t.test('should work if there are no links', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'empty.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), - 'empty.md: no issues found', - 'should report' + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'empty.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], + [null, 'empty.md: no issues found\n'], + 'should work' ) - }, st.error) + } }) t.test('should work with stdin', function(st) { st.plan(1) - var subprocess = execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort' - ]) + var subprocess = childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort' + ].join(' '), + onexec + ) fs.createReadStream('github.md').pipe(subprocess.stdin) - subprocess.then(function(result) { - st.equal( - strip(result.stderr), + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - '', - ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', - '', - '⚠ 1 warning' - ].join('\n'), - 'should report an error' + null, + [ + '', + ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', + '', + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should work when not all files are given', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'github.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'github.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'github.md', - ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', - ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - '', - '⚠ 9 warnings' - ].join('\n'), - 'should report' + null, + [ + 'github.md', + ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', + ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + '', + '⚠ 9 warnings', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should work when all files are given', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'github.md', - 'examples/github.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'github.md', + 'examples/github.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'examples/github.md', - ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', - ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', - ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', - '', - 'github.md', - ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', - ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - '', - '⚠ 14 warnings' - ].join('\n'), - 'should report' + null, + [ + 'examples/github.md', + ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', + ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', + ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', + '', + 'github.md', + ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', + ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + '', + '⚠ 14 warnings', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should work with definitions', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'definitions.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'definitions.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'definitions.md', - ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links', - '', - '⚠ 1 warning' - ].join('\n'), - 'should report' + null, + [ + 'definitions.md', + ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links', + '', + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should work on GitHub URLs when given a repo', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"wooorm/test"', - '--use', - '../sort', - 'github.md', - 'examples/github.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"wooorm/test\\""', + '--use', + '../sort', + 'github.md', + 'examples/github.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'examples/github.md', - ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', - ' 15:34-15:93 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', - ' 31:10-31:73 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', - ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', - ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 37:10-37:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 37:10-37:72 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', - '', - 'github.md', - ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', - ' 21:34-21:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 23:34-23:84 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 45:10-45:82 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 53:10-53:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 53:10-53:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - '', - '⚠ 31 warnings' - ].join('\n'), - 'should report' + null, + [ + 'examples/github.md', + ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', + ' 15:34-15:93 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', + ' 31:10-31:73 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', + ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', + ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 37:10-37:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 37:10-37:72 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', + '', + 'github.md', + ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', + ' 21:34-21:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 23:34-23:84 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 45:10-45:82 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 53:10-53:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 53:10-53:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + '', + '⚠ 31 warnings', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should work when with Git directory', function(st) { st.plan(1) - Promise.resolve() - .then(function() { - return execa('git', ['init']) - }) - .then(function() { - return execa('git', [ - 'remote', - 'add', - 'origin', - 'git@github.com:wooorm/test.git' - ]) - }) - .then(function() { - return execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'github.md', - 'examples/github.md' - ]) - }) - .then( - function(result) { - clean() - st.equal( - strip(result.stderr), - [ - 'examples/github.md', - ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', - ' 15:34-15:93 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', - ' 31:10-31:73 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', - ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', - ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 37:10-37:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 37:10-37:72 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links', - ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', - '', - 'github.md', - ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', - ' 21:34-21:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 23:34-23:84 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 45:10-45:82 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', - ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 53:10-53:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 53:10-53:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - '', - '⚠ 31 warnings' - ].join('\n'), - 'should report' - ) - }, - function(err) { - clean() - st.error(err) - } + childProcess.exec('git init', oninit) + + function oninit(err) { + if (err) { + t.ifErr(err) + } else { + childProcess.exec( + 'git remote add origin git@github.com:wooorm/test.git', + onremote + ) + } + } + + function onremote(err) { + if (err) { + clean() + t.ifErr(err) + } else { + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'github.md', + 'examples/github.md' + ].join(' '), + onexec + ) + } + } + + function onexec(err, stdout, stderr) { + clean() + st.deepEqual( + [err, strip(stderr)], + [ + null, + [ + 'examples/github.md', + ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', + ' 15:34-15:93 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', + ' 31:10-31:73 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', + ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links', + ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 37:10-37:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 37:10-37:72 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links', + ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links', + '', + 'github.md', + ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', + ' 21:34-21:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 23:34-23:84 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 45:10-45:82 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', + ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 53:10-53:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 53:10-53:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + '', + '⚠ 31 warnings', + '' + ].join('\n') + ], + 'should work' ) + } function clean() { rimraf.sync('./.git') @@ -460,59 +543,52 @@ test('remark-validate-links', function(t) { fs.renameSync('../../.git', '../../.git.bak') - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'github.md' - ]).then( - function() { - clean() - st.fail('should not work') - }, - function(err) { - clean() - st.ok(/not a git repository/i.test(err.stderr), 'should fail') - } + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'github.md' + ].join(' '), + onexec ) - function clean() { + function onexec(err) { fs.renameSync('../../.git.bak', '../../.git') + st.ok(/not a git repository/i.test(err), 'should fail') } }) t.test('should fail w/o Git repository w/o remote', function(st) { st.plan(1) - Promise.resolve() - .then(function() { - return execa('git', ['init']) - }) - .then(function() { - return execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - 'github.md' - ]) - }) - .then( - function() { - clean() - st.fail('should not work') - }, - function(err) { - clean() - st.ok(/Could not find remote origin/.test(err.stderr), 'should fail') - } - ) + childProcess.exec('git init', oninit) - function clean() { + function oninit(err) { + if (err) { + t.ifErr(err) + } else { + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + 'github.md' + ].join(' '), + onexec + ) + } + } + + function onexec(err) { rimraf.sync('./.git') + st.ok(/Could not find remote origin/.test(err), 'should fail') } }) @@ -521,36 +597,36 @@ test('remark-validate-links', function(t) { fs.renameSync('../../.git', '../../.git.bak') - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"wooorm/test"', - '--use', - '../sort', - 'small.md' - ]).then( - function(result) { - clean() - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"wooorm/test\\""', + '--use', + '../sort', + 'small.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + fs.renameSync('../../.git.bak', '../../.git') + st.deepEqual( + [err, strip(stderr)], + [ + null, [ 'small.md', ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links', '', - '⚠ 1 warning' - ].join('\n'), - 'should work' - ) - }, - function(err) { - clean() - st.error(err, 'shoult not fail') - } - ) - - function clean() { - fs.renameSync('../../.git.bak', '../../.git') + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' + ) } }) @@ -559,34 +635,34 @@ test('remark-validate-links', function(t) { fs.renameSync('../../.git', '../../.git.bak') - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:{remote:"wooorm/test"}', - 'small.md' - ]).then( - function(result) { - clean() - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:{remote:\\"wooorm/test\\"}"', + 'small.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + fs.renameSync('../../.git.bak', '../../.git') + st.deepEqual( + [err, strip(stderr)], + [ + null, [ 'small.md', ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links', '', - '⚠ 1 warning' - ].join('\n'), - 'should work' - ) - }, - function(err) { - clean() - st.error(err, 'shoult not fail') - } - ) - - function clean() { - fs.renameSync('../../.git.bak', '../../.git') + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' + ) } }) @@ -595,34 +671,34 @@ test('remark-validate-links', function(t) { fs.renameSync('../../.git', '../../.git.bak') - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"wooorm/test",root:"../"', - 'small.md' - ]).then( - function(result) { - clean() - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"wooorm/test\\",root:\\"../\\""', + 'small.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + fs.renameSync('../../.git.bak', '../../.git') + st.deepEqual( + [err, strip(stderr)], + [ + null, [ 'small.md', ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links', '', - '⚠ 1 warning' - ].join('\n'), - 'should work' - ) - }, - function(err) { - clean() - st.error(err, 'shoult not fail') - } - ) - - function clean() { - fs.renameSync('../../.git.bak', '../../.git') + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' + ) } }) @@ -631,20 +707,27 @@ test('remark-validate-links', function(t) { fs.renameSync('../../.git', '../../.git.bak') - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:false', - '--use', - '../sort', - 'github.md', - 'examples/github.md' - ]).then( - function(result) { - clean() - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:false"', + '--use', + '../sort', + 'github.md', + 'examples/github.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + fs.renameSync('../../.git.bak', '../../.git') + st.deepEqual( + [err, strip(stderr)], + [ + null, [ 'examples/github.md', ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', @@ -665,382 +748,476 @@ test('remark-validate-links', function(t) { ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', ' 71:41-71:56 warning Link to unknown heading: `readme` missing-heading remark-validate-links', '', - '⚠ 15 warnings' - ].join('\n'), - 'should report' - ) - }, - function(err) { - clean() - st.error(err) - } - ) - - function clean() { - fs.renameSync('../../.git.bak', '../../.git') + '⚠ 15 warnings', + '' + ].join('\n') + ], + 'should work' + ) } }) t.test('should work when finding non-hosted Git remotes', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"ssh://git@domain.com/user/project.git"', - '--use', - '../sort', - 'small.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"ssh://git@domain.com/user/project.git\\""', + '--use', + '../sort', + 'small.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'small.md', - ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links', - '', - '⚠ 1 warning' - ].join('\n'), - 'should report' + null, + [ + 'small.md', + ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links', + '', + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should support a GitLab shortcode', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"gitlab:wooorm/test"', - '--use', - '../sort', - 'gitlab.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"gitlab:wooorm/test\\""', + '--use', + '../sort', + 'gitlab.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'gitlab.md', - ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', - ' 19:34-19:102 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', - ' 21:12-21:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', - ' 23:10-23:37 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', - ' 25:10-25:35 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', - ' 37:10-37:41 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links', - ' 39:10-39:39 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links', - ' 41:10-41:82 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links', - ' 43:10-43:83 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links', - ' 45:10-45:40 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', - ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 47:10-47:38 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', - ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 49:10-49:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', - ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 51:10-51:82 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', - ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - '', - '⚠ 17 warnings' - ].join('\n'), - 'should report' + null, + [ + 'gitlab.md', + ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links', + ' 19:34-19:102 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', + ' 21:12-21:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', + ' 23:10-23:37 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', + ' 25:10-25:35 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', + ' 37:10-37:41 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links', + ' 39:10-39:39 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links', + ' 41:10-41:82 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links', + ' 43:10-43:83 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links', + ' 45:10-45:40 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', + ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 47:10-47:38 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', + ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 49:10-49:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', + ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 51:10-51:82 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links', + ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + '', + '⚠ 17 warnings', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should support a Bitbucket shortcode', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"bitbucket:wooorm/test"', - '--use', - '../sort', - 'bitbucket.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"bitbucket:wooorm/test\\""', + '--use', + '../sort', + 'bitbucket.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'bitbucket.md', - ' 5:37-5:67 warning Link to unknown heading: `world` missing-heading remark-validate-links', - ' 21:34-21:104 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 23:12-23:83 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 25:10-25:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 27:10-27:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 39:10-39:60 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links', - ' 41:10-41:58 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links', - ' 43:10-43:103 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links', - ' 45:10-45:104 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links', - ' 47:10-47:56 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 47:10-47:56 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 49:10-49:54 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 49:10-49:54 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 51:10-51:99 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 51:10-51:99 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - ' 53:10-53:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', - ' 53:10-53:100 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', - '', - '⚠ 17 warnings' - ].join('\n'), - 'should report' + null, + [ + 'bitbucket.md', + ' 5:37-5:67 warning Link to unknown heading: `world` missing-heading remark-validate-links', + ' 21:34-21:104 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 23:12-23:83 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 25:10-25:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 27:10-27:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 39:10-39:60 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links', + ' 41:10-41:58 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links', + ' 43:10-43:103 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links', + ' 45:10-45:104 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links', + ' 47:10-47:56 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 47:10-47:56 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 49:10-49:54 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 49:10-49:54 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 51:10-51:99 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 51:10-51:99 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + ' 53:10-53:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links', + ' 53:10-53:100 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links', + '', + '⚠ 17 warnings', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should suggest similar links', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'suggestions.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'suggestions.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'suggestions.md', - ' 3:22-3:37 warning Link to unknown heading: `helloo`. Did you mean `hello` missing-heading remark-validate-links', - ' 7:17-7:39 warning Link to unknown heading in `github.md`: `fiiiles`. Did you mean `files` missing-heading-in-file remark-validate-links', - '', - '⚠ 2 warnings' - ].join('\n'), - 'should report' + null, + [ + 'suggestions.md', + ' 3:22-3:37 warning Link to unknown heading: `helloo`. Did you mean `hello` missing-heading remark-validate-links', + ' 7:17-7:39 warning Link to unknown heading in `github.md`: `fiiiles`. Did you mean `files` missing-heading-in-file remark-validate-links', + '', + '⚠ 2 warnings', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should recognise links to particular lines', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"wooorm/test"', - '--use', - '../sort', - 'line-links.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"wooorm/test\\""', + '--use', + '../sort', + 'line-links.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'line-links.md', - ' 5:9-5:61 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links', - ' 9:1-9:71 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links', - '', - '⚠ 2 warnings' - ].join('\n'), - 'should report' + null, + [ + 'line-links.md', + ' 5:9-5:61 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links', + ' 9:1-9:71 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links', + '', + '⚠ 2 warnings', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should recognise links with encoded URLs', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"wooorm/test"', - '--use', - '../sort', - 'weird-characters.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"wooorm/test\\""', + '--use', + '../sort', + 'weird-characters.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'weird-characters.md', - ' 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', - ' 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', - ' 15:17-15:114 warning Link to unknown heading in `examples/weird#characters.md`: `world` missing-heading-in-file remark-validate-links', - ' 17:17-17:120 warning Link to unknown heading in `examples/weird#character/readme.md`: `world` missing-heading-in-file remark-validate-links', - '', - '⚠ 4 warnings' - ].join('\n'), - 'should report' + null, + [ + 'weird-characters.md', + ' 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', + ' 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', + ' 15:17-15:114 warning Link to unknown heading in `examples/weird#characters.md`: `world` missing-heading-in-file remark-validate-links', + ' 17:17-17:120 warning Link to unknown heading in `examples/weird#character/readme.md`: `world` missing-heading-in-file remark-validate-links', + '', + '⚠ 4 warnings', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should check images', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"wooorm/test"', - '--use', - '../sort', - 'images.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"wooorm/test\\""', + '--use', + '../sort', + 'images.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], [ - 'images.md', - ' 19:10-19:50 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', - ' 21:12-21:42 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', - ' 23:10-23:91 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', - ' 35:1-35:38 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', - ' 37:1-37:79 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', - '', - '⚠ 5 warnings' - ].join('\n'), - 'should report' + null, + [ + 'images.md', + ' 19:10-19:50 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', + ' 21:12-21:42 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', + ' 23:10-23:91 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', + ' 35:1-35:38 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', + ' 37:1-37:79 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links', + '', + '⚠ 5 warnings', + '' + ].join('\n') + ], + 'should work' ) - }, st.error) + } }) t.test('should support query parameters', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"wooorm/test"', - '--use', - '../sort', - 'query-params.md' - ]).then( - function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"wooorm/test\\""', + '--use', + '../sort', + 'query-params.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], + [ + null, [ 'query-params.md', ' 9:33-9:55 warning Link to unknown heading: `query-params?`. Did you mean `query-params` missing-heading remark-validate-links', '', - '⚠ 1 warning' - ].join('\n'), - 'should report' - ) - }, - function(err) { - st.error(err, 'should not fail') - } - ) + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' + ) + } }) t.test('should support case insensitive headings', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..', - '--use', - '../sort', - 'case-insensitive-headings.md' - ]).then( - function(result) { - st.equal( - strip(result.stderr), + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..', + '--use', + '../sort', + 'case-insensitive-headings.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], + [ + null, [ 'case-insensitive-headings.md', ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links', ' 9:16-9:48 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links', '', - '⚠ 2 warnings' - ].join('\n'), - 'should report' - ) - }, - function(err) { - st.error(err, 'should not fail') - } - ) + '⚠ 2 warnings', + '' + ].join('\n') + ], + 'should work' + ) + } }) t.test('should ignore external links', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:"wooorm/test"', - '--use', - '../sort', - 'external.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), - 'external.md: no issues found', - 'should report' + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=repository:\\"wooorm/test\\""', + '--use', + '../sort', + 'external.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], + [null, 'external.md: no issues found\n'], + 'should work' ) - }, st.error) + } }) t.test('should ignore external links (without repo)', function(st) { st.plan(1) - execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=repository:false', - '--use', - '../sort', - 'external.md' - ]).then(function(result) { - st.equal( - strip(result.stderr), - 'external.md: no issues found', - 'should report' + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '../..=repository:false', + '--use', + '../sort', + 'external.md' + ].join(' '), + onexec + ) + + function onexec(err, stdout, stderr) { + st.deepEqual( + [err, strip(stderr)], + [null, 'external.md: no issues found\n'], + 'should work' ) - }, st.error) + } }) t.test('should support self-hosted Git solutions', function(st) { st.plan(1) - Promise.resolve() - .then(function() { - return execa('git', ['init']) - }) - .then(function() { - return execa('git', [ - 'remote', - 'add', - 'origin', - 'git@gitlab.acme.company:acme/project.git' - ]) - }) - .then(function() { - return execa(bin, [ - '--no-config', - '--no-ignore', - '--use', - '../..=urlConfig:{hostname:"gitlab.acme.com",prefix:"/acme/project/blob/",headingPrefix:"#",lines:true}', - 'self-hosted.md' - ]) - }) - .then( - function(result) { - clean() - st.equal( - strip(result.stderr), - [ - 'self-hosted.md', - ' 5:1-5:82 warning Link to unknown heading: `world` missing-heading remark-validate-links', - '', - '⚠ 1 warning' - ].join('\n'), - 'should report' - ) - }, - function(err) { - clean() - st.error(err) - } + childProcess.exec('git init', oninit) + + function oninit(err) { + if (err) { + t.ifErr(err) + } else { + childProcess.exec( + 'git remote add origin git@gitlab.acme.company:acme/project.git', + onremote + ) + } + } + + function onremote(err) { + if (err) { + clean() + t.ifErr(err) + } else { + childProcess.exec( + [ + bin, + '--no-config', + '--no-ignore', + '--use', + '"../..=urlConfig:{hostname:\\"gitlab.acme.com\\",prefix:\\"/acme/project/blob/\\",headingPrefix:\\"#\\",lines:true}"', + 'self-hosted.md' + ].join(' '), + onexec + ) + } + } + + function onexec(err, stdout, stderr) { + clean() + st.deepEqual( + [err, strip(stderr)], + [ + null, + [ + 'self-hosted.md', + ' 5:1-5:82 warning Link to unknown heading: `world` missing-heading remark-validate-links', + '', + '⚠ 1 warning', + '' + ].join('\n') + ], + 'should work' ) + } function clean() { rimraf.sync('./.git')