Blame view

node_modules/nocache/test/index.js 1.42 KB
f7563de62   Palak Handa   first commit
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
53
54
55
56
  var nocache = require('..')
  
  var assert = require('assert')
  var connect = require('connect')
  var request = require('supertest')
  
  describe('nocache', function () {
    it('sets headers properly', function (done) {
      var app = connect()
      app.use(function (req, res, next) {
        res.setHeader('ETag', 'abc123')
        next()
      })
      app.use(nocache())
      app.use(function (req, res) {
        res.end('Hello world!')
      })
  
      request(app).get('/')
        .expect('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
        .expect('Pragma', 'no-cache')
        .expect('Expires', '0')
        .expect('ETag', 'abc123')
        .end(done)
    })
  
    it('can be told to squash etags', function (done) {
      var app = connect()
      app.use(function (req, res, next) {
        res.setHeader('ETag', 'abc123')
        next()
      })
      app.use(nocache({ noEtag: true }))
      app.use(function (req, res) {
        res.end('Hello world!')
      })
  
      request(app).get('/')
        .expect('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
        .expect('Pragma', 'no-cache')
        .expect('Expires', '0')
        .end(function (err, res) {
          if (err) {
            done(err)
            return
          }
          assert.equal(res.header.etag, undefined)
          done()
        })
    })
  
    it('names its function and middleware', function () {
      assert.equal(nocache.name, 'nocache')
      assert.equal(nocache().name, 'nocache')
    })
  })