From 7a1ab0ceaff119ce8a53624342877383bf1fe2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Wed, 23 Oct 2024 16:52:45 -0400 Subject: [PATCH] maybe? --- .../obsidian-testing-framework/src/index.ts | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/packages/obsidian-testing-framework/src/index.ts b/packages/obsidian-testing-framework/src/index.ts index 11f8b15..3058cd8 100644 --- a/packages/obsidian-testing-framework/src/index.ts +++ b/packages/obsidian-testing-framework/src/index.ts @@ -5,7 +5,7 @@ import path from "path"; import { ObsidianTestFixtures } from "./fixtures.js"; import { existsSync } from "fs"; import { getApp, waitForIndexingComplete } from "./util.js"; -import {execSync} from "child_process"; +import { execSync } from "child_process"; import { Page } from "playwright"; export interface ObsidianTestingConfig { @@ -24,59 +24,68 @@ export function getExe(): string { if (process.platform == "darwin") { throw new Error("use a non-toy operating system, dumbass"); } - const possibleDirs = ["/opt/Obsidian", "/usr/lib/Obsidian", "/opt/obsidian", "/usr/lib/obsidian", "/var/lib/flatpak/app/md.obsidian.Obsidian/current/active/files", "/snap/obsidian/current"]; - for(let i = 0; i < possibleDirs.length; i++) { - if(existsSync(possibleDirs[i])) { + const possibleDirs = [ + "/opt/Obsidian", + "/usr/lib/Obsidian", + "/opt/obsidian", + "/usr/lib/obsidian", + "/var/lib/flatpak/app/md.obsidian.Obsidian/current/active/files", + "/snap/obsidian/current", + ]; + for (let i = 0; i < possibleDirs.length; i++) { + if (existsSync(possibleDirs[i])) { console.log(execSync(`ls -l ${possibleDirs[i]}`).toString()); return path.join(possibleDirs[i], "resources", "app.asar"); } } - return "" + return ""; } async function selectNewVault(page: Page, vaultPath: string) { try { - let btn = await page.locator("button", {hasText: "Open"}); + let btn = await page.locator("button", { hasText: "Open" }); const promise = page.waitForEvent("filechooser"); await btn.click(); const chooser = await promise; await chooser.setFiles(vaultPath); - } catch(e) { - console.debug("congratulations, you don't have to choose a vault manually!") + } catch (e) { + console.debug( + "congratulations, you don't have to choose a vault manually!" + ); } } const obsidianTestFixtures: Fixtures = { electronApp: [ - async ({ obsidian: { vault } }, run) => { + async ({}, run) => { process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true"; - console.log("asar located at:", getExe()) + console.log("asar located at:", getExe()); const electronApp = await electron.launch({ timeout: 60000, - args: [ - getExe(), - !!vault && `obsidian://open?path=${encodeURIComponent(vault)}`, - ].filter((a) => !!a) as string[], + args: [getExe()].filter((a) => !!a) as string[], }); electronApp.on("console", async (msg) => { console.log( ...(await Promise.all(msg.args().map((a) => a.jsonValue()))) ); }); - + await run(electronApp); await electronApp.close(); }, { timeout: 60000 }, ], page: [ - async ({ electronApp, obsidian: {vault} }, run) => { + async ({ electronApp, obsidian: { vault } }, run) => { const windows = electronApp.windows(); console.log("windows", windows); - const page = windows.last()!; - await page.waitForEvent("load") + let page = windows.last()!; + await page.waitForEvent("load"); await page.waitForLoadState("domcontentloaded"); await selectNewVault(page, vault!); + page = electronApp.windows().last()!; + await page.waitForEvent("load"); + await page.waitForLoadState("domcontentloaded"); await waitForIndexingComplete(await getApp(page)); page.on("console", async (msg) => { console.log(