req-id-gen-factory.test.js — fastify Source File
Architecture documentation for req-id-gen-factory.test.js, a javascript file in the fastify codebase.
Entity Profile
Source Code
'use strict'
const { test } = require('node:test')
const { reqIdGenFactory } = require('../../lib/req-id-gen-factory')
test('should create incremental ids deterministically', t => {
t.plan(1)
const reqIdGen = reqIdGenFactory()
for (let i = 1; i < 1e4; ++i) {
if (reqIdGen() !== 'req-' + i.toString(36)) {
t.assert.fail()
break
}
}
t.assert.ok(true)
})
test('should have prefix "req-"', t => {
t.plan(1)
const reqIdGen = reqIdGenFactory()
t.assert.ok(reqIdGen().startsWith('req-'))
})
test('different id generator functions should have separate internal counters', t => {
t.plan(5)
const reqIdGenA = reqIdGenFactory()
const reqIdGenB = reqIdGenFactory()
t.assert.strictEqual(reqIdGenA(), 'req-1')
t.assert.strictEqual(reqIdGenA(), 'req-2')
t.assert.strictEqual(reqIdGenB(), 'req-1')
t.assert.strictEqual(reqIdGenA(), 'req-3')
t.assert.strictEqual(reqIdGenB(), 'req-2')
})
test('should start counting with 1', t => {
t.plan(1)
const reqIdGen = reqIdGenFactory()
t.assert.strictEqual(reqIdGen(), 'req-1')
})
test('should handle requestIdHeader and return provided id in header', t => {
t.plan(1)
const reqIdGen = reqIdGenFactory('id')
t.assert.strictEqual(reqIdGen({ headers: { id: '1337' } }), '1337')
})
test('should handle requestIdHeader and fallback if id is not provided in header', t => {
t.plan(1)
const reqIdGen = reqIdGenFactory('id')
t.assert.strictEqual(reqIdGen({ headers: { notId: '1337' } }), 'req-1')
})
// ... (74 more lines)
Source
Frequently Asked Questions
What does req-id-gen-factory.test.js do?
req-id-gen-factory.test.js is a source file in the fastify codebase, written in javascript.
Where is req-id-gen-factory.test.js in the architecture?
req-id-gen-factory.test.js is located at test/internals/req-id-gen-factory.test.js (directory: test/internals).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free