Skip to content

Commit 2400910

Browse files
cjk7989Jikun
andauthored
fix: correct the default node version (16 to 22) (#996)
* bug fix * added UT --------- Co-authored-by: Jikun <jikunchen@microsoft.com>
1 parent 8214cf9 commit 2400910

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/cli/commands/deploy/deploy.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import * as deployClientModule from "../../../core/deploy-client.js";
99
import { deploy } from "./deploy.js";
1010
import * as loginModule from "../login/login.js";
1111
import { loadPackageJson } from "../../../core/utils/json.js";
12+
import { DEFAULT_VERSION, SUPPORTED_VERSIONS } from "../../../core/constants.js";
13+
import * as optionsModule from "../../../core/utils/options.js";
1214

1315
const pkg = loadPackageJson();
1416

@@ -269,5 +271,41 @@ describe("deploy", () => {
269271
expect(logger.error).toHaveBeenCalledWith("The deployment binary exited with code 1.");
270272
expect(exitSpy).not.toHaveBeenCalled();
271273
});
274+
275+
it("should pass correct FUNCTION_LANGUAGE_VERSION for python when only apiLanguage is specified", async () => {
276+
vi.spyOn(optionsModule, "isUserOrConfigOption").mockImplementation((option) => option === "apiLanguage");
277+
278+
await deploy({ outputLocation: "/test-output", dryRun: false, apiLanguage: "python" });
279+
280+
const spawnCall = vi.mocked(spawn).mock.calls[0];
281+
const env = spawnCall[2]?.env as Record<string, string>;
282+
expect(env.FUNCTION_LANGUAGE).toBe("python");
283+
expect(env.FUNCTION_LANGUAGE_VERSION).toBe(DEFAULT_VERSION.Python);
284+
expect(SUPPORTED_VERSIONS.Python).toContain(env.FUNCTION_LANGUAGE_VERSION);
285+
});
286+
287+
it("should pass correct FUNCTION_LANGUAGE_VERSION for dotnet when only apiLanguage is specified", async () => {
288+
vi.spyOn(optionsModule, "isUserOrConfigOption").mockImplementation((option) => option === "apiLanguage");
289+
290+
await deploy({ outputLocation: "/test-output", dryRun: false, apiLanguage: "dotnet" });
291+
292+
const spawnCall = vi.mocked(spawn).mock.calls[0];
293+
const env = spawnCall[2]?.env as Record<string, string>;
294+
expect(env.FUNCTION_LANGUAGE).toBe("dotnet");
295+
expect(env.FUNCTION_LANGUAGE_VERSION).toBe(DEFAULT_VERSION.Dotnet);
296+
expect(SUPPORTED_VERSIONS.Dotnet).toContain(env.FUNCTION_LANGUAGE_VERSION);
297+
});
298+
299+
it("should pass correct FUNCTION_LANGUAGE_VERSION for dotnetisolated when only apiLanguage is specified", async () => {
300+
vi.spyOn(optionsModule, "isUserOrConfigOption").mockImplementation((option) => option === "apiLanguage");
301+
302+
await deploy({ outputLocation: "/test-output", dryRun: false, apiLanguage: "dotnetisolated" });
303+
304+
const spawnCall = vi.mocked(spawn).mock.calls[0];
305+
const env = spawnCall[2]?.env as Record<string, string>;
306+
expect(env.FUNCTION_LANGUAGE).toBe("dotnetisolated");
307+
expect(env.FUNCTION_LANGUAGE_VERSION).toBe(DEFAULT_VERSION.DotnetIsolated);
308+
expect(SUPPORTED_VERSIONS.DotnetIsolated).toContain(env.FUNCTION_LANGUAGE_VERSION);
309+
});
272310
});
273311
});

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const DEFAULT_CONFIG: SWACLIConfig = {
6868
appName: SWA_CLI_APP_NAME || undefined,
6969
dryRun: useEnvVarOrUseDefault(SWA_CLI_DEPLOY_DRY_RUN, false),
7070
apiLanguage: SWA_CLI_API_LANGUAGE || "node",
71-
apiVersion: SWA_CLI_API_VERSION || "16",
71+
apiVersion: SWA_CLI_API_VERSION || "22",
7272
dataApiDevserverUrl: SWA_CLI_DATA_API_DEVSERVER_URL || undefined,
7373

7474
// swa login options

src/core/constants.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { DEFAULT_CONFIG } from "../config.js";
2+
import { DEFAULT_VERSION, SUPPORTED_VERSIONS } from "./constants.js";
3+
4+
describe("DEFAULT_CONFIG and DEFAULT_VERSION/SUPPORTED_VERSIONS consistency", () => {
5+
it("DEFAULT_CONFIG.apiVersion should match DEFAULT_VERSION.Node", () => {
6+
expect(DEFAULT_CONFIG.apiVersion).toBe(DEFAULT_VERSION.Node);
7+
});
8+
9+
it("DEFAULT_CONFIG.apiLanguage should be 'node'", () => {
10+
expect(DEFAULT_CONFIG.apiLanguage).toBe("node");
11+
});
12+
13+
it("every DEFAULT_VERSION should be in its corresponding SUPPORTED_VERSIONS", () => {
14+
expect(SUPPORTED_VERSIONS.Node).toContain(DEFAULT_VERSION.Node);
15+
expect(SUPPORTED_VERSIONS.Dotnet).toContain(DEFAULT_VERSION.Dotnet);
16+
expect(SUPPORTED_VERSIONS.DotnetIsolated).toContain(DEFAULT_VERSION.DotnetIsolated);
17+
expect(SUPPORTED_VERSIONS.Python).toContain(DEFAULT_VERSION.Python);
18+
});
19+
});

0 commit comments

Comments
 (0)