Skip to content

Commit

Permalink
ci: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brokeyourbike committed Sep 20, 2024
1 parent 90ff878 commit 0f65167
Show file tree
Hide file tree
Showing 16 changed files with 204 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ jobs:
- run: pnpm install
- run: pnpm run build
- run: pnpm run typecheck

unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 20
check-latest: true
cache: 'pnpm'
- run: pnpm install
- run: pnpm run test:unit
1 change: 0 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
check-latest: true
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build

- uses: paambaati/codeclimate-action@v5
continue-on-error: true
Expand Down
27 changes: 27 additions & 0 deletions packages/time/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest'
import {
getMonthOptions,
getYearOptions,
parseAndFormatDate,
parseAndFormatTime,
formatDateOnly,
} from '../index'

describe('time', () => {
it('can generate month options', () => {
expect(getMonthOptions()).toHaveLength(12)
})
it('can generate year options', () => {
const currentYear = new Date().getFullYear()
expect(getYearOptions(currentYear)).toHaveLength(1)
})
it('can parse date', () => {
expect(parseAndFormatDate('2024-09-20T11:16:49.96+01:00')).toEqual('20/09/2024 11:16:49')
})
it('can parse time', () => {
expect(parseAndFormatTime('2024-09-20T11:16:49.96+01:00')).toEqual('11:16')
})
it('can format date only', () => {
expect(formatDateOnly(new Date('2024-09-20T11:16:49.96+01:00'))).toEqual('2024-09-20')
})
})
11 changes: 6 additions & 5 deletions packages/use-form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@
},
"license": "MIT",
"peerDependencies": {
"next": ">=14.0",
"react": ">=18.0",
"axios": ">=1.7",
"js-cookie": ">=3.0",
"swr": ">=2.0",
"lodash.isequal": ">=4.0",
"react-hot-toast": ">=2.0"
"next": ">=14.0",
"react": ">=18.0",
"react-hot-toast": ">=2.0",
"swr": ">=2.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
"@types/js-cookie": "^3.0.6",
"@types/lodash.isequal": "^4.5.8"
"@types/lodash.isequal": "^4.5.8",
"next-router-mock": "^0.9.13"
}
}
12 changes: 12 additions & 0 deletions packages/use-form/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { renderHook } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import {useForm} from '..'

vi.mock('next/router', () => require('next-router-mock'));

describe('useForm', () => {
it('useForm should not be undefined', () => {
const { result } = renderHook(() => useForm())
expect(result.current).not.toBeUndefined()
})
})
10 changes: 10 additions & 0 deletions packages/use-get/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { renderHook } from '@testing-library/react'
import { describe, expect, it } from 'vitest'
import {useGet} from '..'

describe('useGet', () => {
it('useGet isLoading should be true', () => {
const { result } = renderHook(() => useGet('https://jsonplaceholder.typicode.com/todos/1'))
expect(result.current.isLoading).toBeTruthy()
})
})
4 changes: 4 additions & 0 deletions packages/uuid/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
coverage/
node_modules
.reports/
3 changes: 3 additions & 0 deletions packages/uuid/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/__tests__/**
src
!.npmignore
23 changes: 23 additions & 0 deletions packages/uuid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# `@glocurrency/uuid`

UUID Helpers

---

## Install

```bash
$ pnpm add @glocurrency/uuid
```

## Usage

```js
import { first8 } from '@glocurrency/uuid'

first8('c4e4b3e4-4b3e-4c4e-b3e4-c4e4b3e4b3e4') // c4e4b3e4
```

## Authors

- [Ivan Stasiuk](https://github.com/brokeyourbike) | [Twitter](https://twitter.com/brokeyourbike) | [LinkedIn](https://www.linkedin.com/in/brokeyourbike) | [stasi.uk](https://stasi.uk)
38 changes: 38 additions & 0 deletions packages/uuid/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@glocurrency/uuid",
"description": "UUID Helpers",
"version": "0.0.3",
"type": "module",
"engines": {
"node": ">=20.x"
},
"main": "./dist/index.cjs",
"sideEffects": false,
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
}
},
"publishConfig": {
"access": "public"
},
"scripts": {
"prebuild": "shx rm -rf dist",
"typecheck": "tsc --noEmit",
"type:generate": "tsc --declaration -p tsconfig.build.json",
"build": "vite build --config vite.config.ts && pnpm run type:generate",
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
"test:unit": "vitest --run --config vite.config.ts",
"test:unit:coverage": "pnpm test:unit --coverage"
},
"repository": {
"type": "git",
"url": "https://github.com/glocurrency/commons.ts",
"directory": "packages/uuid"
},
"license": "MIT"
}
17 changes: 17 additions & 0 deletions packages/uuid/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest'
import {
first8,
slim,
} from '../index'

describe('uuid', () => {
it('can get first 8 chars', () => {
expect(first8('a322523d-2a01-407f-8d28-4fbcbc011370')).toBe('a322523d')
})
it('can work with empty string', () => {
expect(first8('')).toBe('')
})
it('can slim uuid', () => {
expect(slim('a322523d-2a01-407f-8d28-4fbcbc011370')).toBe('a322523d2a01407f8d284fbcbc011370')
})
})
7 changes: 7 additions & 0 deletions packages/uuid/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const first8 = (value: string): string => {
return value.slice(0, 8)
}

export const slim = (value: string): string => {
return value.replace(/-/g, '');
}
16 changes: 16 additions & 0 deletions packages/uuid/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"emitDeclarationOnly": true,
"rootDir": "src",
"outDir": "dist"
},
"exclude": [
"*.config.ts",
"*.setup.ts",
"**/__tests__",
"**/__mocks__",
"src/**/*.test.tsx"
]
}
4 changes: 4 additions & 0 deletions packages/uuid/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*.ts", "src/**/*.tsx", "*.config.ts"]
}
8 changes: 8 additions & 0 deletions packages/uuid/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig, mergeConfig } from 'vite'
import { defaultConfig } from '../../vite.config'

export default mergeConfig(defineConfig(defaultConfig), {
build: {
target: ['node20'],
},
})
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 0f65167

Please sign in to comment.