obsidian-testing-framework 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/electron-singleton.d.ts +2 -0
- package/lib/electron-singleton.js +17 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +21 -45
- package/lib/internal-util.d.ts +4 -0
- package/lib/internal-util.js +39 -0
- package/package.json +12 -5
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { _electron as electron } from "playwright";
|
|
2
|
+
import { addConsoleListener } from "./internal-util";
|
|
3
|
+
const singleton = {
|
|
4
|
+
app: null,
|
|
5
|
+
};
|
|
6
|
+
export async function getOrCreateApp(obsidianPath, uriArg) {
|
|
7
|
+
if (singleton.app) {
|
|
8
|
+
return singleton.app;
|
|
9
|
+
}
|
|
10
|
+
const app = await electron.launch({
|
|
11
|
+
timeout: 60000,
|
|
12
|
+
args: [obsidianPath, uriArg].filter((a) => !!a),
|
|
13
|
+
});
|
|
14
|
+
addConsoleListener(app);
|
|
15
|
+
singleton.app = app;
|
|
16
|
+
return app;
|
|
17
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export interface ObsidianTestingConfig {
|
|
2
2
|
vault?: string;
|
|
3
3
|
obsidianPath?: string;
|
|
4
|
+
experimentalUseSingleton?: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare function getExe(obsidianPath?: string): string;
|
|
6
6
|
export declare const test: import("vitest").TestAPI<{
|
|
7
7
|
page: import("playwright-core").Page;
|
|
8
8
|
obsidian: ObsidianTestingConfig;
|
package/lib/index.js
CHANGED
|
@@ -4,38 +4,8 @@ import path from "path";
|
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
5
5
|
import { pageUtils, waitForIndexingComplete } from "./util.js";
|
|
6
6
|
import { randomBytes } from "crypto";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (obsidianPath) {
|
|
10
|
-
return path.join(obsidianPath, "Resources", "app.asar");
|
|
11
|
-
}
|
|
12
|
-
if (process.platform == "win32") {
|
|
13
|
-
const p = path.join(process.env.LOCALAPPDATA, "Obsidian", "Resources", "app.asar");
|
|
14
|
-
if (existsSync(p)) {
|
|
15
|
-
return p;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
const possibleDirs = [
|
|
19
|
-
"/opt/Obsidian",
|
|
20
|
-
"/usr/lib/Obsidian",
|
|
21
|
-
"/opt/obsidian",
|
|
22
|
-
"/usr/lib/obsidian",
|
|
23
|
-
"/var/lib/flatpak/app/md.obsidian.Obsidian/current/active/files",
|
|
24
|
-
"/snap/obsidian/current",
|
|
25
|
-
];
|
|
26
|
-
for (let i = 0; i < possibleDirs.length; i++) {
|
|
27
|
-
if (existsSync(possibleDirs[i])) {
|
|
28
|
-
// console.log(execSync(`ls -l ${possibleDirs[i]}`).toString());
|
|
29
|
-
return path.join(possibleDirs[i], "resources", "app.asar");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return "";
|
|
33
|
-
}
|
|
34
|
-
function checkToy() {
|
|
35
|
-
if (process.platform == "darwin") {
|
|
36
|
-
throw new Error("use a non-toy operating system, dumbass");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
7
|
+
import { addConsoleListener, checkToy, getExe } from "./internal-util.js";
|
|
8
|
+
import { getOrCreateApp } from "./electron-singleton.js";
|
|
39
9
|
function generateVaultConfig(vault) {
|
|
40
10
|
const vaultHash = randomBytes(8).toString("hex").toLocaleLowerCase();
|
|
41
11
|
let configLocation;
|
|
@@ -66,13 +36,15 @@ function generateVaultConfig(vault) {
|
|
|
66
36
|
return vaultHash;
|
|
67
37
|
}
|
|
68
38
|
else {
|
|
69
|
-
return Object.entries(json.vaults).find(a => a[1].path === vault)[0];
|
|
39
|
+
return Object.entries(json.vaults).find((a) => a[1].path === vault)[0];
|
|
70
40
|
}
|
|
71
41
|
}
|
|
72
42
|
// @ts-ignore some error about a string type now having `undefined` as part of it's union
|
|
73
43
|
export const test = base.extend({
|
|
74
44
|
electronApp: [
|
|
75
|
-
async ({ obsidian
|
|
45
|
+
async ({ obsidian }, run) => {
|
|
46
|
+
console.log("obsidian", obsidian);
|
|
47
|
+
const { obsidianPath = undefined, experimentalUseSingleton = false } = obsidian ?? {};
|
|
76
48
|
const vault = inject("vault");
|
|
77
49
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
|
|
78
50
|
console.log("asar located at:", getExe(obsidianPath));
|
|
@@ -83,17 +55,20 @@ export const test = base.extend({
|
|
|
83
55
|
uriArg = `obsidian://open?vault=${encodeURIComponent(id)}`;
|
|
84
56
|
}
|
|
85
57
|
}
|
|
86
|
-
const electronApp =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
58
|
+
const electronApp = experimentalUseSingleton
|
|
59
|
+
? await getOrCreateApp(getExe(obsidianPath), !!uriArg ? uriArg : undefined)
|
|
60
|
+
: await electron.launch({
|
|
61
|
+
timeout: 60000,
|
|
62
|
+
args: [getExe(obsidianPath), uriArg].filter((a) => !!a),
|
|
63
|
+
});
|
|
64
|
+
addConsoleListener(electronApp);
|
|
93
65
|
await electronApp.firstWindow();
|
|
94
66
|
await run(electronApp);
|
|
95
|
-
|
|
96
|
-
|
|
67
|
+
if (!experimentalUseSingleton) {
|
|
68
|
+
await electronApp.close();
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{ auto: true },
|
|
97
72
|
],
|
|
98
73
|
page: [
|
|
99
74
|
async ({ electronApp }, run) => {
|
|
@@ -110,7 +85,7 @@ export const test = base.extend({
|
|
|
110
85
|
for (let fn of Object.entries(pageUtils)) {
|
|
111
86
|
await page.exposeFunction(fn[0], fn[1]);
|
|
112
87
|
}
|
|
113
|
-
page.on("pageerror", exc => {
|
|
88
|
+
page.on("pageerror", (exc) => {
|
|
114
89
|
console.error("EXCEPTION");
|
|
115
90
|
console.error(exc);
|
|
116
91
|
});
|
|
@@ -118,6 +93,7 @@ export const test = base.extend({
|
|
|
118
93
|
console.log(...(await Promise.all(msg.args().map((a) => a.jsonValue()))));
|
|
119
94
|
});
|
|
120
95
|
await run(page);
|
|
121
|
-
},
|
|
96
|
+
},
|
|
97
|
+
{ auto: true },
|
|
122
98
|
],
|
|
123
99
|
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
export function checkToy() {
|
|
4
|
+
if (process.platform == "darwin") {
|
|
5
|
+
throw new Error("use a non-toy operating system, dumbass");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function getExe(obsidianPath) {
|
|
9
|
+
checkToy();
|
|
10
|
+
if (obsidianPath) {
|
|
11
|
+
return path.join(obsidianPath, "Resources", "app.asar");
|
|
12
|
+
}
|
|
13
|
+
if (process.platform == "win32") {
|
|
14
|
+
const p = path.join(process.env.LOCALAPPDATA, "Obsidian", "Resources", "app.asar");
|
|
15
|
+
if (existsSync(p)) {
|
|
16
|
+
return p;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const possibleDirs = [
|
|
20
|
+
"/opt/Obsidian",
|
|
21
|
+
"/usr/lib/Obsidian",
|
|
22
|
+
"/opt/obsidian",
|
|
23
|
+
"/usr/lib/obsidian",
|
|
24
|
+
"/var/lib/flatpak/app/md.obsidian.Obsidian/current/active/files",
|
|
25
|
+
"/snap/obsidian/current",
|
|
26
|
+
];
|
|
27
|
+
for (let i = 0; i < possibleDirs.length; i++) {
|
|
28
|
+
if (existsSync(possibleDirs[i])) {
|
|
29
|
+
// console.log(execSync(`ls -l ${possibleDirs[i]}`).toString());
|
|
30
|
+
return path.join(possibleDirs[i], "resources", "app.asar");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
export function addConsoleListener(app) {
|
|
36
|
+
app.on("console", async (msg) => {
|
|
37
|
+
console.log(...(await Promise.all(msg.args().map((a) => a.jsonValue()))));
|
|
38
|
+
});
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "obsidian-testing-framework",
|
|
3
3
|
"packageManager": "yarn@4.5.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"dependencies": {
|
|
5
6
|
"@codemirror/language": "https://github.com/lishid/cm-language",
|
|
6
7
|
"@codemirror/state": "^6.0.1",
|
|
7
8
|
"@codemirror/view": "^6.0.1",
|
|
8
|
-
"@playwright/test": "^1.
|
|
9
|
+
"@playwright/test": "^1.58.2",
|
|
9
10
|
"asar": "^3.2.0",
|
|
10
11
|
"electron": "^33.0.2",
|
|
11
12
|
"obsidian": "latest",
|
|
12
|
-
"playwright": "^1.
|
|
13
|
+
"playwright": "^1.58.2",
|
|
13
14
|
"tmp": "^0.2.3",
|
|
14
15
|
"typescript": "^5.6.3",
|
|
15
16
|
"xvfb-maybe": "^0.2.1"
|
|
@@ -18,8 +19,13 @@
|
|
|
18
19
|
"./lib",
|
|
19
20
|
"../../README.md"
|
|
20
21
|
],
|
|
22
|
+
"exports": {
|
|
23
|
+
"./fixture": "./lib/fixtures.js",
|
|
24
|
+
"./util": "./lib/util.js",
|
|
25
|
+
".": "./lib/index.js"
|
|
26
|
+
},
|
|
21
27
|
"readme": "",
|
|
22
|
-
"version": "0.
|
|
28
|
+
"version": "0.2.0",
|
|
23
29
|
"main": "./lib/index.js",
|
|
24
30
|
"typings": "./lib/index.d.ts",
|
|
25
31
|
"repository": {
|
|
@@ -29,11 +35,12 @@
|
|
|
29
35
|
"scripts": {
|
|
30
36
|
"build": "tsc",
|
|
31
37
|
"lint": "tslint -c tslint.json src/**/*.ts",
|
|
32
|
-
"prepublishOnly": "pwsh -command 'rm README.md; cp ../../README.md . && rimraf lib && npm run build'"
|
|
38
|
+
"prepublishOnly": "pwsh -command 'rm README.md; cp ../../README.md . && rimraf lib && npm run build'",
|
|
39
|
+
"prepare": "yarn run build"
|
|
33
40
|
},
|
|
34
41
|
"devDependencies": {
|
|
35
42
|
"@types/tmp": "^0",
|
|
36
43
|
"rimraf": "^6.0.1",
|
|
37
|
-
"vitest": "^
|
|
44
|
+
"vitest": "^4.0.18"
|
|
38
45
|
}
|
|
39
46
|
}
|