From 2aaa0a9097d3d1d9b2e865d569a48a511bd08386 Mon Sep 17 00:00:00 2001 From: Alexandru Placinta Date: Mon, 30 Oct 2023 15:26:31 +0100 Subject: [PATCH] Advance with coverage --- tests/toolchain_install.test.ts | 67 ++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/tests/toolchain_install.test.ts b/tests/toolchain_install.test.ts index 139df62c..f2882575 100644 --- a/tests/toolchain_install.test.ts +++ b/tests/toolchain_install.test.ts @@ -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"; @@ -39,11 +38,9 @@ describe("Tests of toolchain command", () => { installToolchain: jest.fn(async (): Promise => { return Promise.resolve(0); }), - version: jest.fn((): Promise => { - return Promise.resolve(semver.parse("2.2.2") as semver.SemVer); - }), selfUpdate: jest.fn(), activeToolchain: jest.fn().mockReturnValue("active toolchain"), + addTargets: jest.fn(), }; afterEach(() => { @@ -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)); @@ -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);