Skip to content
This repository has been archived by the owner on Jun 12, 2022. It is now read-only.

Commit

Permalink
test(cache): started writing cache tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Mar 31, 2017
1 parent b872a2c commit 65a9f8b
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions test/cache.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
'use strict'

const Buffer = require('safe-buffer').Buffer

const test = require('tap').test
const tnock = require('./util/tnock')

const fetch = require('..')

const CACHE = require('./util/test-dir')(__filename)
const CONTENT = Buffer.from('hello, world!')
const HOST = 'https://local.registry.npm'

test('accepts a local path for caches', t => {
tnock(t, HOST).get('/test').reply(200, CONTENT)
return fetch(`${HOST}/test`, {
cacheManager: CACHE,
retry: {retries: 0}
}).then(res => res.buffer()).then(body => {
t.deepEqual(body, CONTENT, 'got remote content')
return fetch(`${HOST}/test`, {
cacheManager: CACHE
}).then(res => {
t.equal(res.status, 200, 'non-stale cached res has 200 status')
return res.buffer()
}).then(body => {
t.deepEqual(body, CONTENT, 'got cached content')
})
})
})

test('accepts a local path for caches')
test('matches requests by url')
test('sends both If-None-Match and If-Modified-Since headers')
test('status code is 304 on cache hit')
test('status code is 304 on revalidated cache hit')
test('status code is 200 on cache miss + request')
test('cached request updated on 304 (so no longer stale)')
test('Warning header removed on cache hit')
Expand Down

0 comments on commit 65a9f8b

Please sign in to comment.