Files
Sebastian Poxhofer 5ad36a2387 test(linters): add linting rule to enforce usage of host rules test util (#44692)
* ci(linter): add renovate/no-host-rules-mock rule

Flags vi.mock()/vi.doMock() calls whose module specifier contains
"host-rules" in spec files. Tests should configure real rules via
hostRules.add() instead of mocking the host-rules module.

Enabled at "warn" severity instead of "error": the repo currently has
35 pre-existing violations across 34 spec files, which exceeds the
agreed fix threshold of 12 files. No violation fixes are included;
migrating each spec to real hostRules.add()/clear() setup is a
semantic test rewrite that should be done incrementally, after which
the rule can be promoted to "error".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* ci(linter): enforce renovate/no-host-rules-mock at error

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(datasource): use real host-rules instead of mocking

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(manager): use real host-rules instead of mocking

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(platform): use real host-rules instead of mocking

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(util,workers): use real host-rules instead of mocking

Also narrow renovate/no-host-rules-mock to the host-rules module itself so that mocking e.g. host-rules-from-env is not flagged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* ci(linter): mention '~test/host-rules.ts' util in no-host-rules-mock message

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 10:36:12 +00:00

156 lines
4.3 KiB
TypeScript

import { hostRules } from '~test/host-rules.ts';
import * as githubGraphql from '../../../util/github/graphql/index.ts';
import type { Timestamp } from '../../../util/timestamp.ts';
import { getDigest, getPkgReleases } from '../index.ts';
import { GithubReleasesDatasource } from './index.ts';
describe('modules/datasource/github-releases/index', () => {
beforeEach(() => {
hostRules.add({ token: 'some-token' });
});
describe('getReleases', () => {
it('returns releases', async () => {
vi.spyOn(githubGraphql, 'queryReleases').mockResolvedValueOnce([
{
id: 1,
url: 'https://example.com',
name: 'some/dep2',
description: 'some description',
version: 'a',
releaseTimestamp: '2020-03-09T13:00:00Z' as Timestamp,
},
{
id: 2,
url: 'https://example.com',
name: 'some/dep2',
description: 'some description',
version: 'v',
releaseTimestamp: '2020-03-09T12:00:00Z' as Timestamp,
},
{
id: 3,
url: 'https://example.com',
name: 'some/dep2',
description: 'some description',
version: '1.0.0',
releaseTimestamp: '2020-03-09T11:00:00Z' as Timestamp,
},
{
id: 4,
url: 'https://example.com',
name: 'some/dep2',
description: 'some description',
version: 'v1.1.0',
releaseTimestamp: '2020-03-09T10:00:00Z' as Timestamp,
},
{
id: 5,
url: 'https://example.com',
name: 'some/dep2',
description: 'some description',
version: '2.0.0',
releaseTimestamp: '2020-04-09T10:00:00Z' as Timestamp,
isStable: false,
},
]);
const res = await getPkgReleases({
datasource: GithubReleasesDatasource.id,
packageName: 'some/dep',
});
expect(res).toMatchObject({
registryUrl: 'https://github.com',
releases: [
{
releaseTimestamp: '2020-03-09T11:00:00.000Z' as Timestamp,
version: '1.0.0',
},
{
version: 'v1.1.0',
releaseTimestamp: '2020-03-09T10:00:00.000Z' as Timestamp,
},
{
version: '2.0.0',
releaseTimestamp: '2020-04-09T10:00:00.000Z' as Timestamp,
isStable: false,
},
],
sourceUrl: 'https://github.com/some/dep',
});
});
});
describe('getDigest', () => {
const packageName = 'some/dep';
const currentValue = 'v1.0.0';
const currentDigest = 'sha-of-v1';
const newValue = 'v15.0.0';
const newDigest = 'sha-of-v15';
beforeEach(() => {
vi.spyOn(githubGraphql, 'queryTags').mockResolvedValueOnce([
{
version: 'v1.0.0',
gitRef: 'v1.0.0',
releaseTimestamp: '2021-01-01' as Timestamp,
hash: 'sha-of-v1',
},
{
version: 'v15.0.0',
gitRef: 'v15.0.0',
releaseTimestamp: '2022-10-01' as Timestamp,
hash: 'sha-of-v15',
},
]);
});
it('should be independent of the current digest', async () => {
const digest = await getDigest(
{
datasource: GithubReleasesDatasource.id,
packageName,
currentValue,
},
newValue,
);
expect(digest).toBe(newDigest);
});
it('should be independent of the current value', async () => {
const digest = await getDigest(
{ datasource: GithubReleasesDatasource.id, packageName },
newValue,
);
expect(digest).toBe(newDigest);
});
it('returns updated digest in new release', async () => {
const digest = await getDigest(
{
datasource: GithubReleasesDatasource.id,
packageName,
currentValue,
currentDigest,
},
newValue,
);
expect(digest).toEqual(newDigest);
});
it('returns null if the new value/tag does not exist', async () => {
const digest = await getDigest(
{
datasource: GithubReleasesDatasource.id,
packageName,
currentValue,
currentDigest,
},
'unknown-tag',
);
expect(digest).toBeNull();
});
});
});