test: add vitest for unit tests (#50)
* feat: add vitest for unit tests * chore: address pull request feedback * test: add unit test code quality workflow
This commit is contained in:
11
.github/workflows/code-quality.yml
vendored
11
.github/workflows/code-quality.yml
vendored
@@ -55,3 +55,14 @@ jobs:
|
||||
|
||||
- name: Typecheck
|
||||
run: turbo typecheck
|
||||
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup
|
||||
uses: ./tooling/github/setup
|
||||
|
||||
- name: Test
|
||||
run: pnpm test
|
||||
|
||||
11
package.json
11
package.json
@@ -4,6 +4,7 @@
|
||||
"engines": {
|
||||
"node": ">=20.11.0"
|
||||
},
|
||||
"type": "module",
|
||||
"packageManager": "pnpm@8.15.1",
|
||||
"scripts": {
|
||||
"build": "turbo build",
|
||||
@@ -17,14 +18,22 @@
|
||||
"lint": "turbo lint --continue -- --cache --cache-location node_modules/.cache/.eslintcache",
|
||||
"lint:fix": "turbo lint --continue -- --fix --cache --cache-location node_modules/.cache/.eslintcache",
|
||||
"lint:ws": "pnpm dlx sherif@latest",
|
||||
"test": "cross-env NODE_ENV=development vitest run --coverage.enabled",
|
||||
"test:ui": "cross-env NODE_ENV=development vitest --ui --coverage.enabled",
|
||||
"typecheck": "turbo typecheck"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@homarr/prettier-config": "workspace:^0.1.0",
|
||||
"@turbo/gen": "^1.12.2",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"@vitest/coverage-v8": "^1.2.2",
|
||||
"@vitest/ui": "^1.2.2",
|
||||
"cross-env": "^7.0.3",
|
||||
"prettier": "^3.2.4",
|
||||
"turbo": "^1.12.2",
|
||||
"typescript": "^5.3.3"
|
||||
"typescript": "^5.3.3",
|
||||
"vite-tsconfig-paths": "^4.3.1",
|
||||
"vitest": "^1.2.2"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
|
||||
10
packages/common/src/test/object.spec.ts
Normal file
10
packages/common/src/test/object.spec.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { objectKeys } from "../object";
|
||||
|
||||
describe("objectKeys should return all keys of an object", () => {
|
||||
it("should return all keys of an object", () => {
|
||||
const obj = { a: 1, b: 2, c: 3 };
|
||||
expect(objectKeys(obj)).toEqual(["a", "b", "c"]);
|
||||
});
|
||||
});
|
||||
19
packages/common/src/test/string.spec.ts
Normal file
19
packages/common/src/test/string.spec.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { capitalize } from "../string";
|
||||
|
||||
const capitalizeTestCases = [
|
||||
["hello", "Hello"],
|
||||
["World", "World"],
|
||||
["123", "123"],
|
||||
["a", "A"],
|
||||
["two words", "Two words"],
|
||||
] as const;
|
||||
|
||||
describe("capitalize should capitalize the first letter of a string", () => {
|
||||
capitalizeTestCases.forEach(([input, expected]) => {
|
||||
it(`should capitalize ${input} to ${expected}`, () => {
|
||||
expect(capitalize(input)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
1132
pnpm-lock.yaml
generated
1132
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
23
vitest.config.ts
Normal file
23
vitest.config.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import react from "@vitejs/plugin-react";
|
||||
import tsconfigPaths from "vite-tsconfig-paths";
|
||||
import { configDefaults, defineConfig } from "vitest/config";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react(), tsconfigPaths()],
|
||||
test: {
|
||||
include: ["**/*.spec.ts"],
|
||||
poolOptions: {
|
||||
threads: {
|
||||
singleThread: false,
|
||||
},
|
||||
},
|
||||
coverage: {
|
||||
provider: "v8",
|
||||
reporter: ["html", "json-summary", "json"],
|
||||
all: true,
|
||||
exclude: ["apps/nextjs/.next/"],
|
||||
},
|
||||
|
||||
exclude: [...configDefaults.exclude, "apps/nextjs/.next"],
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user