Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Jan 9, 2025
1 parent 0721af9 commit 6c67f9a
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "turbo run dev",
"lint": "turbo run --continue lint",
"format": "turbo run --continue format",
"test": "turbo run --continue test",
"storybook:dev": "turbo run --filter=@app/storybook dev",
"web:dev": "turbo run --filter=@app/web dev"
},
Expand Down
8 changes: 6 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
"main": "src/index.ts",
"scripts": {
"lint": "eslint .",
"format": "eslint . --fix"
"format": "eslint . --fix",
"test": "vitest run",
"test:cov": "vitest run --coverage"
},
"devDependencies": {
"typescript": "^5.7.3"
"@vitest/coverage-v8": "^2.1.8",
"typescript": "^5.7.3",
"vitest": "^2.1.8"
},
"dependencies": {
"clsx": "^2.1.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/utils/src/name.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from 'vitest'

import { getShortenName } from './name.js'

test('getShortenName', () => {
expect(getShortenName('John Doe')).toBe('John D.')
expect(getShortenName('John Doe Jr.')).toBe('John J.')
})
6 changes: 6 additions & 0 deletions packages/utils/src/name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function getShortenName(fullName: string) {
const names = fullName.split(' ')
const firstName = names[0]
const lastName = names[names.length - 1]
return `${firstName} ${lastName.charAt(0)}.`
}
9 changes: 9 additions & 0 deletions packages/utils/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
coverage: {
provider: 'v8',
},
},
})
137 changes: 137 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
"dev": {
"cache": false,
"persistent": true
},
"test": {
"cache": false
},
"test:cov": {
"cache": false
}
}
}

0 comments on commit 6c67f9a

Please sign in to comment.