Repository navigation
Expand file tree
/
Copy pathindex.test.ts
More file actions
202 lines (192 loc) · 6.27 KB
/
Copy pathindex.test.ts
File metadata and controls
202 lines (192 loc) · 6.27 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { describe, expect, it, vi } from "vite-plus/test";
import { runFinalize, runPrepare } from "./index.js";
describe("Azure lifecycle", () => {
it("passes the Node selector to bootstrap and activates its exact result", async () => {
const run = vi.fn();
const installVitePlus = vi.fn(async () => "22.23.1");
await runPrepare(
{
SETUP_VP_VERSION: "1.3.0",
SETUP_VP_NODE_VERSION: "22",
SYSTEM_DEFAULTWORKINGDIRECTORY: process.cwd(),
},
{
installVitePlus,
prepareCacheMetadata: () => ({ ready: false }),
configureAuth: () => undefined,
setupSfw: async () => ({ executable: "vp", sfw: false }),
parseRunInstall: () => [],
runInstall: () => undefined,
getCommandOutput: () => "vp v1.3.0",
run,
parseInstalledVpVersion: () => "1.3.0",
prependPath: () => undefined,
setVariable: () => undefined,
logWarning: () => undefined,
logInfo: () => undefined,
},
);
expect(installVitePlus).toHaveBeenCalledWith(
"1.3.0",
expect.objectContaining({
projectDir: process.cwd(),
nodeVersion: "22",
}),
);
expect(run).toHaveBeenCalledWith("vp", ["env", "use", "22.23.1"], { cwd: process.cwd() });
});
it("runs prepare in install → cache order", async () => {
const calls: string[] = [];
await runPrepare(
{
SETUP_VP_VERSION: "latest",
SETUP_VP_CACHE: "true",
SYSTEM_DEFAULTWORKINGDIRECTORY: process.cwd(),
},
{
installVitePlus: async () => {
calls.push("install");
},
prepareCacheMetadata: () => {
calls.push("cache");
return { ready: false };
},
configureAuth: () => undefined,
setupSfw: async () => ({ executable: "vp", sfw: false }),
parseRunInstall: () => [],
runInstall: () => undefined,
getCommandOutput: () => "vp v0.2.2",
run: () => undefined,
parseInstalledVpVersion: () => "0.2.2",
prependPath: () => undefined,
setVariable: () => undefined,
logWarning: () => undefined,
logInfo: () => undefined,
},
);
expect(calls).toEqual(["install", "cache"]);
});
it("runs finalize in auth → sfw → install → version order", async () => {
const calls: string[] = [];
await runFinalize(
{
SETUP_VP_RUN_INSTALL: "true",
SYSTEM_DEFAULTWORKINGDIRECTORY: process.cwd(),
},
{
installVitePlus: async () => undefined,
prepareCacheMetadata: () => ({ ready: false }),
configureAuth: () => {
calls.push("auth");
return undefined;
},
setupSfw: async () => {
calls.push("sfw");
return { executable: "vp", sfw: false };
},
parseRunInstall: () => {
calls.push("parse");
return [{}];
},
runInstall: () => {
calls.push("install");
},
getCommandOutput: () => {
calls.push("version");
return "vp v0.2.2";
},
run: () => undefined,
parseInstalledVpVersion: () => "0.2.2",
prependPath: () => undefined,
setVariable: () => undefined,
logWarning: () => undefined,
logInfo: () => undefined,
},
);
expect(calls).toEqual(["auth", "parse", "sfw", "install", "version"]);
});
it.each(["0.3.0", "0.3.1"])("prepare disables only Node.js on Vite+ %s", async (version) => {
const run = vi.fn();
await runPrepare(
{
SETUP_VP_VERSION: "latest",
SETUP_VP_NODE_MANAGER: "false",
SETUP_VP_PACKAGE_MANAGER: version === "0.3.1" ? '{"pnpm":true,"bun":false}' : "",
SYSTEM_DEFAULTWORKINGDIRECTORY: process.cwd(),
},
{
installVitePlus: async () => undefined,
prepareCacheMetadata: () => ({ ready: false }),
configureAuth: () => undefined,
setupSfw: async () => ({ executable: "vp", sfw: false }),
parseRunInstall: () => [],
runInstall: () => undefined,
getCommandOutput: () => `vp v${version}`,
run,
parseInstalledVpVersion: () => "0.2.2",
prependPath: () => undefined,
setVariable: () => undefined,
logWarning: () => undefined,
logInfo: () => undefined,
},
);
expect(run).toHaveBeenCalledWith(
"vp",
version === "0.3.0" ? ["env", "off"] : ["env", "off", "node"],
);
if (version === "0.3.1") {
expect(run).not.toHaveBeenCalledWith("vp", ["env", "on", "pm"]);
expect(run).toHaveBeenCalledWith("vp", ["env", "off", "bun"]);
}
});
it("prepare leaves the node manager alone when nodeManager is unset", async () => {
const run = vi.fn();
await runPrepare(
{
SETUP_VP_VERSION: "latest",
SYSTEM_DEFAULTWORKINGDIRECTORY: process.cwd(),
},
{
installVitePlus: async () => undefined,
prepareCacheMetadata: () => ({ ready: false }),
configureAuth: () => undefined,
setupSfw: async () => ({ executable: "vp", sfw: false }),
parseRunInstall: () => [],
runInstall: () => undefined,
getCommandOutput: () => "vp v0.2.2",
run,
parseInstalledVpVersion: () => "0.2.2",
prependPath: () => undefined,
setVariable: () => undefined,
logWarning: () => undefined,
logInfo: () => undefined,
},
);
expect(run).not.toHaveBeenCalled();
});
it("skips install when runInstall is false", async () => {
const runInstall = vi.fn();
await runFinalize(
{
SETUP_VP_RUN_INSTALL: "false",
SYSTEM_DEFAULTWORKINGDIRECTORY: process.cwd(),
},
{
installVitePlus: async () => undefined,
prepareCacheMetadata: () => ({ ready: false }),
configureAuth: () => undefined,
setupSfw: async () => ({ executable: "vp", sfw: false }),
parseRunInstall: () => [],
runInstall,
getCommandOutput: () => "vp v0.2.2",
run: () => undefined,
parseInstalledVpVersion: () => "0.2.2",
prependPath: () => undefined,
setVariable: () => undefined,
logWarning: () => undefined,
logInfo: () => undefined,
},
);
expect(runInstall).not.toHaveBeenCalled();
});
});