Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"redis": "docker run -p 6379:6379 --rm redis:7.2",
"valkey": "docker run -p 6379:6379 --rm valkey/valkey:latest",
"test": "npm run unit && npm run typescript",
"typescript": "tsd",
"typescript": "tstyche",
"unit": "c8 --100 node --test"
},
"keywords": [
Expand Down Expand Up @@ -53,7 +53,7 @@
"eslint": "^9.17.0",
"fastify": "^5.0.0",
"neostandard": "^0.12.0",
"tsd": "^0.33.0",
"tstyche": "^7.0.0",
"why-is-node-running": "^3.2.2"
},
"dependencies": {
Expand All @@ -63,4 +63,4 @@
"publishConfig": {
"access": "public"
}
}
}
8 changes: 4 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ test('Should throw when trying to connect on an invalid host', async (t) => {
t.after(() => fastify.close())

fastify.register(fastifyValkey, {
addresses: [{ host: 'invalid_host' }],
addresses: [{ host: 'invalid_host', port: 9999 }],
connectionBackoff: {
numberOfRetries: 0
}
Expand Down Expand Up @@ -312,7 +312,7 @@ test('Should be able to register multiple namespaced @fastify/valkey instances',
t.assert.ok(fastify.valkey.multiple_namespace2)
})

test('Should throw when @fastify/valkey is initialized with an option that makes valkey throw', async (t) => {
test('Should throw when @fastify/valkey is initialized with an option that makes valkey throw', { skip: process.platform === 'darwin' }, async (t) => {
t.plan(1)

const fastify = Fastify()
Expand All @@ -323,10 +323,10 @@ test('Should throw when @fastify/valkey is initialized with an option that makes
await t.assert.rejects(fastify.ready())
})

test('Should throw when @fastify/valkey is initialized with a namespace and an option that makes valkey throw', async (t) => {
test('Should throw when @fastify/valkey is initialized with a namespace and an option that makes valkey throw', { skip: process.platform === 'darwin' }, async (t) => {
t.plan(1)

const fastify = Fastify()
const fastify = Fastify({ pluginTimeout: 20000 })
t.after(() => fastify.close())

fastify.register(fastifyValkey, {
Expand Down
40 changes: 0 additions & 40 deletions types/index.test-d.ts

This file was deleted.

41 changes: 41 additions & 0 deletions types/index.tst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Fastify, { FastifyInstance } from 'fastify'
import { GlideClient, GlideClusterClient } from '@valkey/valkey-glide'
import { expect } from 'tstyche'
import fastifyValkey, { FastifyValkey, FastifyValkeyPluginOptions, FastifyValkeyNamespacedInstance, } from '.'

const app:FastifyInstance = Fastify()
const valkey = {} as GlideClient
const valkeyCluster = {} as GlideClusterClient
app.register(fastifyValkey, { addresses: [{ host: '127.0.0.1', port: 6379 }] })

app.register(fastifyValkey, {
client: valkey,
closeClient: true,
namespace: 'one'
})

app.register(fastifyValkey, {
namespace: 'two',
addresses: [{ host: '127.0.0.1', port: 6379 }]
})

expect<FastifyValkeyPluginOptions>().type.toBeAssignableFrom({
client: valkeyCluster
})

expect<FastifyValkeyPluginOptions>().type.not.toBeAssignableFrom({
namespace: 'three',
unknownOption: 'this should trigger a typescript error'
})

// Plugin property available
app.after(() => {
expect(app.valkey).type.toBeAssignableTo<GlideClient | GlideClusterClient>()
expect(app.valkey).type.toBe<FastifyValkey>()

expect(app.valkey).type.toBeAssignableTo<FastifyValkeyNamespacedInstance>()
expect(app.valkey.one).type.toBe<
GlideClient | GlideClusterClient | undefined
>()
expect(app.valkey.two).type.toBe<GlideClient | GlideClusterClient | undefined>()
})
Loading