Skip to content

Commit

Permalink
Run tests in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jan 19, 2024
1 parent 1ebce7b commit 3ac32d7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/test/background/testingApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { executeFunction } from "webext-content-scripts";
import { once } from "../../shared.js";

export async function ensureScripts(tabId: number): Promise<void> {
await browser.tabs.executeScript(tabId, {
Expand Down Expand Up @@ -56,14 +57,27 @@ export async function createTargets(): Promise<Targets> {
throw new Error("The expected frames were not found");
}

const getHiddenWindow = once(async (): Promise<number> => {
const { id } = await browser.windows.create({
focused: false,
state: "minimized",
});
return id!;
});

export async function openTab(url: string): Promise<number> {
const tab = await browser.tabs.create({
windowId: await getHiddenWindow(),
active: false,
url,
});
return tab.id!;
}

export async function closeHiddenWindow(): Promise<void> {
return browser.windows.remove(await getHiddenWindow());
}

export async function closeTab(tabId: number): Promise<void> {
await browser.tabs.remove(tabId);
}

0 comments on commit 3ac32d7

Please sign in to comment.