feat: add unit tests
This commit is contained in:
parent
9e58978b4d
commit
7cbb07fd67
7 changed files with 1734 additions and 11 deletions
5
.github/workflows/deploy.yml
vendored
5
.github/workflows/deploy.yml
vendored
|
@ -48,7 +48,10 @@ jobs:
|
||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run unit tests
|
||||||
|
run: pnpm test:unit
|
||||||
|
|
||||||
|
- name: Run E2E tests
|
||||||
run: pnpm test:e2e
|
run: pnpm test:e2e
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v3
|
||||||
|
|
7
apps/main/jest.config.js
Normal file
7
apps/main/jest.config.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||||
|
export default {
|
||||||
|
verbose: true,
|
||||||
|
preset: "ts-jest",
|
||||||
|
testEnvironment: "node",
|
||||||
|
testPathIgnorePatterns: ["e2e"], // ignore playwright tests
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "pnpm cp && vite build",
|
"build": "pnpm cp && vite build",
|
||||||
"serve": "serve build --listen 5173",
|
"serve": "serve build --listen 5173",
|
||||||
|
"test:unit": "jest",
|
||||||
"test:e2e": "playwright test",
|
"test:e2e": "playwright test",
|
||||||
"clean": "rm -rf .turbo .svelte-kit build node_modules vite.config.ts.timestamp-*",
|
"clean": "rm -rf .turbo .svelte-kit build node_modules vite.config.ts.timestamp-*",
|
||||||
"lint": "eslint ."
|
"lint": "eslint ."
|
||||||
|
@ -23,6 +24,7 @@
|
||||||
"@playwright/test": "^1.36.2",
|
"@playwright/test": "^1.36.2",
|
||||||
"@sveltejs/adapter-static": "^2.0.2",
|
"@sveltejs/adapter-static": "^2.0.2",
|
||||||
"@sveltejs/kit": "^1.22.1",
|
"@sveltejs/kit": "^1.22.1",
|
||||||
|
"@types/jest": "^29.5.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.61.0",
|
"@typescript-eslint/eslint-plugin": "^5.61.0",
|
||||||
"@typescript-eslint/parser": "^5.61.0",
|
"@typescript-eslint/parser": "^5.61.0",
|
||||||
"autoprefixer": "^10.4.14",
|
"autoprefixer": "^10.4.14",
|
||||||
|
@ -31,6 +33,7 @@
|
||||||
"eslint-plugin-import": "^2.27.5",
|
"eslint-plugin-import": "^2.27.5",
|
||||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||||
"eslint-plugin-svelte": "^2.32.2",
|
"eslint-plugin-svelte": "^2.32.2",
|
||||||
|
"jest": "^29.6.2",
|
||||||
"postcss": "^8.4.25",
|
"postcss": "^8.4.25",
|
||||||
"prettier-plugin-svelte": "^2.10.1",
|
"prettier-plugin-svelte": "^2.10.1",
|
||||||
"prettier-plugin-tailwindcss": "^0.3.0",
|
"prettier-plugin-tailwindcss": "^0.3.0",
|
||||||
|
@ -39,6 +42,7 @@
|
||||||
"svelte": "^4.0.5",
|
"svelte": "^4.0.5",
|
||||||
"svelte-check": "^3.4.5",
|
"svelte-check": "^3.4.5",
|
||||||
"tailwindcss": "^3.3.2",
|
"tailwindcss": "^3.3.2",
|
||||||
|
"ts-jest": "^29.1.1",
|
||||||
"tslib": "^2.6.0",
|
"tslib": "^2.6.0",
|
||||||
"typescript": "^5.1.6",
|
"typescript": "^5.1.6",
|
||||||
"vite": "^4.4.2"
|
"vite": "^4.4.2"
|
||||||
|
|
85
apps/main/src/utils/getAge.test.ts
Normal file
85
apps/main/src/utils/getAge.test.ts
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
import { testing } from "./getAge"
|
||||||
|
|
||||||
|
const { birth, dateFormatOption, getAge, ageInt, ageDecimal, isOverBirthDay } =
|
||||||
|
testing
|
||||||
|
|
||||||
|
describe("getAge tests", () => {
|
||||||
|
test("birthday should be 2002-07-30", () => {
|
||||||
|
expect(birth).toEqual(new Date("2002-07-30, 00:00:00.000 +09:00"))
|
||||||
|
})
|
||||||
|
|
||||||
|
test("isOverBirthDay to work", () => {
|
||||||
|
expect(
|
||||||
|
isOverBirthDay(new Date("2022-12-31, 00:00:00.000 +09:00"))
|
||||||
|
).toEqual(true)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isOverBirthDay(new Date("2023-01-01, 00:00:00.000 +09:00"))
|
||||||
|
).toEqual(false)
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isOverBirthDay(new Date("2023-07-29, 00:00:00.000 +09:00"))
|
||||||
|
).toEqual(false)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isOverBirthDay(new Date("2023-07-30, 00:00:00.000 +09:00"))
|
||||||
|
).toEqual(true)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isOverBirthDay(new Date("2023-07-31, 00:00:00.000 +09:00"))
|
||||||
|
).toEqual(true)
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isOverBirthDay(new Date("2023-12-31, 00:00:00.000 +09:00"))
|
||||||
|
).toEqual(true)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isOverBirthDay(new Date("2024-01-01, 00:00:00.000 +09:00"))
|
||||||
|
).toEqual(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("dateFormatOption should work properly", () => {
|
||||||
|
expect(
|
||||||
|
new Date("2002-07-30, 00:00:00.000 +09:00").toLocaleString(
|
||||||
|
"en-US",
|
||||||
|
dateFormatOption
|
||||||
|
)
|
||||||
|
).toEqual("7/30/2002, 00:00:00.000 GMT+09:00")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("ageInt to work", () => {
|
||||||
|
expect(ageInt(birth)).toEqual(0)
|
||||||
|
expect(ageInt(new Date("2023-07-29"))).toEqual(20)
|
||||||
|
expect(ageInt(new Date("2023-07-30"))).toEqual(21)
|
||||||
|
expect(ageInt(new Date("2023-07-31"))).toEqual(21)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("ageDecimal to work", () => {
|
||||||
|
expect(ageDecimal(new Date("2023-07-29, 00:00:00.000 +09:00"))).toEqual(
|
||||||
|
0.9972602739726028
|
||||||
|
)
|
||||||
|
expect(ageDecimal(new Date("2023-07-30, 00:00:00.000 +09:00"))).toEqual(
|
||||||
|
0
|
||||||
|
)
|
||||||
|
expect(ageDecimal(new Date("2023-07-31, 00:00:00.000 +09:00"))).toEqual(
|
||||||
|
0.00273224043715847
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("getAge to work", () => {
|
||||||
|
expect(getAge(new Date("2002-07-30, 00:00:00.000 +09:00"))).toEqual(0.0)
|
||||||
|
expect(getAge(new Date("2023-07-29, 00:00:00.000 +09:00"))).toEqual(
|
||||||
|
20.997260273972604
|
||||||
|
)
|
||||||
|
expect(getAge(new Date("2023-07-30, 00:00:00.000 +09:00"))).toEqual(
|
||||||
|
21.0
|
||||||
|
)
|
||||||
|
expect(getAge(new Date("2023-07-31, 00:00:00.000 +09:00"))).toEqual(
|
||||||
|
21.002732240437158
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
|
@ -5,6 +5,7 @@
|
||||||
"dev": "turbo run dev --parallel --continue",
|
"dev": "turbo run dev --parallel --continue",
|
||||||
"build": "turbo run build",
|
"build": "turbo run build",
|
||||||
"serve": "turbo run serve",
|
"serve": "turbo run serve",
|
||||||
|
"test:unit": "turbo run test:unit --parallel --continue",
|
||||||
"test:e2e": "turbo run test:e2e --parallel --continue",
|
"test:e2e": "turbo run test:e2e --parallel --continue",
|
||||||
"lint": "turbo run lint",
|
"lint": "turbo run lint",
|
||||||
"clean": "turbo run clean && rm -rf node_modules"
|
"clean": "turbo run clean && rm -rf node_modules"
|
||||||
|
|
1640
pnpm-lock.yaml
generated
1640
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
@ -11,6 +11,9 @@
|
||||||
"serve": {
|
"serve": {
|
||||||
"cache": false
|
"cache": false
|
||||||
},
|
},
|
||||||
|
"test:unit": {
|
||||||
|
"cache": false
|
||||||
|
},
|
||||||
"test:e2e": {
|
"test:e2e": {
|
||||||
"cache": false
|
"cache": false
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue