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

Setup test CI #109

Merged
merged 5 commits into from
Jul 26, 2024
Merged
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
30 changes: 30 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: PR
on: pull_request

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-

- name: Install pnpm
uses: pnpm/action-setup@v4

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- run: pnpm i
- run: pnpm exec turbo run test
17 changes: 17 additions & 0 deletions packages/frontpage/lib/components/time-ago.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { afterEach, beforeEach, expect, test, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import { TimeAgo } from "./time-ago";

beforeEach(() => {
vi.useFakeTimers();
});

afterEach(() => {
vi.useRealTimers();
});

test("correct relative time", () => {
vi.setSystemTime(new Date("2024-01-02"));
render(<TimeAgo createdAt={new Date("2024-01-01")} />);
expect(screen.getByText("1 day ago")).toBeDefined();
});
10 changes: 8 additions & 2 deletions packages/frontpage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "next start",
"lint": "eslint .",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate"
"db:migrate": "drizzle-kit migrate",
"test": "vitest"
},
"dependencies": {
"@next/env": "^14.2.4",
Expand Down Expand Up @@ -45,15 +46,20 @@
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@testing-library/react": "^16.0.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@vitejs/plugin-react": "^4.3.1",
"babel-plugin-react-compiler": "0.0.0-experimental-938cd9a-20240601",
"drizzle-kit": "^0.22.7",
"eslint": "^8",
"eslint-config-next": "15.0.0-rc.0",
"jsdom": "^24.1.1",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
"typescript": "^5",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.0.4"
}
}
10 changes: 10 additions & 0 deletions packages/frontpage/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
plugins: [react(), tsconfigPaths()],
test: {
environment: "jsdom",
},
});
Loading