Skip to content

Commit

Permalink
test: get logs for failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abdurrahman-ledger authored and nicolas-meilan committed Sep 27, 2024
1 parent 65237db commit 5707a08
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/ledger-live-desktop/index-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface Window {

getAllFeatureFlags: (appLanguage: string) => Partial<{ [key in FeatureId]: Feature }>;
getAllEnvs: () => { [key in EnvName]: unknown };
saveLogs: (path: string) => void;

// for mocking purposes apparently?
// eslint-disable-next-line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { ListAppsResult } from "@ledgerhq/live-common/apps/types";
import { AnnouncementDeviceModelId } from "@ledgerhq/live-common/notifications/AnnouncementProvider/types";
import { getAllFeatureFlags } from "@ledgerhq/live-common/e2e/index";
import { getAllEnvs } from "@ledgerhq/live-env";
import { ipcRenderer } from "electron";
import { memoryLogger } from "~/renderer/logger";

const mockListAppsResult = (
appDesc: string,
Expand Down Expand Up @@ -281,6 +283,25 @@ interface RawEvents {
}
window.getAllFeatureFlags = getAllFeatureFlags;
window.getAllEnvs = getAllEnvs;
window.saveLogs = async (path: string): Promise<void> => {
const memoryLogs = memoryLogger.getMemoryLogs();

try {
// Serializes ourself with `stringify` to avoid "object could not be cloned" errors from the electron IPC serializer.
const memoryLogsStr = JSON.stringify(memoryLogs, null, 2);
// Requests the main process to save logs in a file
await ipcRenderer.invoke(
"save-logs",
{
canceled: false,
filePath: path,
},
memoryLogsStr,
);
} catch (error) {
console.error("Error while requesting to save logs from the renderer process", error);
}
};

if (getEnv("MOCK")) {
window.mock = {
Expand Down
11 changes: 11 additions & 0 deletions apps/ledger-live-desktop/tests/utils/allureUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ export async function captureArtifacts(page: Page, testInfo: TestInfo) {
await testInfo.attach("Test Video", { body: videoData, contentType: "video/webm" });
}
}

const filePath = `tests/artifacts/${testInfo.title.replace(/[^a-zA-Z0-9]/g, " ")}.json`;

await page.evaluate(filePath => {
window.saveLogs(filePath);
}, filePath);

await testInfo.attach("Test logs", {
path: filePath,
contentType: "application/json",
});
}

0 comments on commit 5707a08

Please sign in to comment.