fix: coerce weird versions
Node.js CI / CI (push) Failing after 12s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m14s

This commit is contained in:
2026-02-03 19:19:29 -08:00
parent df608370a4
commit 0dbedfe546
2 changed files with 37 additions and 4 deletions
@@ -291,6 +291,30 @@ describe("dependencyAnalyzerService", () => {
expect(result[0]?.currentVersion).toBe(">=1.0.0");
});
it("should handle partial version numbers like '2'", async() => {
expect.assertions(2);
const mockNpmService = createMockNpmService();
const oldDate = getDaysAgoIso(15);
mockNpmService.getPackageInfo.mockResolvedValue({
"dist-tags": { latest: "3.0.0" },
"name": "test-package",
"time": { "3.0.0": oldDate },
"versions": { "3.0.0": { version: "3.0.0" } },
});
const { DependencyAnalyzerService }
= await import("../../src/services/dependencyAnalyzerService.js");
const analyzerService = new DependencyAnalyzerService(
mockNpmService as Parameters<typeof DependencyAnalyzerService>[0],
);
const result = await analyzerService.analyzePackageJson({
dependencies: {
"test-package": "2",
},
});
expect(result).toHaveLength(1);
expect(result[0]?.currentVersion).toBe("2");
});
it("should handle npm errors gracefully", async() => {
expect.assertions(1);
const mockNpmService = createMockNpmService();