/
memory.spec.js
60 lines (52 loc) · 1.71 KB
/
memory.spec.js
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
57
58
59
60
/**
* Copyright 2015 Google Inc. All Rights Reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file or at
* https://github.com/firebase/superstatic/blob/master/LICENSE
*/
'use strict';
var chai = require('chai');
chai.use(require('chai-as-promised'));
var expect = chai.expect;
var memoryProvider = require('../../../lib/providers/memory');
var RSVP = require('rsvp');
describe('memory provider', function() {
var store;
var provider;
beforeEach(function() {
store = store || {};
provider = memoryProvider({store: store});
});
it('should resolve null if not in the store', function() {
return expect(provider({}, '/whatever')).to.eventually.be.null;
});
it('should return a stream of the content if found', function(done) {
store['/index.html'] = 'foobar';
provider({}, '/index.html').then(function(result) {
var out = '';
result.stream.on('data', function(data) {
out += data;
});
result.stream.on('end', function() {
expect(out).to.eq('foobar');
done();
});
}, done);
});
it('should return an etag of the content', function() {
store['/a.html'] = 'foo';
store['/b.html'] = 'bar';
return RSVP.hash({a: provider({}, '/a.html'), b: provider({}, '/b.html')}).then(function(result) {
expect(result.a.etag).not.to.be.null;
expect(result.b.etag).not.to.be.null;
expect(result.a.etag).not.to.eq(result.b.etag);
});
});
it('should return the length of content', function() {
store['/index.html'] = 'foobar';
return expect(provider({}, '/index.html')).to.eventually.have.property('size', 6);
});
afterEach(function() {
store = null;
});
});