DEV: Use a separate KVS namespace for tests (#17591)
This commit is contained in:
parent
331874229e
commit
cb40e4c322
|
@ -1,3 +1,5 @@
|
|||
import { isTesting } from "discourse-common/config/environment";
|
||||
|
||||
// A simple key value store that uses LocalStorage
|
||||
let safeLocalStorage;
|
||||
|
||||
|
@ -10,7 +12,7 @@ try {
|
|||
safeLocalStorage["safeLocalStorage"] = true;
|
||||
}
|
||||
} catch (e) {
|
||||
// cookies disabled, we don't care
|
||||
// local storage disabled
|
||||
safeLocalStorage = null;
|
||||
}
|
||||
|
||||
|
@ -18,7 +20,7 @@ export default class KeyValueStore {
|
|||
context = null;
|
||||
|
||||
constructor(ctx) {
|
||||
this.context = ctx;
|
||||
this.context = isTesting() ? `test_${ctx}` : ctx;
|
||||
}
|
||||
|
||||
abandonLocal() {
|
||||
|
|
|
@ -3,14 +3,14 @@ import KeyValueStore from "discourse/lib/key-value-store";
|
|||
|
||||
module("Unit | Utility | key-value-store", function () {
|
||||
test("is able to get the result back from the store", function (assert) {
|
||||
const store = new KeyValueStore("test_");
|
||||
const store = new KeyValueStore("example");
|
||||
store.set({ key: "bob", value: "uncle" });
|
||||
|
||||
assert.strictEqual(store.get("bob"), "uncle");
|
||||
});
|
||||
|
||||
test("is able remove items from the store", function (assert) {
|
||||
const store = new KeyValueStore("test_");
|
||||
const store = new KeyValueStore("example");
|
||||
store.set({ key: "bob", value: "uncle" });
|
||||
store.remove("bob");
|
||||
|
||||
|
@ -18,7 +18,7 @@ module("Unit | Utility | key-value-store", function () {
|
|||
});
|
||||
|
||||
test("is able to nuke the store", function (assert) {
|
||||
const store = new KeyValueStore("test_");
|
||||
const store = new KeyValueStore("example");
|
||||
store.set({ key: "bob1", value: "uncle" });
|
||||
store.abandonLocal();
|
||||
localStorage.a = 1;
|
||||
|
@ -28,7 +28,7 @@ module("Unit | Utility | key-value-store", function () {
|
|||
});
|
||||
|
||||
test("is API-compatible with `localStorage`", function (assert) {
|
||||
const store = new KeyValueStore("test_");
|
||||
const store = new KeyValueStore("example");
|
||||
store.setItem("bob", "uncle");
|
||||
assert.strictEqual(store.getItem("bob"), "uncle");
|
||||
|
||||
|
|
Loading…
Reference in New Issue