From 24fbb15155e1ff337d7e50f1042a7ba14641b245 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Thu, 27 Nov 2025 10:07:07 +0000 Subject: [PATCH] chore(index): add jsdoc types --- index.js | 3 +++ test/index.test.js | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6b53b6c..0a0e332 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ const methodNames = [ 'type', 'types' ] +/** @this {import('fastify').FastifyRequest} */ function acceptsMethod () { if (!this.raw[acceptsObjectSymbol]) { this.raw[acceptsObjectSymbol] = accepts(this.raw) @@ -20,6 +21,7 @@ function acceptsMethod () { return this.raw[acceptsObjectSymbol] } +/** @this {import('fastify').FastifyReply} */ function replyAcceptMethod () { if (!this.request[acceptsObjectSymbol]) { this.request[acceptsObjectSymbol] = accepts(this.request.raw) @@ -27,6 +29,7 @@ function replyAcceptMethod () { return this.request[acceptsObjectSymbol] } +/** @type {typeof import('./types/index').fastifyAccepts} */ function fastifyAccepts (fastify, options, done) { fastify.decorateRequest('accepts', acceptsMethod) diff --git a/test/index.test.js b/test/index.test.js index aa90f23..3ea09a5 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -6,6 +6,8 @@ const fastifyAccepts = require('..') const Fastify = require('fastify') +/** @typedef {import('node:test').TestContext} TestContext */ + const testCases = [ { name: 'request - no header', @@ -88,7 +90,7 @@ const testCases = [ } ] -test('accept header', async t => { +test('accept header', async (/** @type {TestContext} */ t) => { t.plan(testCases.length) const fastify = Fastify() @@ -120,7 +122,7 @@ test('accept header', async t => { const BASE_URL = `http://localhost:${fastify.server.address().port}` for (const testCase of testCases) { - await t.test(testCase.name, async (t) => { + await t.test(testCase.name, async (/** @type {TestContext} */ t) => { t.plan(1) const result = await fetch(`${BASE_URL}${testCase.url}`, { @@ -133,7 +135,7 @@ test('accept header', async t => { } }) -test('no reply decorator', async function (t) { +test('no reply decorator', async function (/** @type {TestContext} */ t) { const fastify = Fastify() fastify.register(fastifyAccepts, { decorateReply: false }) await fastify.ready()