Skip to content

Commit d057b98

Browse files
Bv fetch changes to fix, PD-238557 (#140)
* PD-238557, bug fix * PD-238557, fixing test cases * 2.9.3
1 parent 6713f93 commit d057b98

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

lib/bvFetch/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,15 @@ module.exports = function BvFetch ({ shouldCache, cacheName, cacheLimit }) {
8383
}
8484
}).then(() => {
8585
if (canBeCached) {
86-
const clonedResponse = response.clone()
86+
const clonedResponse = response.clone();
87+
const sizeCheck = response.clone();
8788
const newHeaders = new Headers();
8889
clonedResponse.headers.forEach((value, key) => {
8990
newHeaders.append(key, value);
9091
});
9192
newHeaders.append('X-Bazaarvoice-Cached-Time', Date.now())
9293
// Get response text to calculate its size
93-
clonedResponse.text().then(text => {
94+
sizeCheck.text().then(text => {
9495
// Calculate size of response text in bytes
9596
const sizeInBytes = new Blob([text]).size;
9697

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bv-ui-core",
3-
"version": "2.9.2",
3+
"version": "2.9.3",
44
"license": "Apache 2.0",
55
"description": "Bazaarvoice UI-related JavaScript",
66
"repository": {

test/unit/bvFetch/index.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,17 @@ describe('BvFetch', function () {
140140
bvFetchInstance.bvFetchFunc(url, options)
141141
.then(response => {
142142
// 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)
145146

146147
// Check if caches.match was called
147-
expect(cacheStub.calledOnce).to.be.false;
148+
expect(cacheStub.calledOnce).to.be.false;
148149

149150
// 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)
153154
done();
154155
})
155156
.catch(done);

0 commit comments

Comments
 (0)