als-send-file
Version:
file serving with advanced options for caching, headers, and error handling, compatible with Express middleware.
35 lines (29 loc) • 1.11 kB
JavaScript
const { describe, it, beforeEach, afterEach, after } = require('node:test');
const assert = require('node:assert');
const optionsSchema = require('../lib/options-schema')
it('Defaults', () => {
assert.deepStrictEqual(optionsSchema.validate({}), {
charset: undefined,
maxAge: undefined,
public: undefined,
etag: true,
download: false,
noCache: false,
noStore: false
})
})
it('charset', () => {
assert.throws(() => optionsSchema.validate({charset:''}))
assert.throws(() => optionsSchema.validate({charset:'a'.repeat(51)}))
assert.throws(() => optionsSchema.validate({charset:58}))
assert.throws(() => optionsSchema.validate({charset:{}}))
})
it('maxAge', () => {
assert(optionsSchema.validate({maxAge:'adgf'}).maxAge === 3600)
assert(optionsSchema.validate({maxAge:{}}).maxAge === 3600)
assert(optionsSchema.validate({maxAge:'58'}).maxAge === 3600)
})
it('Booleans',() => {
assert(optionsSchema.validate({etag:false}).etag === false)
assert(optionsSchema.validate({download:true}).etag === true)
})