Files
cobble/src/utils/running-version.test.ts
T
tben 524f0dde36 Show the running version on Settings > General
The General page ends with a Version block naming the release this
server runs, so an update can be confirmed from the app.

The version is COBBLE_VERSION, the release tag the image was built with
(Dockerfile ARG, passed by the release workflow, which falls back to
package.json's version on a workflow-dispatch build), else package.json's
version, which a development server reports too, with (development)
after it. runningVersion (src/utils/running-version.ts) drops an
unusable version string rather than showing it.

Also includes the working tree's pending signup guard in
src/pages/__root.server.ts: a user who still holds a session while the
install has no users is sent to /auth/logout (and may load it).
2026-10-22 16:03:56 +01:00

65 lines
2.1 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import runningVersion from "./running-version";
describe("runningVersion", () => {
test("a release reports the build's version", () => {
expect(
runningVersion({
env: { NODE_ENV: "production", COBBLE_VERSION: "v0.1.1" },
}),
).toEqual({ version: "v0.1.1", mode: "production" });
});
test("a production build without a version falls back to the source's", () => {
expect(
runningVersion({
env: { NODE_ENV: "production" },
package_version: "0.1.1",
}),
).toEqual({ version: "0.1.1", mode: "production" });
});
test("a development server reports the source's version too", () => {
expect(
runningVersion({
env: { NODE_ENV: "development" },
package_version: "0.1.1",
}),
).toEqual({ version: "0.1.1", mode: "development" });
});
test("a development server with a build version prefers it", () => {
expect(
runningVersion({
env: { NODE_ENV: "development", COBBLE_VERSION: "v0.2.0" },
package_version: "0.1.1",
}),
).toEqual({ version: "v0.2.0", mode: "development" });
});
test("no NODE_ENV at all is a development server", () => {
expect(runningVersion({ env: {}, package_version: "0.1.1" })).toEqual({
version: "0.1.1",
mode: "development",
});
});
test("an unusable version is dropped rather than shown", () => {
expect(
runningVersion({
env: { NODE_ENV: "production", COBBLE_VERSION: "bad version!" },
package_version: "",
}),
).toEqual({ version: null, mode: "production" });
});
test("an empty build version falls back to the source's", () => {
expect(
runningVersion({
env: { NODE_ENV: "production", COBBLE_VERSION: " " },
package_version: "0.1.1",
}),
).toEqual({ version: "0.1.1", mode: "production" });
});
});