Skip to content

Commit 2bc131d

Browse files
authored
Merge pull request #17 from crashmax-dev/add-tests
chore: add tests
2 parents b952118 + c028cde commit 2bc131d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1130
-255
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

examples/with-fastify/src/api/users/users.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function userController(
3434
{ schema: userBodySchema },
3535
async (request, reply) => {
3636
const { username, age } = request.body
37-
const newUser = service.addUser(username, age)
37+
const newUser = await service.addUser(username, age)
3838
if (!newUser) return reply.status(400).send('Username exist')
3939
return newUser
4040
}

examples/with-fastify/src/api/users/users.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { User, Users } from '../../dto/users.dto.js'
2-
import type { Steno } from '@stenodb/fastify'
2+
import type { AsyncProvider } from '@stenodb/fastify'
33
import type { FastifyInstance } from 'fastify'
44

55
export class UserService {
6-
#users: Steno.NodeProvider<Users>
6+
#users: AsyncProvider<Users>
77

88
constructor(private readonly fastify: FastifyInstance) {
99
this.#users = this.fastify.steno.get<Users>('users')!

examples/with-fastify/src/dto/users.dto.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Exclude, Type } from 'class-transformer'
2-
import { IsNumber, IsString, Length } from 'class-validator'
2+
import { IsNumber, IsOptional, IsString, Length } from 'class-validator'
33
import { Post } from './posts.dto.js'
44

55
export class Users {
@@ -13,6 +13,7 @@ export class Users {
1313

1414
export class User {
1515
@Exclude({ toPlainOnly: true })
16+
@IsOptional()
1617
@IsNumber()
1718
userId: number
1819

examples/with-fastify/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ const usersInitialData = new Users(
1616
new User(2, 'alice', 23)
1717
)
1818

19-
const usersAdapter = new AsyncAdapter(
20-
'users',
21-
Users,
22-
usersInitialData
23-
)
19+
const usersAdapter = new AsyncAdapter('users', Users, usersInitialData)
2420

2521
fastify.register(FastifySteno, {
2622
path: resolve(dirname(fileURLToPath(import.meta.url)), '..', 'db'),

examples/with-nest/src/app.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Injectable, OnModuleInit } from '@nestjs/common'
2-
import { Steno, StenoService } from '@stenodb/nest'
2+
import { AsyncProvider, StenoService } from '@stenodb/nest'
33
import { CreateUserDto, initialUsersData, Users } from './dto/users.dto'
44

55
@Injectable()
66
export class UsersService implements OnModuleInit {
7-
private usersProvider: Steno.NodeProvider<Users>
7+
private usersProvider: AsyncProvider<Users>
88

99
constructor(private readonly stenoService: StenoService) {}
1010

examples/with-nest/src/dto/users.dto.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { Exclude, Type } from 'class-transformer'
2-
import { IsNumber, IsString, Length, Max, Min } from 'class-validator'
2+
import {
3+
IsNumber,
4+
IsOptional,
5+
IsString,
6+
Length,
7+
Max,
8+
Min
9+
} from 'class-validator'
310

411
export class Users {
512
@Type(() => CreateUserDto)
@@ -11,8 +18,9 @@ export class Users {
1118
}
1219

1320
export class CreateUserDto {
14-
@IsNumber()
1521
@Exclude({ toPlainOnly: true })
22+
@IsOptional()
23+
@IsNumber()
1624
id: number
1725

1826
@IsString()

examples/with-node/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "@crashmax/tsconfig",
33
"compilerOptions": {
4+
"moduleResolution": "NodeNext",
45
"experimentalDecorators": true,
56
"emitDecoratorMetadata": true,
67
"outDir": "dist"

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
"dev:examples": "turbo run dev --filter=./examples/*",
1313
"build": "turbo run build --filter=./packages/*",
1414
"build:examples": "turbo run build --filter=./examples/*",
15+
"test": "turbo run test",
1516
"format": "prettier --write --ignore-unknown **"
1617
},
1718
"devDependencies": {
1819
"@crashmax/prettier-config": "3.0.1",
1920
"@crashmax/tsconfig": "1.0.2",
21+
"ava": "5.2.0",
2022
"cross-env": "7.0.3",
2123
"nodemon": "2.0.20",
2224
"ts-node": "10.9.1",

packages/browser/package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"name": "@stenodb/browser",
33
"description": "✍ Easy to use local JSON database",
4+
"type": "module",
45
"version": "3.4.1",
56
"exports": {
67
".": {
78
"types": "./dist/index.d.ts",
89
"require": "./dist/index.js",
9-
"default": "./dist/index.mjs"
10+
"default": "./dist/index.js"
1011
}
1112
},
1213
"types": "./dist/index.d.ts",
1314
"main": "./dist/index.js",
14-
"module": "./dist/index.mjs",
15+
"module": "./dist/index.js",
1516
"files": [
1617
"dist",
1718
"src"
@@ -52,6 +53,16 @@
5253
"peerDependencies": {
5354
"@stenodb/logger": "workspace:3.4.1"
5455
},
56+
"ava": {
57+
"snapshotDir": "test/snapshots",
58+
"extensions": {
59+
"ts": "module"
60+
},
61+
"nodeArguments": [
62+
"--loader=ts-node/esm",
63+
"--no-warnings"
64+
]
65+
},
5566
"engines": {
5667
"node": ">=14.16"
5768
}

0 commit comments

Comments
 (0)