add ability to provide custom obsidian path to test harness

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2026-01-02 15:21:25 -05:00
parent b1d0453723
commit de4c5d0b2c
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -1,6 +1,5 @@
import { test as base } from "@playwright/test";
import { test as base, inject } from "vitest";
import { _electron as electron } from "playwright";
import { Fixtures } from "@playwright/test";
import path from "path";
import { ObsidianTestFixtures } from "./fixtures.js";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
@ -9,17 +8,27 @@ import { randomBytes } from "crypto";
export interface ObsidianTestingConfig {
vault?: string;
obsidianPath?: string;
}
export function getExe(): string {
export function getExe(obsidianPath?: string): string {
checkToy();
if (process.platform == "win32") {
return path.join(
const p = path.join(
process.env.LOCALAPPDATA!,
"Obsidian",
"Resources",
"app.asar"
);
if (existsSync(p)) {
return p;
}
if (obsidianPath) {
const p = path.join(obsidianPath, "Resources", "app.asar");
if (existsSync(p)) {
return p;
}
}
}
const possibleDirs = [
@ -85,11 +94,13 @@ function generateVaultConfig(vault: string) {
}
}
const obsidianTestFixtures: Fixtures<ObsidianTestFixtures> = {
// @ts-ignore some error about a string type now having `undefined` as part of it's union
export const test = base.extend<ObsidianTestFixtures>({
electronApp: [
async ({ obsidian: { vault } }, run) => {
async ({obsidian: {obsidianPath}}, run) => {
const vault = <string> inject("vault")
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
console.log("asar located at:", getExe());
console.log("asar located at:", getExe(obsidianPath));
let uriArg = "";
if (vault) {
let id = generateVaultConfig(vault);
@ -100,18 +111,17 @@ const obsidianTestFixtures: Fixtures<ObsidianTestFixtures> = {
const electronApp = await electron.launch({
timeout: 60000,
args: [getExe(), uriArg].filter((a) => !!a) as string[],
args: [getExe(obsidianPath), uriArg].filter((a) => !!a) as string[],
});
electronApp.on("console", async (msg) => {
console.log(
...(await Promise.all(msg.args().map((a) => a.jsonValue())))
);
});
await electronApp.waitForEvent("window");
await electronApp.firstWindow();
await run(electronApp);
await electronApp.close();
},
{ timeout: 60000 },
}, {auto: true}
],
page: [
async ({ electronApp }, run) => {
@ -137,10 +147,6 @@ const obsidianTestFixtures: Fixtures<ObsidianTestFixtures> = {
);
});
await run(page);
},
{ timeout: 60000 },
}, {auto: true}
],
obsidian: [{}, { option: true }],
};
// @ts-ignore some error about a string type now having `undefined` as part of it's union
export const test = base.extend<ObsidianTestFixtures>(obsidianTestFixtures);
});