Skip to content
Draft
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
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Tests

on:
pull_request:

jobs:
unit-tests:
name: Unit tests
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Lint
run: bun run lint

- name: Test
run: bun run test
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint"
"lint": "eslint",
"test": "bun test"
},
"dependencies": {
"@tailwindcss/typography": "^0.5.19",
Expand Down
41 changes: 41 additions & 0 deletions src/lib/posts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, test } from "bun:test";

import { getAllPostIds, getPostData, getSortedPostsData } from "./posts";

describe("getSortedPostsData", () => {
test("reads post frontmatter sorted by newest date first", () => {
expect(getSortedPostsData()).toEqual([
{
id: "hello-world",
title: "Hello, world",
date: "2024-01-01",
description: "A short introduction.",
},
]);
});
});

describe("getAllPostIds", () => {
test("returns route params for markdown posts", () => {
expect(getAllPostIds()).toEqual([
{
params: {
slug: "hello-world",
},
},
]);
});
});

describe("getPostData", () => {
test("returns frontmatter and rendered markdown content", async () => {
await expect(getPostData("hello-world")).resolves.toMatchObject({
id: "hello-world",
title: "Hello, world",
date: "2024-01-01",
description: "A short introduction.",
contentHtml:
"<p>Welcome. This is the first entry \u2014 more soon on engineering, debate, and building Cursor.</p>\n",
});
});
});
21 changes: 21 additions & 0 deletions src/lib/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, test } from "bun:test";

import { cn, formatDate } from "./utils";

describe("cn", () => {
test("merges conditional classes", () => {
expect(cn("base", false && "hidden", ["flex", "items-center"])).toBe(
"base flex items-center",
);
});

test("resolves conflicting Tailwind classes", () => {
expect(cn("px-2 py-1", "px-4")).toBe("py-1 px-4");
});
});

describe("formatDate", () => {
test("formats dates in UTC", () => {
expect(formatDate("2024-01-01")).toBe("January 1, 2024");
});
});
Loading