|
27 | 27 |
|
28 | 28 | import { assert, expect } from "chai"; |
29 | 29 | import { createHash } from "crypto"; |
30 | | -import { readFile, stat, unlink, writeFile } from "fs/promises"; |
| 30 | +import { existsSync } from "fs"; |
| 31 | +import { readdir, readFile, stat, unlink, writeFile } from "fs/promises"; |
31 | 32 | import * as os from 'os'; |
32 | 33 | import path from "path/posix"; |
33 | 34 | import { env } from "process"; |
@@ -524,40 +525,72 @@ async function assureDebugLevelLoggingIsEnabled() { |
524 | 525 | export function printRascalOutputOnFailure(channel: 'Language Parametric Rascal' | 'Rascal MPL') { |
525 | 526 |
|
526 | 527 | const ZOOM_OUT_FACTOR = 5; |
| 528 | + const N_LOG_LINES = 250; |
| 529 | + // We guess some locations where the logs can be, since we cannot easily retrieve those from VS Code. |
| 530 | + const TEST_STORAGE_DIRS = [ |
| 531 | + path.join(path.resolve(), "uitests"), // typical CI path |
| 532 | + path.join(os.tmpdir(), "vscode-uitests") // typical local path |
| 533 | + ]; |
| 534 | + |
527 | 535 | afterEach("print output in case of failure", async function () { |
528 | 536 | if (!this.currentTest || this.currentTest.state !== "failed") { return; } |
529 | | - const bbp = new BottomBarPanel(); |
530 | | - try { |
531 | | - for (let z = 0; z < ZOOM_OUT_FACTOR; z++) { |
532 | | - await new Workbench().executeCommand('workbench.action.zoomOut'); |
533 | | - } |
534 | | - await bbp.maximize(); |
535 | | - console.log('**********************************************'); |
536 | | - console.log('***** Rascal MPL output for the failed tests: '); |
537 | | - let textLines: WebElement[] = []; |
538 | | - let tries = 0; |
539 | | - while (textLines.length === 0 && tries < 3) { |
540 | | - await showRascalOutput(bbp, channel); |
541 | | - textLines = await ignoreFails(bbp.findElements(By.className('view-line'))) ?? []; |
542 | | - tries++; |
543 | | - } |
544 | | - if (textLines.length === 0) { |
545 | | - console.log("We could not capture the output lines"); |
546 | | - } |
547 | 537 |
|
548 | | - for (const l of textLines) { |
549 | | - console.log(await l.getText()); |
| 538 | + console.log('**********************************************'); |
| 539 | + console.log(`***** ${channel} output for the failed tests: `); |
| 540 | + |
| 541 | + let foundLogs = false; |
| 542 | + for (const vsCodeDir of TEST_STORAGE_DIRS) { |
| 543 | + try { |
| 544 | + const logDir = path.join(vsCodeDir, "settings", "logs"); |
| 545 | + if (existsSync(logDir)) { |
| 546 | + for (const entry of await readdir(logDir, {recursive: true})) { |
| 547 | + if (entry.includes("usethesource.rascalmpl") && entry.includes(channel)) { |
| 548 | + console.log(`***** ${entry}`); |
| 549 | + const contents = await readFile(path.join(logDir, entry), {encoding: "utf-8"}); |
| 550 | + console.log(contents.split('\n').splice(-N_LOG_LINES).join('\n')); |
| 551 | + foundLogs = true; |
| 552 | + } |
| 553 | + } |
| 554 | + } |
| 555 | + } catch (e) { |
| 556 | + console.log(`Error capturing logs in ${vsCodeDir}: `, e); |
550 | 557 | } |
551 | | - } catch (e) { |
552 | | - console.log('Error capturing output: ', e); |
553 | 558 | } |
554 | | - finally { |
555 | | - console.log('*******End output*****************************'); |
556 | | - for (let z = 0; z < ZOOM_OUT_FACTOR; z++) { |
557 | | - await new Workbench().executeCommand('workbench.action.zoomIn'); |
| 559 | + |
| 560 | + if (!foundLogs) { |
| 561 | + // Fall back to legacy copy-from-VS Code approach if there were no log files. |
| 562 | + const bbp = new BottomBarPanel(); |
| 563 | + try { |
| 564 | + for (let z = 0; z < ZOOM_OUT_FACTOR; z++) { |
| 565 | + await new Workbench().executeCommand('workbench.action.zoomOut'); |
| 566 | + } |
| 567 | + await bbp.maximize(); |
| 568 | + let textLines: WebElement[] = []; |
| 569 | + let tries = 0; |
| 570 | + while (textLines.length === 0 && tries < 3) { |
| 571 | + await showRascalOutput(bbp, channel); |
| 572 | + textLines = await ignoreFails(bbp.findElements(By.className('view-line'))) ?? []; |
| 573 | + tries++; |
| 574 | + } |
| 575 | + if (textLines.length === 0) { |
| 576 | + console.log("We could not capture the output lines"); |
| 577 | + } |
| 578 | + |
| 579 | + for (const l of textLines) { |
| 580 | + console.log(await l.getText()); |
| 581 | + } |
| 582 | + } catch (e) { |
| 583 | + console.log('Error capturing output: ', e); |
| 584 | + } |
| 585 | + finally { |
| 586 | + for (let z = 0; z < ZOOM_OUT_FACTOR; z++) { |
| 587 | + await new Workbench().executeCommand('workbench.action.zoomIn'); |
| 588 | + } |
| 589 | + await bbp.closePanel(); |
558 | 590 | } |
559 | | - await bbp.closePanel(); |
560 | 591 | } |
| 592 | + |
| 593 | + console.log('*******End output*****************************'); |
561 | 594 | }); |
562 | 595 | } |
563 | 596 |
|
|
0 commit comments