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 29, 2023
1 parent 06b1a58 commit c80cdd7
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/output.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Output, OutputExporter } from "./types";
import { Output } from "./types";
import { execStdout } from "./utils/exec";
import * as core from "@actions/core";

export class Outputs implements OutputExporter {
public async outputs(): Promise<Output[]> {
export class Outputs {
public static async outputs(): Promise<Output[]> {
return Promise.resolve([
await Outputs.rustc(),
await Outputs.rustcHash(),
Expand Down
2 changes: 1 addition & 1 deletion src/toolchain_install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const installToolchainCommand = new Command()

core.info(await rustup.activeToolchain());

(await new Outputs().outputs()).forEach((output) => {
(await Outputs.outputs()).forEach((output) => {
core.setOutput(output.name, output.value);
});
});
13 changes: 0 additions & 13 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,3 @@ export interface Output {
name: string;
value: string;
}

/**
* `Output` defines simple interface to provide a list of outputs that the action exports.
*/
export interface OutputExporter {
/**
* Creates a list of outputs that will be exported by the GitHub action.
*
* The signature includes async as some outputs require async code to be retrieved.
* @return{Promise<Output[]>}
*/
outputs(): Promise<Output[]>;
}
1 change: 1 addition & 0 deletions tests/installers/rustup_init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RustUpInit } from "../../src/installers/rustup_init";
import process from "process";

jest.mock("@actions/exec");
jest.mock("@actions/core");
jest.mock("@actions/tool-cache", () => ({
downloadTool: jest.fn().mockReturnValue("some path"),
}));
Expand Down
2 changes: 1 addition & 1 deletion tests/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("Outputs tests", () => {
);

expect(
(await new Outputs().outputs())
(await Outputs.outputs())
.map((output) => {
return output.value;
})
Expand Down
79 changes: 79 additions & 0 deletions tests/toolchain_install.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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";

jest.mock("@actions/exec", () => ({
exec: jest.fn(),
}));
jest.mock("@actions/core", () => ({
debug: jest.fn(),
startGroup: jest.fn(),
endGroup: jest.fn(),
info: jest.fn(),
error: jest.fn(),
setOutput: jest.fn(),
}));
jest.mock("../src/installers/rustup", () => ({
RustUp: {
getOrInstall: jest.fn(),
},
}));
jest.mock("../src/output", () => ({
Outputs: {
outputs: jest.fn(),
},
}));

describe("Tests of toolchain command", () => {
const originalEnv = process.env;

afterEach(() => {
process.env = originalEnv;
jest.resetAllMocks();
});

test("Outputs", async () => {

Check failure on line 37 in tests/toolchain_install.test.ts

View workflow job for this annotation

GitHub Actions / Lint check

Async arrow function has no 'await' expression
process.env.INPUT_PROFILE = "minim";

const obj = {
supportProfiles: jest.fn(async (): Promise<boolean> => {
return Promise.resolve(true);
}),
supportComponents: jest.fn(async (): Promise<boolean> => {
return Promise.resolve(true);
}),
setProfile: jest.fn(),
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"),
};
(RustUp.getOrInstall as jest.Mock).mockImplementation(async () => {
return Promise.resolve(obj);
});
(Outputs.outputs as jest.Mock).mockReturnValue(
Promise.resolve([
{
name: "rustc",
value: "version",
},
]),
);

installToolchainCommand
.hook("postAction", () => {
expect(mockedCore.setOutput).toHaveBeenCalledTimes(1);
expect(mockedCore.setOutput).toHaveBeenCalledWith(
"rustc",
"version",
);
})
.parse([]);
});
});

0 comments on commit c80cdd7

Please sign in to comment.