Skip to content

Commit

Permalink
Advance with coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
placintaalexandru committed Oct 30, 2023
1 parent 3a93e12 commit 2aaa0a9
Showing 1 changed file with 50 additions and 17 deletions.
67 changes: 50 additions & 17 deletions tests/toolchain_install.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { installToolchainCommand } from "../src/toolchain_install";
import { RustUp } from "../src/installers/rustup";
import * as semver from "semver";
import { Outputs } from "../src/output";
import * as mockedCore from "@actions/core";

Expand Down Expand Up @@ -39,11 +38,9 @@ describe("Tests of toolchain command", () => {
installToolchain: jest.fn(async (): Promise<number> => {
return Promise.resolve(0);
}),
version: jest.fn((): Promise<semver.SemVer> => {
return Promise.resolve(semver.parse("2.2.2") as semver.SemVer);
}),
selfUpdate: jest.fn(),
activeToolchain: jest.fn().mockReturnValue("active toolchain"),
addTargets: jest.fn(),
};

afterEach(() => {
Expand All @@ -66,19 +63,6 @@ describe("Tests of toolchain command", () => {
.parse([]);
});

test("Install toolchain: downgrade on nightly", () => {
(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
return Promise.resolve(mockedRustUp);
});
(Outputs.outputs as jest.Mock).mockReturnValue(Promise.resolve([]));

installToolchainCommand
.hook("postAction", () => {
expect(mockedRustUp.selfUpdate).toHaveBeenCalledTimes(1);
})
.parse(["node", "exe", "--toolchain", "nightly"]);
});

test("Install toolchain: should self update due to components", () => {
mockedRustUp.supportComponents.mockReturnValue(Promise.resolve(false));

Expand All @@ -101,6 +85,55 @@ describe("Tests of toolchain command", () => {
]);
});

// test("Install toolchain: downgrade on nightly", () => {
// mockedRustUp.supportProfiles.mockReturnValue(Promise.resolve(true));
// mockedRustUp.supportComponents.mockReturnValue(Promise.resolve(true));
//
// (RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
// return Promise.resolve(mockedRustUp);
// });
// (Outputs.outputs as jest.Mock).mockReturnValue(Promise.resolve([]));
//
// installToolchainCommand
// .hook("postAction", () => {
// expect(mockedRustUp.installToolchain).toHaveBeenCalledTimes(1);
// expect(mockedRustUp.installToolchain).toHaveBeenCalledWith({
// allowDowngrade: true,
// components: ["c1", "c2"],
// default: false,
// force: false,
// noSelfUpdate: true,
// override: false,
// profile: "default",
// targets: [],
// toolchain: "nightly",
// });
// })
// .parse([
// "node",
// "exe",
// "--toolchain",
// "nightly",
// "--components",
// "c1",
// "--components",
// "c2",
// ]);
// });

test("Install toolchain: add targets", () => {
(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
return Promise.resolve(mockedRustUp);
});
(Outputs.outputs as jest.Mock).mockReturnValue(Promise.resolve([]));

installToolchainCommand
.hook("postAction", () => {
expect(mockedRustUp.addTargets).toHaveBeenCalledTimes(1);
})
.parse(["node", "exe", "--targets", "t1", "--targets", "t2"]);
});

test("Outputs", () => {
(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
return Promise.resolve(mockedRustUp);
Expand Down

0 comments on commit 2aaa0a9

Please sign in to comment.