Compare commits
2 Commits
b1d0453723
...
a2bf146f99
| Author | SHA1 | Date | |
|---|---|---|---|
| a2bf146f99 | |||
| de4c5d0b2c |
@ -19,23 +19,13 @@
|
||||
"../../README.md"
|
||||
],
|
||||
"readme": "",
|
||||
"version": "0.0.4",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./utils": {
|
||||
"types": "./lib/util.d.ts",
|
||||
"default": "./lib/util.js"
|
||||
},
|
||||
"./fixture": {
|
||||
"types": "./lib/fixtures.d.ts",
|
||||
"default": "./lib/fixtures.js"
|
||||
}
|
||||
},
|
||||
"version": "0.1.6",
|
||||
"main": "./lib/index.js",
|
||||
"typings": "./lib/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.tablet.sh/tablet/obsidian-testing-framework"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"lint": "tslint -c tslint.json src/**/*.ts",
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user