File size: 1,552 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import { ignoreLoggingIncomingRequests } from './log-requests'
import type { NodeNextRequest } from '../base-http/node'
import type { LoggingConfig } from '../config-shared'
describe('ignoreLoggingIncomingRequests', () => {
const createMockRequest = (url: string): NodeNextRequest => {
return { url } as NodeNextRequest
}
it('should respect boolean config', () => {
const req = createMockRequest('/test')
expect(
ignoreLoggingIncomingRequests(req, { incomingRequests: false })
).toBe(true)
expect(ignoreLoggingIncomingRequests(req, { incomingRequests: true })).toBe(
false
)
})
it('should not ignore when no ignore patterns configured', () => {
const req = createMockRequest('/test')
expect(ignoreLoggingIncomingRequests(req, {})).toBe(false)
expect(ignoreLoggingIncomingRequests(req, undefined)).toBe(false)
})
it('should handle array of RegExp ignore patterns', () => {
const config: LoggingConfig = {
incomingRequests: {
ignore: [/^\/api\//, /^\/healthcheck/, /^\/_next\/static\//],
},
}
expect(
ignoreLoggingIncomingRequests(createMockRequest('/api/test'), config)
).toBe(true)
expect(
ignoreLoggingIncomingRequests(createMockRequest('/healthcheck'), config)
).toBe(true)
expect(
ignoreLoggingIncomingRequests(
createMockRequest('/_next/static/test.js'),
config
)
).toBe(true)
expect(
ignoreLoggingIncomingRequests(createMockRequest('/page'), config)
).toBe(false)
})
})
|