Skip to content

Commit

Permalink
Fix clearStoredLevels() helper and remaining tests
Browse files Browse the repository at this point in the history
The `clearStoredLevels()` helper did not work correctly for named
loggers -- it looked for cookie names like `loglevel:whatever` instead
of `loglevel:%3Awhatever` (cookie names and values are URL-encoded).

This also fixes another test that started failing after an earlier fix,
I think because of timing/ordering issues. Explicitly clearing storage
before the test fixed the issue (the test was implicitly expecting
nothing to be stored).
  • Loading branch information
Mr0grog committed Jan 11, 2024
1 parent bd0f924 commit 859750c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test/default-level-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ define(['test/test-helpers'], function(testHelpers) {
});

describe("If no level is saved", function() {
beforeEach(function () {
testHelpers.clearStoredLevels();
});

it("new level is always set", function(log) {
log.setDefaultLevel("trace");
expect(log).toBeAtLevel("trace");
Expand Down
2 changes: 1 addition & 1 deletion test/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ define(function () {
window.localStorage.clear();
}
if (self.isCookieStorageAvailable()) {
var storedKeys = window.document.cookie.match(/(?:^|;\s)(loglevel(\:\w+)?)(?=\=)/g);
var storedKeys = window.document.cookie.match(/(?:^|;\s)(loglevel(%3a\w+)?)(?=\=)/ig);
if (storedKeys) {
for (var i = 0; i < storedKeys.length; i++) {
window.document.cookie = storedKeys[i] + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT;";
Expand Down

0 comments on commit 859750c

Please sign in to comment.