Skip to content

Commit 198c52c

Browse files
azuclaude
andauthored
test: add local server tests for preferGET option (#159)
- Add /preferGET endpoint to test server that requires GET method - Add test cases for preferGET option using local server - Replace external service dependency with local test server 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent 8afadf1 commit 198c52c

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

test/no-dead-link.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,19 @@ tester.run("no-dead-link", rule, {
9595
{
9696
inputPath: path.join(__dirname, "fixtures/a.md")
9797
},
98-
// SKIP: External service tests (npmjs.com)
99-
// {
100-
// text: "should success with GET method: [npm results for textlint](https://www.npmjs.com/search?q=textlint)",
101-
// options: {
102-
// preferGET: ["https://www.npmjs.com"]
103-
// }
104-
// },
105-
// {
106-
// text: "should success with GET method whether the option is specific URL: [npm results for textlint](https://www.npmjs.com/search?q=textlint)",
107-
// options: {
108-
// preferGET: ["https://www.npmjs.com/search?q=textlint-rule"]
109-
// }
110-
// },
98+
// Test preferGET option with local server
99+
{
100+
text: `should success with GET method: [preferGET endpoint](${TEST_SERVER_URL}/preferGET)`,
101+
options: {
102+
preferGET: [TEST_SERVER_URL]
103+
}
104+
},
105+
{
106+
text: `should success with GET method when the option is specific URL: [preferGET endpoint](${TEST_SERVER_URL}/preferGET)`,
107+
options: {
108+
preferGET: [`${TEST_SERVER_URL}/preferGET`]
109+
}
110+
},
111111
// Test that redirect is not reported when ignoreRedirects is true
112112
{
113113
text: `should not report redirect when ignoreRedirects is true: ${TEST_SERVER_URL}/301`,

test/test-server.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ export async function startTestServer(options: TestServerOptions = {}): Promise<
9191
}, 10000); // 10 seconds delay
9292
break;
9393

94+
case "/preferGET":
95+
// Endpoint that only works with GET method
96+
// Used to test preferGET option
97+
if (req.method === "HEAD") {
98+
// HEAD request returns 405 Method Not Allowed
99+
res.writeHead(405, { "Content-Type": "text/plain" });
100+
res.end();
101+
} else if (req.method === "GET") {
102+
// GET request returns 200 OK
103+
res.writeHead(200, { "Content-Type": "text/html" });
104+
res.end("<html><body>This endpoint requires GET method</body></html>");
105+
} else {
106+
res.writeHead(405, { "Content-Type": "text/plain" });
107+
res.end("Method Not Allowed");
108+
}
109+
break;
110+
94111
default:
95112
// Default to 200 OK for any other path
96113
res.writeHead(200, { "Content-Type": "text/plain" });

0 commit comments

Comments
 (0)