Clear and restore existing stored items for tests.

This commit is contained in:
Bauke 2023-05-04 14:22:44 +02:00
parent 1c2397b8f6
commit 8eb5e7d972
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 16 additions and 9 deletions

View File

@ -1,13 +1,8 @@
import browser from "webextension-polyfill";
import {type TestContext, setup} from "@holllo/test"; import {type TestContext, setup} from "@holllo/test";
import {type Value} from "@holllo/webextension-storage"; import {type Value} from "@holllo/webextension-storage";
import { import {type Item, createItem, nextItem, nextItemId} from "./item.js";
type Item,
createItem,
nextItem,
nextItemId,
storageForPrefix,
} from "./item.js";
const testText = "Test Item"; const testText = "Test Item";
const testUrl = "https://example.org/"; const testUrl = "https://example.org/";
@ -34,9 +29,21 @@ function assertItem(item: Value<Item>, test: TestContext): void {
await setup( await setup(
"Item", "Item",
async (group) => { async (group) => {
const existingStorages: Array<Record<string, any>> = [];
group.beforeAll(async () => { group.beforeAll(async () => {
// TODO: Temporarily store existing storage and run the tests, and then existingStorages.push(
// restore it again. await browser.storage.local.get(),
await browser.storage.sync.get(),
);
await browser.storage.local.clear();
await browser.storage.sync.clear();
});
group.afterAll(async () => {
await browser.storage.local.set(existingStorages[0]);
await browser.storage.sync.set(existingStorages[1]);
}); });
group.test("create & nextItem", async (test) => { group.test("create & nextItem", async (test) => {