Add unit tests for getArchitecture function
Co-authored-by: xhyrom <56601352+xhyrom@users.noreply.github.com>
This commit is contained in:
parent
9f3f7833ba
commit
340f0773db
91
tests/utils.spec.ts
Normal file
91
tests/utils.spec.ts
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
import { afterEach, describe, expect, it, mock, spyOn } from "bun:test";
|
||||||
|
import { getArchitecture } from "../src/utils";
|
||||||
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
|
describe("getArchitecture", () => {
|
||||||
|
let warningSpy: ReturnType<typeof spyOn>;
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
warningSpy?.mockRestore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return x64 for Windows with arm64 architecture", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("windows", "arm64");
|
||||||
|
|
||||||
|
expect(result).toBe("x64");
|
||||||
|
expect(warningSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
"⚠️ Bun does not provide native arm64 builds for Windows."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return x64 for Windows with aarch64 architecture", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("windows", "aarch64");
|
||||||
|
|
||||||
|
expect(result).toBe("x64");
|
||||||
|
expect(warningSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
|
expect.stringContaining(
|
||||||
|
"⚠️ Bun does not provide native arm64 builds for Windows."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return aarch64 for non-Windows platforms with arm64", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("linux", "arm64");
|
||||||
|
|
||||||
|
expect(result).toBe("aarch64");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return aarch64 for macOS with arm64", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("darwin", "arm64");
|
||||||
|
|
||||||
|
expect(result).toBe("aarch64");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return original arch value for x64", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("windows", "x64");
|
||||||
|
|
||||||
|
expect(result).toBe("x64");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return original arch value for x86", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("linux", "x86");
|
||||||
|
|
||||||
|
expect(result).toBe("x86");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return original arch value for aarch64 on Linux", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
const result = getArchitecture("linux", "aarch64");
|
||||||
|
|
||||||
|
expect(result).toBe("aarch64");
|
||||||
|
expect(warningSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should emit warning with correct message for Windows ARM64 fallback", () => {
|
||||||
|
warningSpy = spyOn(core, "warning");
|
||||||
|
getArchitecture("windows", "arm64");
|
||||||
|
|
||||||
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
|
[
|
||||||
|
"⚠️ Bun does not provide native arm64 builds for Windows.",
|
||||||
|
"Using x64 baseline build which will run through Microsoft's x64 emulation layer.",
|
||||||
|
"This may result in reduced performance and potential compatibility issues.",
|
||||||
|
"💡 For best performance, consider using x64 Windows runners or other platforms with native support.",
|
||||||
|
].join("\n")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user