Skip to content

Commit

Permalink
Inject sessionStorage during testing - Firefox won't allow stubbing t…
Browse files Browse the repository at this point in the history
…he real one
  • Loading branch information
dgirardi committed Dec 3, 2021
1 parent 9180a92 commit f112343
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/debugging.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,21 @@ export function addBidderRequestsHook(next, bidderRequests) {
next(includedBidderRequests);
}

export function getConfig(debugging) {
export function getConfig(debugging, {sessionStorage = window.sessionStorage} = {}) {
if (!debugging.enabled) {
disableOverrides();
try {
window.sessionStorage.removeItem(OVERRIDE_KEY);
} catch (e) {
}
sessionStorage.removeItem(OVERRIDE_KEY);
} catch (e) {}
} else {
try {
const intKey = bidInterceptor.KEYS.rules;
const config = deepClone(debugging);
if (config[intKey]) {
config[intKey] = bidInterceptor.serializeConfig(config[intKey]);
}
window.sessionStorage.setItem(OVERRIDE_KEY, JSON.stringify(config));
} catch (e) {
}
sessionStorage.setItem(OVERRIDE_KEY, JSON.stringify(config));
} catch (e) {}
enableOverrides(debugging);
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/spec/debugging_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ describe('Debugging', function () {
const config = 'raw';
const result = 'serialized';
sandbox.stub(BidInterceptor.prototype, 'serializeConfig').returns(result);
sandbox.stub(window.sessionStorage, 'setItem');
const mockSS = {setItem: sinon.spy()};
sandbox.stub(BidInterceptor.prototype, 'updateConfig');
getConfig({
enabled: true,
[interceptorConfigKey]: config
});
[interceptorConfigKey]: config,
}, {sessionStorage: mockSS});
expect(BidInterceptor.prototype.serializeConfig.calledWith(config)).to.be.true;
expect(window.sessionStorage.setItem.calledWith(sinon.match({
expect(mockSS.setItem.calledWith(sinon.match({
[interceptorConfigKey]: result
})));
});
Expand Down

0 comments on commit f112343

Please sign in to comment.