Skip to content

Commit f957ea8

Browse files
authoredMar 23, 2025··
test: Fix coverage for platform code (#34719)
1 parent 084fea7 commit f957ea8

File tree

17 files changed

+260
-251
lines changed

17 files changed

+260
-251
lines changed
 

‎.github/workflows/build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,10 @@ jobs:
465465
- name: Check coverage threshold
466466
run: |
467467
pnpm nyc check-coverage -t ./coverage/nyc \
468-
--branches 97.5 \
469-
--functions 98.98 \
470-
--lines 97.84 \
471-
--statements 97.84
468+
--branches 98.16 \
469+
--functions 99.51 \
470+
--lines 98.22 \
471+
--statements 98.22
472472
473473
# Catch-all required check for test matrix and coverage
474474
test-success:

‎lib/modules/platform/azure/azure-helper.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ export async function getFile(
9595
return null;
9696
}
9797
}
98-
} catch {
98+
} catch /* v8 ignore start */ {
9999
// it 's not a JSON, so I send the content directly with the line under
100-
}
100+
} /* v8 ignore stop */
101101

102102
return fileContent;
103103
}
104+
104105
return null; // no file found
105106
}
106107

‎lib/modules/platform/azure/index.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export async function getRawFile(
162162
);
163163

164164
return item?.content ?? null;
165-
} catch (err) /* istanbul ignore next */ {
165+
} catch (err) /* v8 ignore start */ {
166166
if (
167167
err.message?.includes('<title>Azure DevOps Services Unavailable</title>')
168168
) {
@@ -178,7 +178,7 @@ export async function getRawFile(
178178
throw new ExternalHostError(err, id);
179179
}
180180
throw err;
181-
}
181+
} /* v8 ignore stop */
182182
}
183183

184184
export async function getJsonFile(
@@ -209,11 +209,11 @@ export async function initRepo({
209209
logger.debug('Repository is disabled- throwing error to abort renovation');
210210
throw new Error(REPOSITORY_ARCHIVED);
211211
}
212-
// istanbul ignore if
212+
/* v8 ignore start */
213213
if (!repo.defaultBranch) {
214214
logger.debug('Repo is empty');
215215
throw new Error(REPOSITORY_EMPTY);
216-
}
216+
} /* v8 ignore stop */
217217
// TODO #22198
218218
config.repoId = repo.id!;
219219

@@ -613,12 +613,12 @@ export async function updatePr({
613613
const existingIndex = config.prList.findIndex(
614614
(item) => item.number === prNo,
615615
);
616-
// istanbul ignore if: should not happen
616+
/* v8 ignore start: should not happen */
617617
if (existingIndex === -1) {
618618
logger.warn({ prNo }, 'PR not found in cache');
619619
// Add to cache
620620
config.prList.push(prToCache);
621-
} else {
621+
} /* v8 ignore stop */ else {
622622
// overwrite existing PR in cache
623623
config.prList[existingIndex] = prToCache;
624624
}
@@ -861,31 +861,31 @@ export function maxBodyLength(): number {
861861
return 4000;
862862
}
863863

864-
/* istanbul ignore next */
864+
/* v8 ignore start */
865865
export function findIssue(): Promise<Issue | null> {
866866
// TODO: Needs implementation (#9592)
867867
logger.debug(`findIssue() is not implemented`);
868868
return Promise.resolve(null);
869-
}
869+
} /* v8 ignore stop */
870870

871-
/* istanbul ignore next */
871+
/* v8 ignore start */
872872
export function ensureIssue(): Promise<EnsureIssueResult | null> {
873873
// TODO: Needs implementation (#9592)
874874
logger.debug(`ensureIssue() is not implemented`);
875875
return Promise.resolve(null);
876-
}
876+
} /* v8 ignore stop */
877877

878-
/* istanbul ignore next */
878+
/* v8 ignore start */
879879
export function ensureIssueClosing(): Promise<void> {
880880
return Promise.resolve();
881-
}
881+
} /* v8 ignore stop */
882882

883-
/* istanbul ignore next */
883+
/* v8 ignore start */
884884
export function getIssueList(): Promise<Issue[]> {
885885
logger.debug(`getIssueList()`);
886886
// TODO: Needs implementation (#9592)
887887
return Promise.resolve([]);
888-
}
888+
} /* v8 ignore stop */
889889

890890
async function getUserIds(users: string[]): Promise<User[]> {
891891
const azureApiGit = await azureApi.gitApi();

‎lib/modules/platform/bitbucket-server/index.ts

+42-38
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ const defaults: {
8282
version: '0.0.0',
8383
};
8484

85-
/* istanbul ignore next */
85+
/* v8 ignore start */
8686
function updatePrVersion(pr: number, version: number): number {
8787
const res = Math.max(config.prVersions.get(pr) ?? 0, version);
8888
config.prVersions.set(pr, res);
8989
return res;
90-
}
90+
} /* v8 ignore stop */
9191

9292
export async function initPlatform({
9393
endpoint,
@@ -116,10 +116,10 @@ export async function initPlatform({
116116
};
117117
try {
118118
let bitbucketServerVersion: string;
119-
// istanbul ignore if: experimental feature
119+
/* v8 ignore start: experimental feature */
120120
if (process.env.RENOVATE_X_PLATFORM_VERSION) {
121121
bitbucketServerVersion = process.env.RENOVATE_X_PLATFORM_VERSION;
122-
} else {
122+
} /* v8 ignore stop */ else {
123123
const { version } = (
124124
await bitbucketServerHttp.getJsonUnchecked<{ version: string }>(
125125
`./rest/api/1.0/application-properties`,
@@ -193,10 +193,10 @@ export async function getRepos(): Promise<string[]> {
193193
const result = repos.map((repo) => `${repo.project.key}/${repo.slug}`);
194194
logger.debug({ result }, 'result of getRepos()');
195195
return result;
196-
} catch (err) /* istanbul ignore next */ {
196+
} catch (err) /* v8 ignore start */ {
197197
logger.error({ err }, `bitbucket getRepos error`);
198198
throw err;
199-
}
199+
} /* v8 ignore stop */
200200
}
201201

202202
export async function getRawFile(
@@ -296,7 +296,7 @@ export async function initRepo({
296296
};
297297

298298
return repoConfig;
299-
} catch (err) /* istanbul ignore next */ {
299+
} catch (err) /* v8 ignore start */ {
300300
if (err.statusCode === 404) {
301301
throw new Error(REPOSITORY_NOT_FOUND);
302302
}
@@ -306,7 +306,7 @@ export async function initRepo({
306306

307307
logger.debug({ err }, 'Unknown Bitbucket initRepo error');
308308
throw err;
309-
}
309+
} /* v8 ignore stop */
310310
}
311311

312312
export async function getBranchForceRebase(
@@ -353,7 +353,7 @@ export async function getPr(
353353
}
354354

355355
// TODO: coverage (#9624)
356-
// istanbul ignore next
356+
/* v8 ignore start */
357357
function matchesState(state: string, desiredState: string): boolean {
358358
if (desiredState === 'all') {
359359
return true;
@@ -362,21 +362,25 @@ function matchesState(state: string, desiredState: string): boolean {
362362
return state !== desiredState.substring(1);
363363
}
364364
return state === desiredState;
365-
}
365+
} /* v8 ignore stop */
366366

367367
// TODO: coverage (#9624)
368-
// istanbul ignore next
369-
const isRelevantPr =
370-
(branchName: string, prTitle: string | null | undefined, state: string) =>
371-
(p: Pr): boolean =>
368+
/* v8 ignore start */
369+
function isRelevantPr(
370+
branchName: string,
371+
prTitle: string | null | undefined,
372+
state: string,
373+
) {
374+
return (p: Pr): boolean =>
372375
p.sourceBranch === branchName &&
373376
(!prTitle || p.title.toUpperCase() === prTitle.toUpperCase()) &&
374377
matchesState(p.state, state);
378+
} /* v8 ignore stop */
375379

376380
// TODO: coverage (#9624)
381+
/* v8 ignore start */
377382
export async function getPrList(refreshCache?: boolean): Promise<Pr[]> {
378383
logger.debug(`getPrList()`);
379-
// istanbul ignore next
380384
if (!config.prList || refreshCache) {
381385
const searchParams: Record<string, string> = {
382386
state: 'ALL',
@@ -399,10 +403,10 @@ export async function getPrList(refreshCache?: boolean): Promise<Pr[]> {
399403
logger.debug('returning cached PR list');
400404
}
401405
return config.prList;
402-
}
406+
} /* v8 ignore stop */
403407

404408
// TODO: coverage (#9624)
405-
// istanbul ignore next
409+
/* v8 ignore start */
406410
export async function findPr({
407411
branchName,
408412
prTitle,
@@ -447,7 +451,7 @@ export async function findPr({
447451
logger.debug(`Renovate did not find a PR for branch #${branchName}`);
448452
}
449453
return pr ?? null;
450-
}
454+
} /* v8 ignore stop */
451455

452456
// Returns the Pull Request for a branch. Null if not exists.
453457
export async function getBranchPr(branchName: string): Promise<BbsPr | null> {
@@ -459,13 +463,13 @@ export async function getBranchPr(branchName: string): Promise<BbsPr | null> {
459463
return existingPr ? getPr(existingPr.number) : null;
460464
}
461465

462-
// istanbul ignore next
466+
/* v8 ignore start */
463467
export async function refreshPr(number: number): Promise<void> {
464468
// wait for pr change propagation
465469
await setTimeout(1000);
466470
// refresh cache
467471
await getPr(number, true);
468-
}
472+
} /* v8 ignore stop */
469473

470474
async function getStatus(
471475
branchName: string,
@@ -609,7 +613,7 @@ export async function setBranchStatus({
609613

610614
// Issue
611615

612-
/* istanbul ignore next */
616+
/* v8 ignore start */
613617
export function findIssue(title: string): Promise<Issue | null> {
614618
logger.debug(`findIssue(${title})`);
615619
// This is used by Renovate when creating its own issues,
@@ -618,9 +622,9 @@ export function findIssue(title: string): Promise<Issue | null> {
618622
//
619623
// Bitbucket Server does not have issues
620624
return Promise.resolve(null);
621-
}
625+
} /* v8 ignore stop */
622626

623-
/* istanbul ignore next */
627+
/* v8 ignore start */
624628
export function ensureIssue({
625629
title,
626630
}: EnsureIssueConfig): Promise<EnsureIssueResult | null> {
@@ -631,9 +635,9 @@ export function ensureIssue({
631635
//
632636
// Bitbucket Server does not have issues
633637
return Promise.resolve(null);
634-
}
638+
} /* v8 ignore stop */
635639

636-
/* istanbul ignore next */
640+
/* v8 ignore start */
637641
export function getIssueList(): Promise<Issue[]> {
638642
logger.debug(`getIssueList()`);
639643
// This is used by Renovate when creating its own issues,
@@ -642,9 +646,9 @@ export function getIssueList(): Promise<Issue[]> {
642646
//
643647
// Bitbucket Server does not have issues
644648
return Promise.resolve([]);
645-
}
649+
} /* v8 ignore stop */
646650

647-
/* istanbul ignore next */
651+
/* v8 ignore start */
648652
export function ensureIssueClosing(title: string): Promise<void> {
649653
logger.debug(`ensureIssueClosing(${title})`);
650654
// This is used by Renovate when creating its own issues,
@@ -653,7 +657,7 @@ export function ensureIssueClosing(title: string): Promise<void> {
653657
//
654658
// Bitbucket Server does not have issues
655659
return Promise.resolve();
656-
}
660+
} /* v8 ignore stop */
657661

658662
export function addAssignees(iid: number, assignees: string[]): Promise<void> {
659663
logger.debug(`addAssignees(${iid}, [${assignees.join(', ')}])`);
@@ -874,10 +878,10 @@ export async function ensureComment({
874878
logger.debug('Comment is already update-to-date');
875879
}
876880
return true;
877-
} catch (err) /* istanbul ignore next */ {
881+
} catch (err) /* v8 ignore start */ {
878882
logger.warn({ err }, 'Error ensuring comment');
879883
return false;
880-
}
884+
} /* v8 ignore stop */
881885
}
882886

883887
export async function ensureCommentRemoval(
@@ -906,9 +910,9 @@ export async function ensureCommentRemoval(
906910
if (commentId) {
907911
await deleteComment(prNo, commentId);
908912
}
909-
} catch (err) /* istanbul ignore next */ {
913+
} catch (err) /* v8 ignore start */ {
910914
logger.warn({ err }, 'Error ensuring comment removal');
911-
}
915+
} /* v8 ignore stop */
912916
}
913917

914918
// Pull Request
@@ -968,7 +972,7 @@ export async function createPr({
968972
`./rest/api/1.0/projects/${config.projectKey}/repos/${config.repositorySlug}/pull-requests`,
969973
{ body },
970974
);
971-
} catch (err) /* istanbul ignore next */ {
975+
} catch (err) /* v8 ignore start */ {
972976
if (
973977
err.body?.errors?.[0]?.exceptionName ===
974978
'com.atlassian.bitbucket.pull.EmptyPullRequestException'
@@ -980,7 +984,7 @@ export async function createPr({
980984
throw new Error(REPOSITORY_CHANGED);
981985
}
982986
throw err;
983-
}
987+
} /* v8 ignore stop */
984988

985989
const pr: BbsPr = {
986990
...utils.prInfo(prInfoRes.body),
@@ -989,10 +993,10 @@ export async function createPr({
989993
// TODO #22198
990994
updatePrVersion(pr.number, pr.version!);
991995

992-
// istanbul ignore if
996+
/* v8 ignore start */
993997
if (config.prList) {
994998
config.prList.push(pr);
995-
}
999+
} /* v8 ignore stop */
9961000

9971001
return pr;
9981002
}
@@ -1073,14 +1077,14 @@ export async function updatePr({
10731077
const existingIndex = config.prList.findIndex(
10741078
(item) => item.number === prNo,
10751079
);
1076-
// istanbul ignore if: should never happen
1080+
/* v8 ignore start: should never happen */
10771081
if (existingIndex === -1) {
10781082
logger.warn(
10791083
{ pr: bbsPr },
10801084
'Possible error: Updated PR was not found in the PRs that were returned from getPrList().',
10811085
);
10821086
config.prList.push({ ...bbsPr, state: finalState });
1083-
} else {
1087+
} /* v8 ignore stop */ else {
10841088
config.prList[existingIndex] = { ...bbsPr, state: finalState };
10851089
}
10861090
}

‎lib/modules/platform/bitbucket-server/utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ function generateUrlFromEndpoint(
8888
// TODO: types (#22198)
8989
auth: `${opts.username}:${opts.password}`,
9090
host: `${url.host}${url.pathname}${
91-
url.pathname.endsWith('/') ? '' : /* istanbul ignore next */ '/'
91+
/* v8 ignore start */
92+
url.pathname.endsWith('/') ? '' : '/'
93+
/* v8 ignore stop */
9294
}scm`,
9395
repository,
9496
});

0 commit comments

Comments
 (0)
Please sign in to comment.