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
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module.exports = require('neostandard')({
ts: true,
ignores: ['dist/', 'node_modules/', 'test/'],
ignores: ['lib/', 'node_modules/', 'test/'],
})
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
"fastify-plugin": "^6.0.0"
},
"files": [
"/lib",
"/typings"
"/lib"
],
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fp from 'fastify-plugin'
import fp = require('fastify-plugin')
Comment thread
Tony133 marked this conversation as resolved.
import { flashFactory } from './flash'
import '@fastify/secure-session'

Expand Down
28 changes: 27 additions & 1 deletion tests/index.test.ts → test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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<SessionData>

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)
})
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"skipLibCheck": true
Comment thread
mcollina marked this conversation as resolved.
},
"exclude": ["node_modules"],
"include": ["./src/**/*.ts", "./tests/**/*.ts"],
"include": ["./src/**/*.ts", "test/**/*.ts"],
"incremental": true
}
Loading