Skip to content

Commit 2913ff1

Browse files
authored
Merge pull request #452 from kt3k/fix-exit-code
fix: return exit code 1 when dead links found
2 parents 221cb85 + 827c514 commit 2913ff1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

markdown-link-check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ async function runMarkdownLinkCheck(filenameForOutput, markdown, opts) {
451451
));
452452

453453
if (err) throw null;
454-
else if (results.some((result) => result.status === 'dead')) return;
454+
else if (results.some((result) => result.status === 'dead')) throw null;
455455
else return;
456456
}
457457

test/markdown-link-check.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const path = require('path');
55
const expect = require('expect.js');
66
const http = require('http');
77
const express = require('express');
8+
const child_process = require('child_process');
89
const markdownLinkCheck = require('../');
910
const dirname = process.platform === 'win32' ? __dirname.replace(/\\/g, '/') : __dirname;
1011

@@ -442,4 +443,21 @@ describe('markdown-link-check', function () {
442443
done();
443444
});
444445
});
446+
447+
describe("CLI", function () {
448+
const cliPath = path.join(__dirname, '..', 'markdown-link-check');
449+
450+
it("exits with 0 if all links are ok", function () {
451+
const { status, output } = child_process.spawnSync(process.execPath, [cliPath, path.join(__dirname, 'alive-links-only.md')]);
452+
expect(status).to.be(0);
453+
expect(output.toString()).to.contain('links checked.');
454+
});
455+
456+
it("exits with 1 if any link is broken", function () {
457+
this.timeout(60000)
458+
const { status, output } = child_process.spawnSync(process.execPath, [cliPath, [path.join(__dirname, 'section-links.md')]]);
459+
expect(status).to.be(1);
460+
expect(output.toString()).to.contain('dead links found!');
461+
});
462+
});
445463
});

0 commit comments

Comments
 (0)