Skip to content

Commit 13fcca3

Browse files
committed
fix(test): add version parameter to getCliEnvironment for full branch coverage
1 parent e1fe1f6 commit 13fcca3

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/lib/constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ export const CLI_VERSION =
7272
* only replace literal `process.env.NODE_ENV`, not dynamic property accesses
7373
* like `getEnv().NODE_ENV`.
7474
*/
75-
export function getCliEnvironment(): string {
76-
if (CLI_VERSION === "0.0.0-dev") {
75+
export function getCliEnvironment(version: string = CLI_VERSION): string {
76+
if (version === "0.0.0-dev") {
7777
return "development";
7878
}
79-
if (CLI_VERSION.includes("-dev.")) {
79+
if (version.includes("-dev.")) {
8080
return "nightly";
8181
}
8282
return "production";

test/lib/constants.test.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,36 +84,24 @@ describe("normalizeUrl", () => {
8484
});
8585

8686
describe("getCliEnvironment", () => {
87-
test("returns 'development' in dev mode (SENTRY_CLI_VERSION not injected)", () => {
88-
// In test/dev mode, CLI_VERSION is "0.0.0-dev" because the build-time
89-
// constant SENTRY_CLI_VERSION is never defined.
87+
test("returns 'development' in dev mode (no build injection)", () => {
88+
// CLI_VERSION is "0.0.0-dev" when SENTRY_CLI_VERSION is not injected
9089
expect(getCliEnvironment()).toBe("development");
9190
});
9291

93-
test("derivation logic: stable versions → 'production'", () => {
94-
// Verify the logic that would run in production builds by checking
95-
// the conditions directly against known version formats.
96-
const stableVersions = ["0.20.0", "1.0.0", "0.23.0", "2.5.1"];
97-
for (const v of stableVersions) {
98-
expect(v === "0.0.0-dev").toBe(false);
99-
expect(v.includes("-dev.")).toBe(false);
100-
// Both conditions false → would return "production"
101-
}
92+
test("returns 'development' for '0.0.0-dev'", () => {
93+
expect(getCliEnvironment("0.0.0-dev")).toBe("development");
10294
});
10395

104-
test("derivation logic: nightly versions contain '-dev.'", () => {
105-
const nightlyVersions = ["0.24.0-dev.1740000000", "1.0.0-dev.1700000000"];
106-
for (const v of nightlyVersions) {
107-
expect(v === "0.0.0-dev").toBe(false);
108-
expect(v.includes("-dev.")).toBe(true);
109-
// First condition false, second true → would return "nightly"
110-
}
96+
test("returns 'nightly' for nightly versions", () => {
97+
expect(getCliEnvironment("0.24.0-dev.1740000000")).toBe("nightly");
98+
expect(getCliEnvironment("1.0.0-dev.1700000000")).toBe("nightly");
11199
});
112100

113-
test("derivation logic: dev fallback is exactly '0.0.0-dev'", () => {
114-
const v = "0.0.0-dev";
115-
expect(v === "0.0.0-dev").toBe(true);
116-
// First condition true → would return "development"
101+
test("returns 'production' for stable versions", () => {
102+
expect(getCliEnvironment("0.20.0")).toBe("production");
103+
expect(getCliEnvironment("1.0.0")).toBe("production");
104+
expect(getCliEnvironment("0.23.0")).toBe("production");
117105
});
118106
});
119107

0 commit comments

Comments
 (0)