From bc78f0566f08be92c66d95238557e865e4cfc114 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Tue, 6 May 2025 13:40:52 -0500 Subject: [PATCH 1/8] fix: return exit code 1 when dead links found --- markdown-link-check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown-link-check b/markdown-link-check index 3849a012..a00a124f 100755 --- a/markdown-link-check +++ b/markdown-link-check @@ -303,7 +303,7 @@ async function runMarkdownLinkCheck(filenameForOutput, markdown, opts) { )); if (err) throw null; - else if (results.some((result) => result.status === 'dead')) return; + else if (results.some((result) => result.status === 'dead')) throw null; else return; } From dc70b823fcddc6cc555f741f0a657487c214fb13 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sun, 11 May 2025 07:46:06 +0900 Subject: [PATCH 2/8] add test cases to check CLI exit code --- test/markdown-link-check.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/markdown-link-check.test.js b/test/markdown-link-check.test.js index fdcfca24..0efd0b65 100644 --- a/test/markdown-link-check.test.js +++ b/test/markdown-link-check.test.js @@ -5,6 +5,7 @@ const path = require('path'); const expect = require('expect.js'); const http = require('http'); const express = require('express'); +const child_process = require('child_process'); const markdownLinkCheck = require('../'); const dirname = process.platform === 'win32' ? __dirname.replace(/\\/g, '/') : __dirname; @@ -436,4 +437,20 @@ describe('markdown-link-check', function () { done(); }); }); + + describe("CLI", function () { + const cliPath = path.join(dirname, '..', 'markdown-link-check'); + + it("exits with 0 if all links are ok", function () { + const { status, output } = child_process.spawnSync(cliPath, [path.join(dirname, 'alive-links-only.md')]); + expect(status).to.be(0); + expect(output.toString()).to.contain('links checked.'); + }); + + it("exits with 1 if any link is broken", function () { + const { status, output } = child_process.spawnSync(cliPath, [path.join(dirname, 'section-links.md')]); + expect(status).to.be(1); + expect(output.toString()).to.contain('dead links found!'); + }); + }); }); From f55187526ba5369d5864cee33f8b663706c336f1 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Thu, 3 Jul 2025 11:07:19 +0900 Subject: [PATCH 3/8] fix for windows --- test/markdown-link-check.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/markdown-link-check.test.js b/test/markdown-link-check.test.js index 0efd0b65..1b4a6a2b 100644 --- a/test/markdown-link-check.test.js +++ b/test/markdown-link-check.test.js @@ -439,16 +439,16 @@ describe('markdown-link-check', function () { }); describe("CLI", function () { - const cliPath = path.join(dirname, '..', 'markdown-link-check'); + const cliPath = path.join(__dirname, '..', 'markdown-link-check'); it("exits with 0 if all links are ok", function () { - const { status, output } = child_process.spawnSync(cliPath, [path.join(dirname, 'alive-links-only.md')]); + const { status, output } = child_process.spawnSync(cliPath, [path.join(__dirname, 'alive-links-only.md')]); expect(status).to.be(0); expect(output.toString()).to.contain('links checked.'); }); it("exits with 1 if any link is broken", function () { - const { status, output } = child_process.spawnSync(cliPath, [path.join(dirname, 'section-links.md')]); + const { status, output } = child_process.spawnSync(cliPath, [path.join(__dirname, 'section-links.md')]); expect(status).to.be(1); expect(output.toString()).to.contain('dead links found!'); }); From 11016c7a787514ec2052985e3fddda455ce53953 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 8 Sep 2025 14:33:01 +0900 Subject: [PATCH 4/8] debug --- test/markdown-link-check.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/markdown-link-check.test.js b/test/markdown-link-check.test.js index 1b4a6a2b..111b00ba 100644 --- a/test/markdown-link-check.test.js +++ b/test/markdown-link-check.test.js @@ -443,12 +443,14 @@ describe('markdown-link-check', function () { it("exits with 0 if all links are ok", function () { const { status, output } = child_process.spawnSync(cliPath, [path.join(__dirname, 'alive-links-only.md')]); + console.log(output.toString()); expect(status).to.be(0); expect(output.toString()).to.contain('links checked.'); }); it("exits with 1 if any link is broken", function () { const { status, output } = child_process.spawnSync(cliPath, [path.join(__dirname, 'section-links.md')]); + console.log(output.toString()); expect(status).to.be(1); expect(output.toString()).to.contain('dead links found!'); }); From 0679d4007c57794c772f10cfcfa42791fae313c0 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 8 Sep 2025 14:37:13 +0900 Subject: [PATCH 5/8] debug --- test/markdown-link-check.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/markdown-link-check.test.js b/test/markdown-link-check.test.js index 111b00ba..d7457488 100644 --- a/test/markdown-link-check.test.js +++ b/test/markdown-link-check.test.js @@ -442,7 +442,9 @@ describe('markdown-link-check', function () { const cliPath = path.join(__dirname, '..', 'markdown-link-check'); it("exits with 0 if all links are ok", function () { - const { status, output } = child_process.spawnSync(cliPath, [path.join(__dirname, 'alive-links-only.md')]); + const x = child_process.spawnSync(cliPath, [path.join(__dirname, 'alive-links-only.md')]); + console.log(x); + const { status, output } = x; console.log(output.toString()); expect(status).to.be(0); expect(output.toString()).to.contain('links checked.'); From 8dc32a283e48fa049cf8a43bb4b5a4978ca005b0 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 8 Sep 2025 14:38:57 +0900 Subject: [PATCH 6/8] debug --- test/markdown-link-check.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/markdown-link-check.test.js b/test/markdown-link-check.test.js index d7457488..8f6b81a7 100644 --- a/test/markdown-link-check.test.js +++ b/test/markdown-link-check.test.js @@ -444,6 +444,7 @@ describe('markdown-link-check', function () { it("exits with 0 if all links are ok", function () { const x = child_process.spawnSync(cliPath, [path.join(__dirname, 'alive-links-only.md')]); console.log(x); + console.log(x.error); const { status, output } = x; console.log(output.toString()); expect(status).to.be(0); From 32da17529c783b4f468407850fea1581c9101d95 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 8 Sep 2025 14:42:11 +0900 Subject: [PATCH 7/8] update --- test/markdown-link-check.test.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/markdown-link-check.test.js b/test/markdown-link-check.test.js index 8f6b81a7..19e30c73 100644 --- a/test/markdown-link-check.test.js +++ b/test/markdown-link-check.test.js @@ -442,18 +442,13 @@ describe('markdown-link-check', function () { const cliPath = path.join(__dirname, '..', 'markdown-link-check'); it("exits with 0 if all links are ok", function () { - const x = child_process.spawnSync(cliPath, [path.join(__dirname, 'alive-links-only.md')]); - console.log(x); - console.log(x.error); - const { status, output } = x; - console.log(output.toString()); + const { status, output } = child_process.spawnSync(process.execPath, [cliPath, path.join(__dirname, 'alive-links-only.md')]); expect(status).to.be(0); expect(output.toString()).to.contain('links checked.'); }); it("exits with 1 if any link is broken", function () { - const { status, output } = child_process.spawnSync(cliPath, [path.join(__dirname, 'section-links.md')]); - console.log(output.toString()); + const { status, output } = child_process.spawnSync(process.execPath, [cliPath, [path.join(__dirname, 'section-links.md')]]); expect(status).to.be(1); expect(output.toString()).to.contain('dead links found!'); }); From 827c514f2fb7c1f7e8e7a69dba89f170846c2f69 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 8 Sep 2025 14:51:14 +0900 Subject: [PATCH 8/8] increase timeout --- test/markdown-link-check.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/markdown-link-check.test.js b/test/markdown-link-check.test.js index 19e30c73..6ebbc3ed 100644 --- a/test/markdown-link-check.test.js +++ b/test/markdown-link-check.test.js @@ -448,6 +448,7 @@ describe('markdown-link-check', function () { }); it("exits with 1 if any link is broken", function () { + this.timeout(60000) const { status, output } = child_process.spawnSync(process.execPath, [cliPath, [path.join(__dirname, 'section-links.md')]]); expect(status).to.be(1); expect(output.toString()).to.contain('dead links found!');