feat(cli): include git sha in --version
This commit is contained in:
+22
-4
@@ -1,12 +1,30 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getCliVersion } from '../src/lib/version.js';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { formatVersionLine, resolveGitSha, resolvePackageVersion } from '../src/lib/version.js';
|
||||
|
||||
describe('getCliVersion', () => {
|
||||
it('matches package.json version when available', () => {
|
||||
afterEach(() => {
|
||||
delete process.env.BIRD_VERSION;
|
||||
delete process.env.BIRD_GIT_SHA;
|
||||
});
|
||||
|
||||
it('reads package.json version when available', () => {
|
||||
const raw = readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8');
|
||||
const pkg = JSON.parse(raw) as { version?: unknown };
|
||||
expect(getCliVersion()).toBe(pkg.version);
|
||||
expect(resolvePackageVersion()).toBe(pkg.version);
|
||||
});
|
||||
|
||||
it('formats injected version + sha', () => {
|
||||
process.env.BIRD_VERSION = '9.9.9';
|
||||
process.env.BIRD_GIT_SHA = 'abcdef123456';
|
||||
expect(formatVersionLine('not a url')).toBe('9.9.9 (abcdef12)');
|
||||
});
|
||||
|
||||
it('adds git sha when available', () => {
|
||||
const version = resolvePackageVersion();
|
||||
const sha = resolveGitSha();
|
||||
expect(sha).toMatch(/^[0-9a-f]{8}$/);
|
||||
expect(formatVersionLine()).toBe(`${version} (${sha})`);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user