Skip to content

Commit

Permalink
Check console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrruby committed Jul 18, 2024
1 parent db68503 commit 08231c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 0 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ beforeAll(async () => {
}
const extensionPath = resolve('holo-key-manager-extension', 'build');
browser = await launchBrowserWithExtension(extensionPath);
const version = await browser.version();
console.log('Browser version:', version);
server = startServer();
});

Expand Down
24 changes: 15 additions & 9 deletions tests/needsSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@ import { findTextBySelector } from './helpers';
export default async function needsSetupTest(browser: Browser) {
const page = await browser.newPage();
await page.goto('http://localhost:3007/tests/test.html');
page.on('console', (msg) => {
for (let i = 0; i < msg.args().length; ++i) {
console.log(`${i}: ${msg.args()[i]}`);
}

await page.evaluate(() => {
window.addEventListener('message', (event) => {
console.log(event.data);
});
});
page.on('console', async (message) => {
const type = message.type();
const text = await message.text();
const args = await Promise.all(message.args().map((arg) => arg.jsonValue()));

const formattedArgs = args.map((arg) => JSON.stringify(arg)).join(', ');
console.log(
`Console message [${type}]: ${text}${formattedArgs ? ` | Args: ${formattedArgs}` : ''}`
);
});

const findTextOnPage = findTextBySelector(page);
Expand All @@ -23,11 +34,6 @@ export default async function needsSetupTest(browser: Browser) {

await signUpButton.click();

await new Promise((resolve) => setTimeout(resolve, 2000));

const pageContent = await page.content();
console.log(pageContent);

const needsSetupText = await findTextOnPage('NeedsSetup');
expect(needsSetupText).toBeTruthy();
}

0 comments on commit 08231c5

Please sign in to comment.