Skip to content

Commit

Permalink
Add browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtusnio committed Aug 24, 2024
1 parent c4f9b03 commit c1bca53
Show file tree
Hide file tree
Showing 3 changed files with 841 additions and 35 deletions.
51 changes: 51 additions & 0 deletions browser_tests/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as puppeteer from "puppeteer";

const EXTENSION_PATH = './';
const EXTENSION_ID = 'cmocagfamghfobhcgipdfhkblaghlbff';

let browser = null;
let workerTarget = null
let worker = null

beforeEach(async () => {
browser = await puppeteer.launch({
headless: false,
args: [
`--disable-extensions-except=${EXTENSION_PATH}`,
`--load-extension=${EXTENSION_PATH}`
]
});

workerTarget = await browser.waitForTarget(
// Assumes that there is only one service worker created by the extension and its URL ends with background.js.
target =>
target.type() === 'service_worker'
);
worker = await workerTarget.worker()
});

afterEach(async () => {
await browser.close();
browser = null;
workerTarget = null
});


test("clicking the extension button activates the extension", async () => {
const someOtherPage = await browser.newPage();
await someOtherPage.goto("https://www.google.com/", { waitUntil: ['domcontentloaded', "networkidle2"] });
await someOtherPage.bringToFront();

await worker.evaluate(async () => {
const tabs = await chrome.tabs.query({ active: true })
await chrome.action.onClicked.dispatch(tabs[0]);
});


const storage = await worker.evaluate(async () => {
return await chrome.storage.local.get(["enabled"])

})

expect(storage).toEqual({ "enabled": true })
});
Loading

0 comments on commit c1bca53

Please sign in to comment.