Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/cli/commands/deploy/deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import * as deployClientModule from "../../../core/deploy-client.js";
import { deploy } from "./deploy.js";
import * as loginModule from "../login/login.js";
import { loadPackageJson } from "../../../core/utils/json.js";
import { DEFAULT_VERSION, SUPPORTED_VERSIONS } from "../../../core/constants.js";
import * as optionsModule from "../../../core/utils/options.js";

const pkg = loadPackageJson();

Expand Down Expand Up @@ -269,5 +271,41 @@ describe("deploy", () => {
expect(logger.error).toHaveBeenCalledWith("The deployment binary exited with code 1.");
expect(exitSpy).not.toHaveBeenCalled();
});

it("should pass correct FUNCTION_LANGUAGE_VERSION for python when only apiLanguage is specified", async () => {
vi.spyOn(optionsModule, "isUserOrConfigOption").mockImplementation((option) => option === "apiLanguage");

await deploy({ outputLocation: "/test-output", dryRun: false, apiLanguage: "python" });

const spawnCall = vi.mocked(spawn).mock.calls[0];
const env = spawnCall[2]?.env as Record<string, string>;
expect(env.FUNCTION_LANGUAGE).toBe("python");
expect(env.FUNCTION_LANGUAGE_VERSION).toBe(DEFAULT_VERSION.Python);
expect(SUPPORTED_VERSIONS.Python).toContain(env.FUNCTION_LANGUAGE_VERSION);
});

it("should pass correct FUNCTION_LANGUAGE_VERSION for dotnet when only apiLanguage is specified", async () => {
vi.spyOn(optionsModule, "isUserOrConfigOption").mockImplementation((option) => option === "apiLanguage");

await deploy({ outputLocation: "/test-output", dryRun: false, apiLanguage: "dotnet" });

const spawnCall = vi.mocked(spawn).mock.calls[0];
const env = spawnCall[2]?.env as Record<string, string>;
expect(env.FUNCTION_LANGUAGE).toBe("dotnet");
expect(env.FUNCTION_LANGUAGE_VERSION).toBe(DEFAULT_VERSION.Dotnet);
expect(SUPPORTED_VERSIONS.Dotnet).toContain(env.FUNCTION_LANGUAGE_VERSION);
});

it("should pass correct FUNCTION_LANGUAGE_VERSION for dotnetisolated when only apiLanguage is specified", async () => {
vi.spyOn(optionsModule, "isUserOrConfigOption").mockImplementation((option) => option === "apiLanguage");

await deploy({ outputLocation: "/test-output", dryRun: false, apiLanguage: "dotnetisolated" });

const spawnCall = vi.mocked(spawn).mock.calls[0];
const env = spawnCall[2]?.env as Record<string, string>;
expect(env.FUNCTION_LANGUAGE).toBe("dotnetisolated");
expect(env.FUNCTION_LANGUAGE_VERSION).toBe(DEFAULT_VERSION.DotnetIsolated);
expect(SUPPORTED_VERSIONS.DotnetIsolated).toContain(env.FUNCTION_LANGUAGE_VERSION);
});
});
});
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const DEFAULT_CONFIG: SWACLIConfig = {
appName: SWA_CLI_APP_NAME || undefined,
dryRun: useEnvVarOrUseDefault(SWA_CLI_DEPLOY_DRY_RUN, false),
apiLanguage: SWA_CLI_API_LANGUAGE || "node",
apiVersion: SWA_CLI_API_VERSION || "16",
apiVersion: SWA_CLI_API_VERSION || "22",
dataApiDevserverUrl: SWA_CLI_DATA_API_DEVSERVER_URL || undefined,

// swa login options
Expand Down
19 changes: 19 additions & 0 deletions src/core/constants.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DEFAULT_CONFIG } from "../config.js";
import { DEFAULT_VERSION, SUPPORTED_VERSIONS } from "./constants.js";

describe("DEFAULT_CONFIG and DEFAULT_VERSION/SUPPORTED_VERSIONS consistency", () => {
it("DEFAULT_CONFIG.apiVersion should match DEFAULT_VERSION.Node", () => {
expect(DEFAULT_CONFIG.apiVersion).toBe(DEFAULT_VERSION.Node);
});

it("DEFAULT_CONFIG.apiLanguage should be 'node'", () => {
expect(DEFAULT_CONFIG.apiLanguage).toBe("node");
});

it("every DEFAULT_VERSION should be in its corresponding SUPPORTED_VERSIONS", () => {
expect(SUPPORTED_VERSIONS.Node).toContain(DEFAULT_VERSION.Node);
expect(SUPPORTED_VERSIONS.Dotnet).toContain(DEFAULT_VERSION.Dotnet);
expect(SUPPORTED_VERSIONS.DotnetIsolated).toContain(DEFAULT_VERSION.DotnetIsolated);
expect(SUPPORTED_VERSIONS.Python).toContain(DEFAULT_VERSION.Python);
});
});
Loading