Something went wrong. Try again.
A free, open-source, self-hosted place to write a novel.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546import { describe, expect, it } from 'vitest';import { readFileSync } from 'node:fs';import { resolve } from 'node:path';import { BUILD } from '#lib/server/version.ts';
/** * One version, written down once. Cloudron's manifest cannot point at `package.json` * and must sort after the previous release, so two numbers are bumped by hand; a * mismatch ships an image that reports a version the platform does not know. * * The build is checked here too, because a missing `define` in `vite.config.ts` * throws in production rather than in a test. */const root = process.cwd();
function readJson(path: string) { return JSON.parse(readFileSync(resolve(root, path), 'utf8')) as Record<string, unknown>;}
describe('build identity', () => { it('carries the version and the commit', () => { expect(BUILD.version).toMatch(/^\d+\.\d+\.\d+/); expect(BUILD.commit.length).toBeGreaterThan(0); });
it('matches the version in package.json', () => { // `vite.config.ts` reads `package.json`, so a difference means the define was // replaced by a literal or dropped altogether. expect(BUILD.version).toBe(readJson('package.json').version); });
it('matches the Cloudron manifest version', () => { // Cloudron compares the manifest version against the installed one to decide // whether an update exists, so drift means the release is never offered. expect(readJson('CloudronManifest.json').version).toBe(BUILD.version); });
it('is given a commit by both image builds', () => { // An image is built from a copy with no `.git`, so without this argument every // published image reports the commit as unknown. for (const dockerfile of ['Dockerfile', 'Dockerfile.cloudron']) { expect(readFileSync(resolve(root, dockerfile), 'utf8')).toContain('ARG APP_COMMIT'); } });});