Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create annotations using workflow commands #20

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 38 additions & 29 deletions __tests__/processResults.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as core from "@actions/core";

import inputs from "../src/inputs";
import { CHECK_NAME, processResults } from "../src/processResults";
import { processResults } from "../src/processResults";

jest.mock("@actions/core", () => ({
debug: jest.fn(),
Expand All @@ -16,6 +18,7 @@ jest.mock("../src/inputs", () => ({

const errorMsg = {
line: 10,
column: 5,
severity: 2,
ruleId: "no-var",
message: "no var allowed",
Expand Down Expand Up @@ -46,41 +49,47 @@ const mockResults = [
},
];

it("returns check endpoint payload with correct annotations", () => {
// @ts-expect-error
const payload = processResults(mockResults);

expect(payload).toMatchObject({
conclusion: "failure",
output: {
title: CHECK_NAME,
summary: "3 error(s) found",
annotations: expect.any(Array),
},
});
beforeEach(() => {
(core.startGroup as jest.Mock).mockClear();
(core.endGroup as jest.Mock).mockClear();
(core.warning as jest.Mock).mockClear();
(core.error as jest.Mock).mockClear();
});

const annotations = payload.output?.annotations;
expect(annotations).toHaveLength(4);
it("should return the number of errors", () => {
// @ts-ignore
expect(processResults(mockResults)).toEqual(3);
});

it("passes the check if there are no errors", () => {
const payload = processResults([
{
filePath: "/bar",
// @ts-expect-error
messages: [warnMsg, invalidMsg],
},
]);
it("start and end a group based on file", () => {
// @ts-ignore
processResults(mockResults);

expect(payload.conclusion).toEqual("success");
expect(core.startGroup).toHaveBeenCalledTimes(2);
expect(core.startGroup).toHaveBeenCalledWith("/foo");
expect(core.startGroup).toHaveBeenCalledWith("/bar");
});

it("does not include warnings if quiet option is true", () => {
it("should log each lint message", () => {
// @ts-ignore
processResults(mockResults);

expect(core.warning).toHaveBeenCalledTimes(1);
expect(core.warning).toHaveBeenCalledWith("file=/foo,line=5::[no-console] no console allowed");

expect(core.error).toHaveBeenCalledTimes(3);
expect(core.error).toHaveBeenCalledWith("file=/foo,line=10,col=5::[no-var] no var allowed");
expect(core.error).toHaveBeenCalledWith("file=/foo,line=20,col=5::[no-var] no var allowed");
expect(core.error).toHaveBeenCalledWith("file=/bar,line=10,col=5::[no-var] no var allowed");
});

it("should skip warnings if quiet option is set", () => {
Object.defineProperty(inputs, "quiet", {
get: () => true,
});
// @ts-expect-error
const payload = processResults(mockResults);
expect(payload.output?.annotations).toHaveLength(3);
expect(payload.output?.annotations?.some((a) => a.annotation_level === "warning")).toBe(false);

// @ts-ignore
processResults(mockResults);

expect(core.warning).not.toHaveBeenCalled();
});
2,001 changes: 1,610 additions & 391 deletions lib/index.js

Large diffs are not rendered by default.

Loading