Repository navigation
Expand file tree
/
Copy pathe2e-instance.mjs
More file actions
57 lines (53 loc) · 1.82 KB
/
Copy pathe2e-instance.mjs
File metadata and controls
57 lines (53 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { execFile, spawn } from "node:child_process";
import { once } from "node:events";
import { open } from "node:fs/promises";
import { promisify } from "node:util";
import { ensureObsidianInstance, launchObsidianInstance } from "obsidian-e2e/runner";
export const FIXTURE_HOST = "podnotes.test";
export const SUPERCAST_FIXTURE_HOST = "priv3.supercast.com";
export const FIXTURE_RESOLVER_RULES = `MAP ${FIXTURE_HOST} 127.0.0.1,MAP ${SUPERCAST_FIXTURE_HOST} 127.0.0.1`;
const resolverFlag = `--host-resolver-rules=${FIXTURE_RESOLVER_RULES}`;
const exec = promisify(execFile);
/** @type {import("obsidian-e2e/runner").SpawnDetachedFn} */
const spawnLogged = async (file, args, { env, cwd, logPath }) => {
const log = await open(logPath, "a", 0o600);
try {
const child = spawn(file, [...args], {
env,
cwd,
detached: true,
stdio: ["ignore", log.fd, log.fd],
});
await once(child, "spawn");
child.unref();
} finally {
await log.close();
}
};
/**
* @param {import("obsidian-e2e/runner").LaunchTarget} target
* @param {import("obsidian-e2e/runner").ObsidianExecDependencies} [deps]
*/
export function launchPodNotesInstance(target, deps = {}) {
return launchObsidianInstance(target, {
...deps,
execFile: (file, args, options) =>
(deps.execFile ?? exec)(file, [...args, resolverFlag], {
encoding: "utf8",
...options,
}),
spawnDetached: (file, args, options) =>
(deps.spawnDetached ?? spawnLogged)(file, [...args, resolverFlag], options),
});
}
/** @returns {import("obsidian-e2e/runner").CliDependencies} */
export function podNotesRunnerDependencies() {
return {
reapOrphanedInstances: async () => ({ reaped: [], scanned: 0 }),
ensureObsidianInstance: (options, config, deps) =>
ensureObsidianInstance(options, config, {
...deps,
launchObsidianInstance: launchPodNotesInstance,
}),
};
}