From 8eb5e7d9721fa1fd5446f9c36db64843ea884a2f Mon Sep 17 00:00:00 2001 From: Bauke Date: Thu, 4 May 2023 14:22:44 +0200 Subject: [PATCH] Clear and restore existing stored items for tests. --- source/item/item.test.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/source/item/item.test.ts b/source/item/item.test.ts index 93faf89..b50b16e 100644 --- a/source/item/item.test.ts +++ b/source/item/item.test.ts @@ -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, test: TestContext): void { await setup( "Item", async (group) => { + const existingStorages: Array> = []; + 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) => {