From 3ac32d7e55c27ebf13558fc168cc1dbf5d6abc4b Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Sat, 20 Jan 2024 01:44:02 +0800 Subject: [PATCH] Run tests in the background --- source/test/background/testingApi.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/test/background/testingApi.ts b/source/test/background/testingApi.ts index 2884a73..5d2a142 100644 --- a/source/test/background/testingApi.ts +++ b/source/test/background/testingApi.ts @@ -1,4 +1,5 @@ import { executeFunction } from "webext-content-scripts"; +import { once } from "../../shared.js"; export async function ensureScripts(tabId: number): Promise { await browser.tabs.executeScript(tabId, { @@ -56,14 +57,27 @@ export async function createTargets(): Promise { throw new Error("The expected frames were not found"); } +const getHiddenWindow = once(async (): Promise => { + const { id } = await browser.windows.create({ + focused: false, + state: "minimized", + }); + return id!; +}); + export async function openTab(url: string): Promise { const tab = await browser.tabs.create({ + windowId: await getHiddenWindow(), active: false, url, }); return tab.id!; } +export async function closeHiddenWindow(): Promise { + return browser.windows.remove(await getHiddenWindow()); +} + export async function closeTab(tabId: number): Promise { await browser.tabs.remove(tabId); }