Skip to content

Commit

Permalink
ci: set up vitest (#41)
Browse files Browse the repository at this point in the history
Trying out Vitest to start adding test coverage. This PR adds vitest,
scripts for running and watching tests, a simple example test, and adds
a Test step to ci workflow.
  • Loading branch information
jordan-acosta authored Jul 1, 2024
1 parent 78a1a15 commit 7aba478
Show file tree
Hide file tree
Showing 6 changed files with 2,742 additions and 56 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ jobs:
- run: npm i
- run: npm run lint

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm i
- run: npm run test

build:
name: Build
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions components/StatusIcon.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect, test } from "vitest";
import { render } from "@testing-library/react";
import { StatusIcon } from "./StatusIcon";

test("Renders green dot for active status", () => {
const { container } = render(<StatusIcon status="active" />);
console.log(container.firstChild.className);
expect(container.firstChild.className.includes("green-600")).toBeTruthy();
});

test("Renders red dot for error status", () => {
const { container } = render(<StatusIcon status="error" />);
expect(container.firstChild.className.includes("red-500")).toBeTruthy();
});

test("Renders yellow dot for any other string", () => {
const { container } = render(<StatusIcon status="pending" />);
expect(container.firstChild.className.includes("yellow-500")).toBeTruthy();
});

test("Renders gray dot for empty string", () => {
const { container } = render(<StatusIcon status="" />);
expect(container.firstChild.className.includes("slate-300")).toBeTruthy();
});
2 changes: 2 additions & 0 deletions components/StatusIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const StatusIcon: FC<{ status: string; className?: string }> = ({
clr = "green-600";
} else if (status === "error") {
clr = "red-500";
} else if (status === "") {
clr = "slate-300";
}

return <span className={`text-${clr} ${className}`}></span>;
Expand Down
Loading

0 comments on commit 7aba478

Please sign in to comment.