Repository navigation
Expand file tree
/
Copy pathinputs.test.ts
More file actions
76 lines (68 loc) · 2.39 KB
/
Copy pathinputs.test.ts
File metadata and controls
76 lines (68 loc) · 2.39 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { describe, expect, it } from "vite-plus/test";
import { parseAzureInputs, resolveProjectDirFromInputs } from "./inputs.js";
import { mkdtempSync, mkdirSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
describe("parseAzureInputs", () => {
it("maps SETUP_VP_* environment variables", () => {
const inputs = parseAzureInputs({
SETUP_VP_VERSION: "1.2.3",
SETUP_VP_WORKING_DIRECTORY: "apps/web",
SETUP_VP_RUN_INSTALL: "false",
SETUP_VP_SFW: "true",
SETUP_VP_NODE_MANAGER: "false",
SETUP_VP_PACKAGE_MANAGER: '{"pnpm":true,"bun":false}',
SETUP_VP_REGISTRY_URL: "https://registry.example/npm/",
SETUP_VP_SCOPE: "@acme",
SETUP_VP_CACHE: "true",
SETUP_VP_CACHE_DEPENDENCY_PATH: "pnpm-lock.yaml",
SYSTEM_DEFAULTWORKINGDIRECTORY: "/workspace",
});
expect(inputs).toEqual({
version: "1.2.3",
workingDirectory: "apps/web",
runInstall: "false",
sfw: true,
nodeManager: false,
packageManager: { pnpm: true, bun: false },
registryUrl: "https://registry.example/npm/",
scope: "@acme",
cache: true,
cacheDependencyPath: "pnpm-lock.yaml",
workspaceRoot: "/workspace",
});
});
it("accepts Azure's title-cased boolean serialization", () => {
const inputs = parseAzureInputs({
SETUP_VP_SFW: "True",
SETUP_VP_CACHE: "True",
});
expect(inputs.sfw).toBe(true);
expect(inputs.cache).toBe(true);
expect(parseAzureInputs({ SETUP_VP_PACKAGE_MANAGER: '""' }).packageManager).toBeUndefined();
});
});
describe("resolveProjectDirFromInputs", () => {
const tempDirs: string[] = [];
it("resolves workingDirectory against the Azure workspace root", () => {
const root = mkdtempSync(path.join(tmpdir(), "setup-vp-azure-"));
tempDirs.push(root);
const child = path.join(root, "apps", "web");
mkdirSync(child, { recursive: true });
const projectDir = resolveProjectDirFromInputs({
version: "latest",
workingDirectory: "apps/web",
runInstall: "true",
sfw: false,
nodeManager: undefined,
packageManager: undefined,
registryUrl: "",
scope: "",
cache: false,
cacheDependencyPath: "",
workspaceRoot: root,
});
expect(projectDir).toBe(child);
for (const dir of tempDirs.splice(0)) rmSync(dir, { recursive: true, force: true });
});
});