diff --git a/packages/obsidian-testing-framework/src/index.ts b/packages/obsidian-testing-framework/src/index.ts index d353d1a..fddb861 100644 --- a/packages/obsidian-testing-framework/src/index.ts +++ b/packages/obsidian-testing-framework/src/index.ts @@ -2,10 +2,8 @@ import { test as base } from "@playwright/test"; import { _electron as electron } from "playwright"; import { Fixtures } from "@playwright/test"; import path from "path"; -import { extractAll } from "asar"; import { ObsidianTestFixtures } from "./fixtures.js"; -import tmp from "tmp"; -import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs"; +import { existsSync } from "fs"; import { getApp, waitForIndexingComplete } from "./util.js"; export interface ObsidianTestingConfig { @@ -18,7 +16,7 @@ export function getExe(): string { process.env.LOCALAPPDATA!, "Obsidian", "Resources", - "obsidian.asar" + "app.asar" ); } if (process.platform == "darwin") { @@ -26,7 +24,7 @@ export function getExe(): string { } 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])) return path.join(possibleDirs[i], "resources", "obsidian.asar"); + if(existsSync(possibleDirs[i])) return path.join(possibleDirs[i], "resources", "app.asar"); } return "" } @@ -35,30 +33,11 @@ const obsidianTestFixtures: Fixtures = { electronApp: [ async ({ obsidian: { vault } }, run) => { process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true"; - let mainFile = path.join(tmp.tmpdir, "obsidian"); - let electronFile = path.join(tmp.tmpdir, "electron"); - const packageJsonFile = path.join(tmp.tmpdir, "obsidian", "package.json"); - try { - rmSync(mainFile, { recursive: true }); - rmSync(electronFile, { recursive: true }); - mkdirSync(electronFile); - mkdirSync(mainFile); - } catch (e) {} - extractAll(getExe(), mainFile); - extractAll(path.join(path.dirname(getExe()), "app.asar"), electronFile); - renameSync( - path.join(mainFile, "main.js"), - path.join(mainFile, "index.js") - ); - const packageJson = JSON.parse(readFileSync(packageJsonFile).toString()); - // packageJson.main = "app.js"; - writeFileSync(packageJsonFile, JSON.stringify(packageJson)); - + const electronApp = await electron.launch({ timeout: 10000, - cwd: mainFile, args: [ - path.join(path.dirname(getExe()), "app.asar"), + getExe(), !!vault && `obsidian://open?vault=${encodeURI(vault)}`, ].filter((a) => !!a) as string[], });