Skip to content

Commit

Permalink
chore(ci): add github workflow (#7)
Browse files Browse the repository at this point in the history
* chore(ci): add github workflow

* chore(ci): make use of yarn & node 18

* chore(validathor): use fake timers in tests

* chore(validathor): stop docs from accidentally being published

* chore(ci): only build lib
  • Loading branch information
Kosai106 authored May 27, 2024
1 parent 111f2ea commit 642e222
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 13 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI

on: [push]

jobs:
unit_test-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Nodejs and npm
uses: actions/setup-node@v2
with:
node-version: "18"

- name: Setup yarn
run: npm install -g yarn

- name: Setup Nodejs with yarn caching
uses: actions/setup-node@v2
with:
node-version: "18"
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile

- run: |
yarn test
yarn lint
yarn type-check
yarn build:lib
1 change: 1 addition & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"private": true,
"name": "@nordic-ui/docs",
"version": "0.0.1",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Here's a basic example usecase
}),
acceptedTerms: boolean(),
createdAt: date([
minDate(new Date('2021/01/01')),
maxDate(new Date()),
min(new Date('2021/01/01')),
max(new Date()),
]),
});
```
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"packageManager": "yarn@1.22.19",
"scripts": {
"build": "turbo run build",
"build:lib": "turbo run build --filter=validathor",
"dev": "turbo run dev --no-cache --continue",
"test": "turbo run test",
"lint": "turbo run lint",
Expand Down
2 changes: 1 addition & 1 deletion packages/validathor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
// Schemas
object, string, number, boolean, date,
// Modifiers
min, max, minLength, maxLength, email,
min, max, email,
} from '@nordic-ui/validathor';

// Define your schema shape
Expand Down
24 changes: 15 additions & 9 deletions packages/validathor/src/schemas/__tests__/date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { ValidationError, TypeError } from '@/utils/errors/errors'
import { date } from '../date'

describe('date()', () => {
beforeEach(() => {
vi.useFakeTimers()
})

afterEach(() => {
vi.useRealTimers()
})

it('should be named correctly', () => {
expect(date().name).toEqual('date')
})
Expand All @@ -27,7 +35,7 @@ describe('date()', () => {
expect(() => parse(schema, 123)).toThrowError(new ValidationError('Not a date'))
})

it('should work with minDate() and maxDate() modifiers', () => {
it('should work with min() and max() modifiers', () => {
const schema1 = date([min(new Date('2021/01/01'))])
const schema2 = date([max(new Date('2021/12/31'))])
const schema3 = date([min(new Date('2021/01/01')), max(new Date('2021/12/31'))])
Expand All @@ -39,13 +47,13 @@ describe('date()', () => {
expect(parse(schema3, new Date('2021/06/15'))).toEqual(new Date('2021/06/15'))

expect(() => parse(schema1, new Date('2020/12/31'))).toThrowError(
new ValidationError('Value must be at least 2020-12-31T23:00:00.000Z'),
new ValidationError('Value must be at least 2021-01-01T00:00:00.000Z'),
)
expect(() => parse(schema2, new Date('2022/01/01'))).toThrowError(
new ValidationError('Value must be at most 2021-12-30T23:00:00.000Z'),
new ValidationError('Value must be at most 2021-12-31T00:00:00.000Z'),
)
expect(() => parse(schema3, new Date('2022/01/01'))).toThrowError(
new ValidationError('Value must be at most 2021-12-30T23:00:00.000Z'),
new ValidationError('Value must be at most 2021-12-31T00:00:00.000Z'),
)
expect(() => parse(schema4, new Date('2020/12/31'))).toThrowError(
new ValidationError('Date is too early'),
Expand All @@ -57,13 +65,11 @@ describe('date()', () => {

it('should work with custom() modifier', () => {
const schema1 = date([
custom((value) => [[value.getUTCDate() === 31, new TypeError('End of the month (maybe)')]]),
custom((value) => [[value.getDate() !== 31, 'End of the month (maybe)']]),
])

expect(() => parse(schema1, new Date('2023/06/01'))).not.toThrowError(
new ValidationError('End of the month (maybe)'),
)
expect(() => parse(schema1, new Date('2023/06/31'))).toThrowError(
expect(parse(schema1, new Date('2024/05/12'))).toEqual(new Date('2024/05/12'))
expect(() => parse(schema1, new Date('2024/05/31'))).toThrowError(
new ValidationError('End of the month (maybe)'),
)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/validathor/src/schemas/__tests__/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('string()', () => {
)
})

it('should work with minLength() and maxLength() modifiers', () => {
it('should work with min() and max() modifiers', () => {
const schema1 = string([min(2)])
const schema2 = string([max(6)])
const schema3 = string([min(2), max(6)])
Expand Down
3 changes: 3 additions & 0 deletions packages/validathor/test/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const setup = () => {
process.env.TZ = 'UTC'
}
1 change: 1 addition & 0 deletions packages/validathor/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default defineConfig({
coverage: {
reporter: ['text', 'json', 'html'],
},
globalSetup: './test/global-setup.ts',
},
})

0 comments on commit 642e222

Please sign in to comment.