Skip to content

Commit

Permalink
Test code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrruby committed Jul 18, 2024
1 parent 636cdb0 commit ee814bc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion holo-key-manager-extension/scripts/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const processMessageExtension = async (
};

chrome.runtime.onMessage.addListener((message: Message, sender, sendResponse: SendResponse) => {
console.log('Received message from', sender);
console.log(JSON.stringify(message));
const sendResponseWithSender = (response: ActionPayload) =>
sendResponse({ ...response, sender: SENDER_BACKGROUND_SCRIPT });

Expand Down
4 changes: 0 additions & 4 deletions holo-key-manager-extension/scripts/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ const parseAndHandleMessage = async (event: MessageEvent) => {
const parsedResult = MessageWithIdSchema.safeParse(event.data);
if (!parsedResult.success || parsedResult.data.sender === SENDER_BACKGROUND_SCRIPT) return;
try {
window.postMessage('Sending message to background script', '*');
window.postMessage(JSON.stringify(chrome), '*');
window.postMessage(JSON.stringify(chrome.runtime), '*');
window.postMessage(JSON.stringify(chrome.runtime.sendMessage), '*');
const response = await sendMessage({ ...parsedResult.data, origin: event.origin });
const parsedMessageSchema = parseMessageSchema(response);
window.postMessage(responseToMessage(parsedMessageSchema.data, parsedResult.data.id), '*');
Expand Down
17 changes: 15 additions & 2 deletions tests/needsSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ export default async function needsSetupTest(browser: Browser) {
const page = await browser.newPage();
await page.goto('http://localhost:3007/tests/test.html');

const targets = browser.targets();
console.log(targets);
// Find the service worker target
const swTarget = await browser.waitForTarget((target) => target.type() === 'service_worker');

// Create a new page for the service worker
const swPage = await swTarget.createCDPSession();

// Enable console logging for the service worker
await swPage.send('Runtime.enable');

// Listen for console messages from the service worker
swPage.on('Runtime.consoleAPICalled', (event) => {
const { type, args } = event;
const formattedArgs = args.map((arg) => arg.value || arg.description).join(', ');
console.log(`Service Worker Console [${type}]: ${formattedArgs}`);
});

await page.evaluate(() => {
window.addEventListener('message', (event) => {
Expand Down

0 comments on commit ee814bc

Please sign in to comment.