UNPKG

st

Version:

A module for serving static files. Does etags, caching, etc.

43 lines (35 loc) 1.23 kB
import zlib from 'node:zlib' import { test } from './support/tap-shim.js' global.options = { cachedHeader: true // inspect to see if something is served from cache } const { req, stExpect } = await import('./support/common.js') test('does not gzip first response', (t) => { req('/test/st.js', { 'accept-encoding': 'none' }, (er, res, body) => { t.equal(res.statusCode, 200) t.notOk(res.headers['content-encoding']) t.notOk(res.headers['x-from-cache']) t.equal(body.toString(), stExpect) // response is delivered before cache is set, so we'll give it a tiny bit // of grace to close out on the server side before starting the next // test setTimeout(t.end, 100) }) }) test('gzips second response', (t) => { req('/test/st.js', { 'accept-encoding': 'gzip' }, (er, res, body) => { t.error(er, 'no error') t.equal(res.statusCode, 200) t.equal(res.headers['content-encoding'], 'gzip') t.equal(res.headers['x-from-cache'], 'true') t.ok(body, 'returned a body') t.not(body.toString(), stExpect, 'gzipped string') zlib.gunzip(body, (er, body) => { if (er) { throw er } t.equal(body.toString(), stExpect) t.end() }) }) })