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 28, 2023
1 parent 1346dc9 commit 46f8461
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions tests/installers/rustup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { RustUpInit } from "../../src/installers/rustup_init";
import * as mockedIo from "@actions/io";
import * as mockedExec from "@actions/exec";
import * as fcj from "@fast-check/jest";
import semver = require("semver/preload");
import * as mockedExecUtils from "../../src/utils/exec";
import * as semver from "semver";

jest.mock("@actions/io", () => ({
which: jest.fn(),
Expand Down Expand Up @@ -101,12 +102,11 @@ describe("Tests of rustup", () => {
(mockedIo.which as jest.Mock).mockReturnValue(
Promise.resolve("/somepath/rustup"),
);
jest.mock("@actions/io", () => ({
parse: jest.fn().mockReturnValue(null),
}));

const rustUp = await RustUp.getOrInstall();

// Save original implementation
const impl = semver.parse;
const mock = jest.spyOn(semver, "parse").mockReturnValue(null);
let threwError = false;

try {
Expand All @@ -116,9 +116,6 @@ describe("Tests of rustup", () => {
}

expect(threwError);

// Restore original implementation as some tests depends on semver.parse
mock.mockImplementation(impl);
});

test("Install toolchain: components", async () => {
Expand Down Expand Up @@ -351,4 +348,24 @@ describe("Tests of rustup", () => {
expect(await rustUp.supportComponents()).toBe(true);
},
);

test("Active toolchain", async () => {
const path = "/somepath/rustup";
(mockedIo.which as jest.Mock).mockReturnValue(Promise.resolve(path));

const result = "string";
const rustUp = await RustUp.getOrInstall();

jest.spyOn(mockedExecUtils, "execStdout").mockReturnValue(
Promise.resolve(result),
);

await rustUp.activeToolchain();

expect(mockedExecUtils.execStdout).toHaveBeenCalledWith(
path,
["show", "active-toolchain"],
undefined,
);
});
});

0 comments on commit 46f8461

Please sign in to comment.