Skip to content

Commit

Permalink
Merge pull request #3 from abikart/main
Browse files Browse the repository at this point in the history
feat(tests): setup
  • Loading branch information
abikart authored Dec 27, 2024
2 parents bc6ffcb + 99beb20 commit d47dc19
Show file tree
Hide file tree
Showing 14 changed files with 2,270 additions and 17 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: PR Checks

on:
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.18.0'

- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: '9.12.1'

- name: Install Dependencies
run: pnpm install

- name: Build Common Package
run: pnpm common build

- name: Test Common Package
run: pnpm common test

- name: Test Frontend
run: pnpm frontend test

- name: Upload Coverage Reports
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: |
apps/frontend/coverage/
packages/common/coverage/
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.18.0'

- name: Setup PNPM
uses: pnpm/action-setup@v3
with:
version: '9.12.1'

- name: Install Dependencies
run: pnpm install

- name: Run Biome Check
run: pnpm check
13 changes: 11 additions & 2 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,29 @@
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview",
"deploy": "GITHUB_PAGES=true vite build"
"deploy": "GITHUB_PAGES=true vite build",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
},
"dependencies": {
"@testing-library/jest-dom": "^6.6.3",
"common": "workspace:*",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@testing-library/react": "^16.1.0",
"@testing-library/user-event": "^14.5.2",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react-swc": "^3.7.2",
"@vitest/coverage-v8": "^2.1.8",
"globals": "^15.14.0",
"jsdom": "^25.0.1",
"typescript": "~5.7.2",
"typescript-eslint": "^8.18.2",
"vite": "^6.0.6"
"vite": "^6.0.6",
"vitest": "^2.1.8"
}
}
1 change: 0 additions & 1 deletion apps/frontend/src/App.css
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

10 changes: 10 additions & 0 deletions apps/frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import App from "./App";

describe("App", () => {
it("renders hello world", () => {
render(<App />);
expect(screen.getByText(/hello world/i)).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion apps/frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBlank, hello } from "common";
import { hello, isBlank } from "common";

const App = () => {
return (
Expand Down
7 changes: 7 additions & 0 deletions apps/frontend/src/test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "@testing-library/jest-dom";
import { cleanup } from "@testing-library/react";
import { afterEach } from "vitest";

afterEach(() => {
cleanup();
});
12 changes: 11 additions & 1 deletion apps/frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
base: process.env.GITHUB_PAGES // Set base URL for GitHub Pages
? "/starter/" // Replace with your actual repository name
: "/",
test: {
globals: true,
environment: "jsdom",
setupFiles: ["./src/test/setup.ts"],
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
exclude: ["node_modules/", "src/test/setup.ts"],
},
},
});
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"files": {
"ignoreUnknown": false,
"ignore": ["dist", "node_modules", "*.local"]
"ignore": ["dist", "node_modules", "*.local", "**/*.json"]
},
"formatter": {
"enabled": true,
Expand Down
2 changes: 1 addition & 1 deletion commitlint.config.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default { extends: ['@commitlint/config-conventional'] };
export default { extends: ["@commitlint/config-conventional"] };
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"check": "biome check",
"test": "pnpm -r test",
"test:watch": "pnpm -r test:watch",
"test:coverage": "pnpm -r test:coverage",
"check": "biome check --write",
"prepare": "husky",
"common": "pnpm --filter common",
"frontend": "pnpm --filter frontend",
Expand Down
9 changes: 7 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"watch": "pnpm build --watch"
"watch": "pnpm build --watch",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
},
"devDependencies": {
"typescript": "~5.7.2",
"vite": "^6.0.6",
"vite-plugin-dts": "^4.4.0"
"vite-plugin-dts": "^4.4.0",
"@vitest/coverage-v8": "^1.3.1",
"vitest": "^1.3.1"
}
}
8 changes: 8 additions & 0 deletions packages/common/src/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, expect, it } from "vitest";
import { hello } from "./main";

describe("hello", () => {
it("returns hello", () => {
expect(hello()).toBe("Hello World");
});
});
18 changes: 14 additions & 4 deletions packages/common/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { defineConfig } from "vite";
import { resolve } from "node:path";
import dts from "vite-plugin-dts";

// https://vitejs.dev/config/
export default defineConfig({
build: { lib: { entry: resolve(__dirname, "src/main.ts"), formats: ["es"] } },
resolve: { alias: { src: resolve("src/") } },
plugins: [dts()],
build: {
lib: {
entry: "src/main.ts",
formats: ["es"],
fileName: "common",
},
},
test: {
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
exclude: ["node_modules/"],
},
},
});
Loading

0 comments on commit d47dc19

Please sign in to comment.