bv-ui-core 2.9.11 → 2.9.13

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.
@@ -168,6 +168,8 @@ module.exports = function BvFetch ({ shouldCache, cacheName, cacheLimit, exclude
168
168
  if (typeof this.shouldCache === 'function') {
169
169
  canBeCached = this.shouldCache(json);
170
170
  }
171
+ }).catch(() => {
172
+ canBeCached = false;
171
173
  }).then(() => {
172
174
  if (canBeCached) {
173
175
  const clonedResponse = response.clone();
@@ -378,4 +380,4 @@ module.exports = function BvFetch ({ shouldCache, cacheName, cacheLimit, exclude
378
380
 
379
381
  this.debounceCleanupExpiredCache = debounce(this.manageCache, 8000);
380
382
 
381
- }
383
+ }
@@ -18,7 +18,7 @@ var getGlobal = function () {
18
18
  windows object during transpilation with __esModule being set. Below code would support
19
19
  global import in all bundle use cases
20
20
  */
21
- if (globalObj && globalObj.__esModule) {
21
+ if (globalObj && globalObj.__esModule && typeof window !== 'undefined' && globalObj !== window) {
22
22
  const proxyGlobal = new Proxy(globalObj, {
23
23
  get: function (target, prop) {
24
24
  if (prop === 'default') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bv-ui-core",
3
- "version": "2.9.11",
3
+ "version": "2.9.13",
4
4
  "license": "Apache 2.0",
5
5
  "description": "Bazaarvoice UI-related JavaScript",
6
6
  "repository": {
@@ -168,6 +168,26 @@ describe('BvFetch', function () {
168
168
  .catch(done);
169
169
  });
170
170
 
171
+ it('should handle a 204 response without a JSON parse error', function (done) {
172
+ const cacheKey = bvFetchInstance.generateCacheKey('https://example.com/empty', {});
173
+ const shouldCache = sinon.spy();
174
+ const response = new Response(null, {
175
+ status: 204,
176
+ headers: {
177
+ 'Cache-Control': 'max-age=3600'
178
+ }
179
+ });
180
+
181
+ bvFetchInstance.shouldCache = shouldCache;
182
+ expect(() => bvFetchInstance.cacheData(response, cacheKey)).to.not.throw();
183
+
184
+ setTimeout(() => {
185
+ expect(shouldCache.called).to.be.false;
186
+ expect(cacheStorage.get(cacheKey)).to.be.undefined;
187
+ done();
188
+ }, 0);
189
+ });
190
+
171
191
  it('should delete cache when size is greater than 10 MB', function (done) {
172
192
  // Mock cache entries exceeding 10 MB
173
193
  const mockCacheEntries = [
@@ -24,4 +24,23 @@ describe('lib/global', function () {
24
24
  }
25
25
  });
26
26
 
27
+ it('should not wrap window in a Proxy when globalObj is window even if __esModule is set', function () {
28
+ if (typeof window !== 'undefined') {
29
+ window.__esModule = true;
30
+ var result = require('../../../lib/global');
31
+ // When globalObj === window, the proxy branch should be skipped,
32
+ // so the result should be strictly equal to window.
33
+ expect(result).to.equal(window);
34
+ delete window.__esModule;
35
+ }
36
+ });
37
+
38
+ it('should return the global object directly when __esModule is not set', function () {
39
+ if (typeof window !== 'undefined') {
40
+ delete window.__esModule;
41
+ var result = require('../../../lib/global');
42
+ expect(result).to.equal(window);
43
+ }
44
+ });
45
+
27
46
  });