obsidian-testing-framework 0.2.5 → 0.3.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/fixtures.d.ts +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +44 -22
- package/package.json +2 -1
package/lib/fixtures.d.ts
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export interface ObsidianTestingConfig {
|
|
2
2
|
vault?: string;
|
|
3
3
|
obsidianPath?: string;
|
|
4
|
-
|
|
4
|
+
concurrent?: false | "copy" | "symlink";
|
|
5
5
|
}
|
|
6
6
|
export declare const test: import("vitest").TestAPI<{
|
|
7
7
|
page: import("playwright-core").Page;
|
|
8
8
|
obsidian: ObsidianTestingConfig;
|
|
9
9
|
electronApp: import("playwright-core").ElectronApplication;
|
|
10
10
|
appHandle: import("playwright-core").JSHandle<import("obsidian").App>;
|
|
11
|
+
vaultPoolDir: string;
|
|
11
12
|
}>;
|
package/lib/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { test as base, inject } from "vitest";
|
|
2
2
|
import { _electron as electron } from "playwright";
|
|
3
3
|
import path from "path";
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
4
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmdirSync, writeFileSync, } from "fs";
|
|
5
5
|
import { pageUtils, waitForIndexingComplete } from "./util.js";
|
|
6
6
|
import { randomBytes } from "crypto";
|
|
7
7
|
import { addConsoleListener, checkToy, getExe } from "./internal-util.js";
|
|
8
|
-
import
|
|
9
|
-
function
|
|
10
|
-
const vaultHash = randomBytes(8).toString("hex").toLocaleLowerCase();
|
|
8
|
+
import symlinkDir from "symlink-dir";
|
|
9
|
+
function findConfig() {
|
|
11
10
|
let configLocation;
|
|
12
|
-
console.log("vault is", vault, existsSync(vault));
|
|
13
11
|
checkToy();
|
|
14
12
|
if (process.platform == "win32") {
|
|
15
13
|
configLocation = path.join(`${process.env.APPDATA}`, "Obsidian");
|
|
@@ -22,13 +20,26 @@ function generateVaultConfig(vault) {
|
|
|
22
20
|
catch (e) { }
|
|
23
21
|
}
|
|
24
22
|
const obsidianConfigFile = path.join(configLocation, "obsidian.json");
|
|
23
|
+
return obsidianConfigFile;
|
|
24
|
+
}
|
|
25
|
+
function generateVaultConfig(vault, concurrent, vaultPoolDir) {
|
|
26
|
+
const vaultHash = randomBytes(8).toString("hex").toLocaleLowerCase();
|
|
27
|
+
let configLocation;
|
|
28
|
+
console.log("vault is", vault, existsSync(vault));
|
|
29
|
+
const obsidianConfigFile = findConfig();
|
|
25
30
|
if (!existsSync(obsidianConfigFile)) {
|
|
26
31
|
writeFileSync(obsidianConfigFile, JSON.stringify({ vaults: {} }));
|
|
27
32
|
}
|
|
28
33
|
const json = JSON.parse(readFileSync(obsidianConfigFile).toString());
|
|
34
|
+
if (concurrent === "symlink") {
|
|
35
|
+
symlinkDir.sync(vault, path.join(vaultPoolDir, vaultHash));
|
|
36
|
+
}
|
|
37
|
+
else if (concurrent === "copy") {
|
|
38
|
+
cpSync(vault, path.join(vaultPoolDir, vaultHash), { recursive: true });
|
|
39
|
+
}
|
|
29
40
|
if (!Object.values(json.vaults).some((a) => a.path === vault)) {
|
|
30
41
|
json.vaults[vaultHash] = {
|
|
31
|
-
path: vault,
|
|
42
|
+
path: concurrent ? path.join(vaultPoolDir, vaultHash) : vault,
|
|
32
43
|
ts: Date.now(),
|
|
33
44
|
};
|
|
34
45
|
writeFileSync(obsidianConfigFile, JSON.stringify(json));
|
|
@@ -41,35 +52,46 @@ function generateVaultConfig(vault) {
|
|
|
41
52
|
}
|
|
42
53
|
// @ts-ignore some error about a string type now having `undefined` as part of it's union
|
|
43
54
|
export const test = base.extend({
|
|
44
|
-
|
|
55
|
+
vaultPoolDir: [
|
|
45
56
|
async ({}, run) => {
|
|
57
|
+
const concurrent = inject("concurrent") ?? "copy";
|
|
58
|
+
if (!concurrent) {
|
|
59
|
+
await run("");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const prefix = "obsidian-testing-framework-vault-pool-";
|
|
63
|
+
const vaultPoolDir = mkdtempSync(prefix);
|
|
64
|
+
await run(vaultPoolDir);
|
|
65
|
+
rmdirSync(vaultPoolDir, { recursive: true });
|
|
66
|
+
const configFile = findConfig();
|
|
67
|
+
const json = JSON.parse(readFileSync(configFile).toString());
|
|
68
|
+
const filtered = Object.fromEntries(Object.entries(json.vaults).filter(([, v]) => !v.path.includes(prefix)));
|
|
69
|
+
writeFileSync(configFile, JSON.stringify({ vaults: filtered }));
|
|
70
|
+
},
|
|
71
|
+
{ scope: "worker", auto: true },
|
|
72
|
+
],
|
|
73
|
+
electronApp: [
|
|
74
|
+
async ({ vaultPoolDir }, run) => {
|
|
46
75
|
const obsidianPath = inject("obsidianPath") ?? undefined;
|
|
47
|
-
const experimentalUseSingleton = inject("experimentalUseSingleton") ?? false;
|
|
48
76
|
const vault = inject("vault");
|
|
77
|
+
const concurrent = inject("concurrent") ?? "copy";
|
|
49
78
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "true";
|
|
50
|
-
console.log({ obsidianPath, experimentalUseSingleton });
|
|
51
79
|
console.log("asar located at:", getExe(obsidianPath));
|
|
52
80
|
let uriArg = "";
|
|
53
81
|
if (vault) {
|
|
54
|
-
let id = generateVaultConfig(vault);
|
|
82
|
+
let id = generateVaultConfig(vault, concurrent, vaultPoolDir);
|
|
55
83
|
if (!!id) {
|
|
56
84
|
uriArg = `obsidian://open?vault=${encodeURIComponent(id)}`;
|
|
57
85
|
}
|
|
58
86
|
}
|
|
59
|
-
const electronApp =
|
|
60
|
-
|
|
61
|
-
:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
if (!experimentalUseSingleton) {
|
|
66
|
-
addConsoleListener(electronApp);
|
|
67
|
-
}
|
|
87
|
+
const electronApp = await electron.launch({
|
|
88
|
+
timeout: 60000,
|
|
89
|
+
args: [getExe(obsidianPath), uriArg].filter((a) => !!a),
|
|
90
|
+
});
|
|
91
|
+
addConsoleListener(electronApp);
|
|
68
92
|
await electronApp.firstWindow();
|
|
69
93
|
await run(electronApp);
|
|
70
|
-
|
|
71
|
-
await electronApp.close();
|
|
72
|
-
}
|
|
94
|
+
await electronApp.close();
|
|
73
95
|
},
|
|
74
96
|
{ auto: true },
|
|
75
97
|
],
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"electron": "^33.0.2",
|
|
13
13
|
"obsidian": "latest",
|
|
14
14
|
"playwright": "^1.58.2",
|
|
15
|
+
"symlink-dir": "^9.0.0",
|
|
15
16
|
"tmp": "^0.2.3",
|
|
16
17
|
"typescript": "^5.6.3",
|
|
17
18
|
"xvfb-maybe": "^0.2.1"
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
".": "./lib/index.js"
|
|
27
28
|
},
|
|
28
29
|
"readme": "",
|
|
29
|
-
"version": "0.
|
|
30
|
+
"version": "0.3.0",
|
|
30
31
|
"main": "./lib/index.js",
|
|
31
32
|
"typings": "./lib/index.d.ts",
|
|
32
33
|
"repository": {
|