Files
RSSHub/lib/utils/git-hash.test.ts
Tony 08a38f0a5e refactor: typing house-keeping (#23074)
* refactor: typing house-keeping

* fix: fix parse date not accepting strict mode

* refactor: use npm package

* fix: address review
2026-08-22 23:58:30 +08:00

36 lines
1.1 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest';
const originalEnv = {
HEROKU_SLUG_COMMIT: process.env.HEROKU_SLUG_COMMIT,
VERCEL_GIT_COMMIT_SHA: process.env.VERCEL_GIT_COMMIT_SHA,
};
afterEach(() => {
vi.resetModules();
vi.unstubAllEnvs();
if (originalEnv.HEROKU_SLUG_COMMIT === undefined) {
delete process.env.HEROKU_SLUG_COMMIT;
} else {
process.env.HEROKU_SLUG_COMMIT = originalEnv.HEROKU_SLUG_COMMIT;
}
if (originalEnv.VERCEL_GIT_COMMIT_SHA === undefined) {
delete process.env.VERCEL_GIT_COMMIT_SHA;
} else {
process.env.VERCEL_GIT_COMMIT_SHA = originalEnv.VERCEL_GIT_COMMIT_SHA;
}
});
describe('git-hash', () => {
it('falls back to unknown when git commands fail', async () => {
delete process.env.HEROKU_SLUG_COMMIT;
delete process.env.VERCEL_GIT_COMMIT_SHA;
// With an empty PATH the shell cannot find git, so the real execSync throws
vi.stubEnv('PATH', '');
const { gitHash } = await import('@/utils/git-hash');
expect(gitHash).toBe('unknown');
});
});