-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathspawn-env.test.ts
More file actions
61 lines (57 loc) · 2.08 KB
/
Copy pathspawn-env.test.ts
File metadata and controls
61 lines (57 loc) · 2.08 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
58
59
60
61
import { mkdtempSync, symlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { delimiter, join } from "node:path";
import { buildNodeShimScript } from "@posthog/shared/node-shim";
import { describe, expect, it } from "vitest";
import { stripElectronNodeShimFromPath } from "./spawn-env";
const EXEC_PATH = "/fake/Electron.app/Contents/MacOS/Electron";
function makeDir(
kind:
| "symlink-shim"
| "wrapper-shim"
| "real-node-wrapper-shim"
| "foreign-wrapper"
| "other-symlink"
| "real-node"
| "empty",
) {
const dir = mkdtempSync(join(tmpdir(), "spawn-env-"));
const node = join(dir, "node");
if (kind === "symlink-shim") symlinkSync(EXEC_PATH, node);
if (kind === "wrapper-shim")
writeFileSync(node, buildNodeShimScript(EXEC_PATH));
if (kind === "real-node-wrapper-shim")
writeFileSync(node, buildNodeShimScript(EXEC_PATH, "/usr/local/bin/node"));
if (kind === "foreign-wrapper")
writeFileSync(node, buildNodeShimScript("/some/other/app"));
if (kind === "other-symlink") symlinkSync("/usr/bin/true", node);
if (kind === "real-node") writeFileSync(node, "");
return dir;
}
describe("stripElectronNodeShimFromPath", () => {
it("removes only dirs whose node aliases the executable", () => {
const symlinkShim = makeDir("symlink-shim");
const wrapperShim = makeDir("wrapper-shim");
const realNodeWrapperShim = makeDir("real-node-wrapper-shim");
const foreign = makeDir("foreign-wrapper");
const other = makeDir("other-symlink");
const real = makeDir("real-node");
const empty = makeDir("empty");
const input = [
symlinkShim,
wrapperShim,
realNodeWrapperShim,
foreign,
other,
real,
empty,
].join(delimiter);
expect(stripElectronNodeShimFromPath(input, EXEC_PATH)).toBe(
[foreign, other, real, empty].join(delimiter),
);
});
it("passes through undefined and empty values", () => {
expect(stripElectronNodeShimFromPath(undefined, EXEC_PATH)).toBeUndefined();
expect(stripElectronNodeShimFromPath("", EXEC_PATH)).toBe("");
});
});