Clear and restore existing stored items for tests.
This commit is contained in:
parent
1c2397b8f6
commit
8eb5e7d972
|
@ -1,13 +1,8 @@
|
|||
import browser from "webextension-polyfill";
|
||||
import {type TestContext, setup} from "@holllo/test";
|
||||
import {type Value} from "@holllo/webextension-storage";
|
||||
|
||||
import {
|
||||
type Item,
|
||||
createItem,
|
||||
nextItem,
|
||||
nextItemId,
|
||||
storageForPrefix,
|
||||
} from "./item.js";
|
||||
import {type Item, createItem, nextItem, nextItemId} from "./item.js";
|
||||
|
||||
const testText = "Test Item";
|
||||
const testUrl = "https://example.org/";
|
||||
|
@ -34,9 +29,21 @@ function assertItem(item: Value<Item>, test: TestContext): void {
|
|||
await setup(
|
||||
"Item",
|
||||
async (group) => {
|
||||
const existingStorages: Array<Record<string, any>> = [];
|
||||
|
||||
group.beforeAll(async () => {
|
||||
// TODO: Temporarily store existing storage and run the tests, and then
|
||||
// restore it again.
|
||||
existingStorages.push(
|
||||
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) => {
|
||||
|
|
Loading…
Reference in New Issue