bv-ui-core 2.9.2 → 2.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,14 +83,15 @@ module.exports = function BvFetch ({ shouldCache, cacheName, cacheLimit }) {
83
83
  }
84
84
  }).then(() => {
85
85
  if (canBeCached) {
86
- const clonedResponse = response.clone()
86
+ const clonedResponse = response.clone();
87
+ const sizeCheck = response.clone();
87
88
  const newHeaders = new Headers();
88
89
  clonedResponse.headers.forEach((value, key) => {
89
90
  newHeaders.append(key, value);
90
91
  });
91
92
  newHeaders.append('X-Bazaarvoice-Cached-Time', Date.now())
92
93
  // Get response text to calculate its size
93
- clonedResponse.text().then(text => {
94
+ sizeCheck.text().then(text => {
94
95
  // Calculate size of response text in bytes
95
96
  const sizeInBytes = new Blob([text]).size;
96
97
 
@@ -166,6 +167,10 @@ module.exports = function BvFetch ({ shouldCache, cacheName, cacheLimit }) {
166
167
  // Check if response is available in cache
167
168
  const newPromise = this.fetchFromCache(cacheKey)
168
169
  .then((cachedResponse) => {
170
+ if (!cachedResponse) {
171
+ this.cachedUrls.delete(cacheKey)
172
+ return Promise.resolve(null);
173
+ }
169
174
  // If response found in cache, return it
170
175
  if (cachedResponse) {
171
176
  return cachedResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bv-ui-core",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
4
4
  "license": "Apache 2.0",
5
5
  "description": "Bazaarvoice UI-related JavaScript",
6
6
  "repository": {
@@ -140,16 +140,17 @@ describe('BvFetch', function () {
140
140
  bvFetchInstance.bvFetchFunc(url, options)
141
141
  .then(response => {
142
142
  // Check if response is fetched from network
143
- expect(response).to.not.be.null;
144
- console.log(response.body)
143
+ setTimeout(() => {
144
+ expect(response).to.not.be.null;
145
+ console.log(response.body)
145
146
 
146
147
  // Check if caches.match was called
147
- expect(cacheStub.calledOnce).to.be.false;
148
+ expect(cacheStub.calledOnce).to.be.false;
148
149
 
149
150
  // Check if response is not cached
150
- const cachedResponse = cacheStorage.get(url);
151
- expect(cachedResponse).to.be.undefined;
152
-
151
+ const cachedResponse = cacheStorage.get(url);
152
+ expect(cachedResponse).to.be.undefined;
153
+ }, 500)
153
154
  done();
154
155
  })
155
156
  .catch(done);