Skip to content

Commit afd2bd7

Browse files
authored
refactor: move from tsd to tstyche (#203)
* chore: install tstyche * chore: move test/index.test-d.ts to test/index.tst.ts and convert it to tstyche * chore: remove tsd * chore: enable test descriptions
1 parent 7fa8f58 commit afd2bd7

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"pretest": "npm run clean",
1616
"test": "npm run lint && npm run unit && npm run typescript && ts-node test/types/index.ts",
1717
"posttest": "npm run clean",
18-
"typescript": "tsd",
18+
"typescript": "tstyche",
1919
"prepare": "husky",
2020
"clean": "rm -f orama_test* && rm -f *.msp",
2121
"preunit": "npm run clean",
@@ -51,14 +51,11 @@
5151
"snazzy": "^9.0.0",
5252
"standard": "^17.1.2",
5353
"ts-node": "^10.9.2",
54-
"tsd": "^0.32.0",
54+
"tstyche": "^4.0.2",
5555
"typescript": "^5.8.3"
5656
},
5757
"publishConfig": {
5858
"access": "public"
5959
},
60-
"tsd": {
61-
"directory": "test/types"
62-
},
6360
"packageManager": "pnpm@10.8.1+sha512.c50088ba998c67b8ca8c99df8a5e02fd2ae2e2b29aaf238feaa9e124248d3f48f9fb6db2424949ff901cffbb5e0f0cc1ad6aedb602cd29450751d11c35023677"
6461
}

test/types/index.test-d.ts renamed to test/types/index.tst.ts

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expectType } from 'tsd'
1+
import { expect, test } from 'tstyche'
22

33
import { InternalTypedDocument, Orama, PartialSchemaDeep, Results, Schema, SearchParams, TypedDocument } from '@orama/orama'
44
import Fastify from 'fastify'
@@ -43,35 +43,45 @@ app.register(fastifyOrama, {
4343
})
4444

4545
const appWithOrama = app.withOrama<typeof mySchema>()
46-
appWithOrama.orama.insert({ quote: 'Hello', author: 'World' }).then(id => {
47-
expectType<string>(id)
46+
47+
test('should enable the insertion of documents', () => {
48+
appWithOrama.orama.insert({ quote: 'Hello', author: 'World' }).then(id => {
49+
expect(id).type.toBe<string>()
50+
})
4851
})
4952

50-
appWithOrama.get('/hello', async () => {
53+
test('should enable the searching of documents', () => {
54+
appWithOrama.get('/hello', async () => {
5155

52-
const {orama} = appWithOrama
53-
const result = await orama.search({ term: 'hello' })
56+
const {orama} = appWithOrama
57+
const result = await orama.search({ term: 'hello' })
5458

55-
expectType<Results<InternalTypedDocument<MySchema>>>(result)
56-
expectType<string>(result.hits[0].document.author)
59+
expect(result).type.toBe<Results<InternalTypedDocument<MySchema>>>()
60+
expect(result.hits[0].document.author).type.toBe<string>()
5761

58-
return {
59-
hello: result.hits
60-
}
62+
return {
63+
hello: result.hits
64+
}
65+
})
6166
})
6267

63-
expectType<{
64-
insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => Promise<string>,
65-
search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Promise<Results<Schema<typeof mySchema>>>,
66-
persist?: () => Promise<any>,
67-
}>(appWithOrama.orama)
68-
69-
fp(function(fastify) {
70-
const fastifyWithOrama = fastify.withOrama<typeof mySchema>()
71-
72-
expectType<{
68+
test('should expose the Orama API', () => {
69+
expect(appWithOrama.orama).type.toBe<{
7370
insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => Promise<string>,
7471
search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Promise<Results<Schema<typeof mySchema>>>,
7572
persist?: () => Promise<any>,
76-
}>(fastifyWithOrama.orama)
73+
}>()
74+
})
75+
76+
77+
test('should enable the withOrama method', () => {
78+
fp(function(fastify) {
79+
const fastifyWithOrama = fastify.withOrama<typeof mySchema>()
80+
81+
expect(fastifyWithOrama.orama).type.toBe<{
82+
insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => Promise<string>,
83+
search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Promise<Results<Schema<typeof mySchema>>>,
84+
persist?: () => Promise<any>,
85+
}>()
86+
})
7787
})

0 commit comments

Comments
 (0)