Skip to content

Commit

Permalink
fix: ignore req.get("host") to get parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Jul 21, 2023
1 parent 6e3dc76 commit 0c307d7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const findRouting = async ({ AST, fileContent }: { AST: any; fileContent: string
if (!pathValue) {
return []; // skip: it will only includes middleware
}
// single argument should be ignored
// req.get("host"); it is not routing
if (node.arguments.length === 1) {
return [];
}
const middlewareArguments =
method === "use"
? // @ts-ignore
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/req.get-but-it-is-not-router/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Router } from "express";

const app = Router();

app.get("/get", (req) => {
const host = req.get("host"); // it is not router
});
export default app;
17 changes: 17 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,21 @@ describe("app snapshot", function () {
| | use | /useEvents | Anonymous Function | app.ts#L6-L8 |`
);
});
it("should ignore req.get() for getting paramter", async () => {
const rootDir = path.join(__dirname, "fixtures/req.get-but-it-is-not-router");
const mdResults = await analyzeDependencies({
filePaths: await globby(["**/*.ts"], { cwd: rootDir }),
cwd: rootDir,
rootBaseUrl: "",
outputFormat: "markdown"
});
assert.strictEqual(
mdResults,
`\
| File | Method | Routing | Middlewares | FilePath |
| ------ | ------ | ------- | ----------- | ------------ |
| app.ts | | | | |
| | get | /get | | app.ts#L5-L7 |`
);
});
});

0 comments on commit 0c307d7

Please sign in to comment.