diff --git a/eslint.config.js b/eslint.config.js index 5e792c6..4c2c5ff 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -2,5 +2,5 @@ module.exports = require('neostandard')({ ts: true, - ignores: ['dist/', 'node_modules/', 'test/'], + ignores: ['lib/', 'node_modules/', 'test/'], }) diff --git a/package.json b/package.json index 27c5a8f..bffd4a5 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,7 @@ "fastify-plugin": "^6.0.0" }, "files": [ - "/lib", - "/typings" + "/lib" ], "publishConfig": { "access": "public" diff --git a/src/index.ts b/src/index.ts index 732fb21..e7047c0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import fp from 'fastify-plugin' +import fp = require('fastify-plugin') import { flashFactory } from './flash' import '@fastify/secure-session' diff --git a/tests/index.test.ts b/test/index.test.ts similarity index 93% rename from tests/index.test.ts rename to test/index.test.ts index 3541731..d3c8766 100644 --- a/tests/index.test.ts +++ b/test/index.test.ts @@ -2,7 +2,7 @@ import { test, TestContext } from 'node:test' import { join } from 'node:path' import { readFileSync } from 'node:fs' import Fastify from 'fastify' -import fastifySession from '@fastify/secure-session' +import fastifySession, { Session, SessionData } from '@fastify/secure-session' import querystring from 'node:querystring' import fastifyFlash from '../src' @@ -393,3 +393,29 @@ test('reply.flash() with no data', async (t: TestContext) => { t.assert.strictEqual(response.payload, '{"warning":[]}') t.assert.strictEqual(response.statusCode, 200) }) + +test('should return 0 when session storage does not echo back what was just set', async (t: TestContext) => { + t.plan(3) + const fastify = Fastify() + + const fakeSession = { + get: () => undefined, + set: () => {} + } as unknown as Session + + fastify.decorateRequest('session', { getter: () => fakeSession }) + fastify.register(fastifyFlash) + + fastify.get('/test', (req, reply) => { + const count = req.flash('error', 'Something went wrong') + t.assert.strictEqual(count, 0) + reply.send({ count }) + }) + + const response = await fastify.inject({ + method: 'GET', + url: '/test', + }) + t.assert.strictEqual(response.payload, '{"count":0}') + t.assert.strictEqual(response.statusCode, 200) +}) diff --git a/tsconfig.json b/tsconfig.json index 929c740..ed79f80 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,6 @@ "skipLibCheck": true }, "exclude": ["node_modules"], - "include": ["./src/**/*.ts", "./tests/**/*.ts"], + "include": ["./src/**/*.ts", "test/**/*.ts"], "incremental": true }