feat(tests): add basic arithmetic functions and corresponding tests

- Implemented `add` and `subtract` functions in multiple packages (web, ui, utils).
- Created unit tests for these functions using Vitest in respective test files.
- Updated turbo.json to include a new test pipeline for coverage and watch mode.
This commit is contained in:
Firman Ramdhani
2026-01-14 18:35:20 +07:00
parent a994be1cd2
commit 914c267e66
18 changed files with 862 additions and 21 deletions
-5
View File
@@ -1,5 +0,0 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ["@repo/eslint-config/index.js"],
};
+1 -1
View File
@@ -24,7 +24,7 @@
"@storybook/react": "^8.2.6", "@storybook/react": "^8.2.6",
"@storybook/react-vite": "^8.2.6", "@storybook/react-vite": "^8.2.6",
"@vitejs/plugin-react": "^5.1.2", "@vitejs/plugin-react": "^5.1.2",
"eslint": "^8.57.1", "eslint": "^8.57.0",
"serve": "^14.2.1", "serve": "^14.2.1",
"storybook": "^8.2.6", "storybook": "^8.2.6",
"typescript": "5.5.4", "typescript": "5.5.4",
+5 -2
View File
@@ -7,7 +7,9 @@
"dev": "vite --clearScreen false", "dev": "vite --clearScreen false",
"build": "tsc && vite build", "build": "tsc && vite build",
"preview": "vite preview", "preview": "vite preview",
"lint": "eslint \"src/**/*.ts\"" "lint": "eslint \"src/**/*.ts\"",
"test": "vitest run",
"test:watch": "vitest --watch"
}, },
"dependencies": { "dependencies": {
"@repo/ui": "workspace:*", "@repo/ui": "workspace:*",
@@ -26,6 +28,7 @@
"@vitejs/plugin-react": "^5.1.2", "@vitejs/plugin-react": "^5.1.2",
"eslint": "^8.57.1", "eslint": "^8.57.1",
"typescript": "5.5.4", "typescript": "5.5.4",
"vite": "^5.1.4" "vite": "^5.1.4",
"vitest": "^4.0.17"
} }
} }
@@ -0,0 +1 @@
export const add = (a: number, b: number) => a + b;
@@ -0,0 +1,11 @@
import { expect, test } from 'vitest';
import { add } from './add';
import { subtract } from './subtract';
test('adds 1 + 2 to equal 3', () => {
expect(add(1, 2)).toBe(3);
});
test('subtracts 2 - 1 to equal 1', () => {
expect(subtract(2, 1)).toBe(1);
});
@@ -0,0 +1 @@
export const subtract = (a: number, b: number) => a - b;
+2 -2
View File
@@ -8,10 +8,10 @@
"dev:web": "turbo run dev --filter=web", "dev:web": "turbo run dev --filter=web",
"dev:docs-dev": "turbo run dev --filter=docs-dev", "dev:docs-dev": "turbo run dev --filter=docs-dev",
"lint": "turbo run lint", "lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"" "format": "prettier --write \"**/*.{ts,tsx,md}\"",
"test": "turbo run test"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^8.57.0",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"turbo": "^2.7.2" "turbo": "^2.7.2"
}, },
+1
View File
@@ -3,6 +3,7 @@
"version": "0.0.0", "version": "0.0.0",
"license": "MIT", "license": "MIT",
"files": [ "files": [
"index.js",
"library.js", "library.js",
"react.js", "react.js",
"storybook.js" "storybook.js"
+6 -3
View File
@@ -7,11 +7,13 @@
}, },
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"lint": "eslint \"**/*.ts\"" "lint": "eslint \"**/*.ts\"",
"test": "vitest run",
"test:watch": "vitest --watch"
}, },
"dependencies": { "dependencies": {
"@tailwindcss/vite": "^4.1.18",
"@repo/utils": "workspace:*", "@repo/utils": "workspace:*",
"@tailwindcss/vite": "^4.1.18",
"react": "^19.2.3", "react": "^19.2.3",
"react-dom": "^19.2.3", "react-dom": "^19.2.3",
"tailwind-merge": "^3.4.0", "tailwind-merge": "^3.4.0",
@@ -26,6 +28,7 @@
"@vitejs/plugin-react": "^5.1.2", "@vitejs/plugin-react": "^5.1.2",
"eslint": "^8.57.1", "eslint": "^8.57.1",
"typescript": "5.5.4", "typescript": "5.5.4",
"vite": "^5.1.4" "vite": "^5.1.4",
"vitest": "^4.0.17"
} }
} }
@@ -0,0 +1 @@
export const add = (a: number, b: number) => a + b;
@@ -0,0 +1 @@
export const subtract = (a: number, b: number) => a - b;
@@ -0,0 +1,11 @@
import { expect, test } from 'vitest';
import { add } from './add';
import { subtract } from './subtract';
test('adds 1 + 2 to equal 3', () => {
expect(add(1, 2)).toBe(3);
});
test('subtracts 2 - 1 to equal 1', () => {
expect(subtract(2, 1)).toBe(1);
});
+5 -2
View File
@@ -6,7 +6,9 @@
}, },
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"lint": "eslint \"**/*.ts\"" "lint": "eslint \"**/*.ts\"",
"test": "vitest run",
"test:watch": "vitest --watch"
}, },
"dependencies": { "dependencies": {
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
@@ -17,6 +19,7 @@
"@repo/typescript-config": "workspace:*", "@repo/typescript-config": "workspace:*",
"@types/crypto-js": "^4.2.2", "@types/crypto-js": "^4.2.2",
"eslint": "^8.57.1", "eslint": "^8.57.1",
"typescript": "5.5.4" "typescript": "5.5.4",
"vitest": "^4.0.17"
} }
} }
@@ -0,0 +1 @@
export const add = (a: number, b: number) => a + b;
@@ -0,0 +1 @@
export const subtract = (a: number, b: number) => a - b;
@@ -0,0 +1,11 @@
import { expect, test } from 'vitest';
import { add } from './add';
import { subtract } from './subtract';
test('adds 1 + 2 to equal 3', () => {
expect(add(1, 2)).toBe(3);
});
test('subtracts 2 - 1 to equal 1', () => {
expect(subtract(2, 1)).toBe(1);
});
+787 -6
View File
File diff suppressed because it is too large Load Diff
+16
View File
@@ -29,6 +29,22 @@
"dev": { "dev": {
"cache": false, "cache": false,
"persistent": true "persistent": true
},
"test": {
"dependsOn": [
"^test"
],
"inputs": [
"$TURBO_DEFAULT$"
],
"outputs": [
"coverage/**",
".vitest/**"
]
},
"test:watch": {
"cache": false,
"persistent": true
} }
} }
} }