Skip to content

Commit

Permalink
log after each test
Browse files Browse the repository at this point in the history
  • Loading branch information
midleman committed Jan 24, 2025
1 parent 7787234 commit ceb5cb8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 2 additions & 3 deletions test/e2e/pages/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ export class Console {
}

async logConsoleContents() {
this.code.logger.log('------------------');
this.code.logger.log('Console contents:');
this.code.logger.log('------------------');
this.code.logger.log('---- START: Console Contents ----');
const contents = await this.code.driver.page.locator(CONSOLE_LINES).allTextContents();
contents.forEach(line => this.code.logger.log(line));
this.code.logger.log('---- END: Console Contents ----');
}

async typeToConsole(text: string, delay = 30, pressEnter = false) {
Expand Down
19 changes: 19 additions & 0 deletions test/e2e/pages/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,23 @@ export class Terminal {
}
}, text);
}

async logTerminalContents() {
const plainText = await this.code.driver.page.evaluate(() => {
const rows = document.querySelectorAll('.xterm-rows > div');
return Array.from(rows)
.map((row) => {
const spans = row.querySelectorAll('span');
return Array.from(spans)
.map((span) => span.textContent?.trim() || '')
.join(' '); // Join spans within a row with a space
})
.filter((line) => line && line.length > 0) // Remove empty lines
.join('\n'); // Join rows with newlines
});

this.code.logger.log('---- START: Terminal Contents ----');
this.code.logger.log(plainText);
this.code.logger.log('---- END: Terminal Contents ----');
}
}
5 changes: 4 additions & 1 deletion test/e2e/tests/_test.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export const test = base.extend<TestFixtures, WorkerFixtures>({
await use(app.code.driver.page);
},

autoTestFixture: [async ({ logger, suiteId }, use, testInfo) => {
autoTestFixture: [async ({ logger, suiteId, app }, use, testInfo) => {
if (!suiteId) { throw new Error('suiteId is required'); }

logger.log('');
Expand All @@ -306,6 +306,9 @@ export const test = base.extend<TestFixtures, WorkerFixtures>({
const testTitle = testInfo.title;
const endLog = failed ? `>>> !!! FAILURE !!! Test end: '${testTitle}' !!! FAILURE !!! <<<` : `>>> Test end: '${testTitle}' <<<`;

await app.workbench.console.logConsoleContents();
await app.workbench.terminal.logTerminalContents();

logger.log('');
logger.log(endLog);
logger.log('');
Expand Down

0 comments on commit ceb5cb8

Please sign in to comment.