Skip to content

Commit

Permalink
chore(deps): update dependency nock to v14 (main) (renovatebot#34557)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
renovate[bot] and viceice authored Feb 28, 2025
1 parent 54cad01 commit 0299455
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/logger/__snapshots__/err-serializer.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports[`logger/err-serializer > got > sanitize http error 1`] = `
"headers": {
"content-type": "application/json",
},
"httpVersion": null,
"httpVersion": "1.1",
"retryCount": 0,
"statusCode": 412,
"statusMessage": "Precondition Failed",
Expand Down
10 changes: 8 additions & 2 deletions lib/modules/datasource/docker/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,20 @@ describe('modules/datasource/docker/index', () => {
});

it('should throw error for 429', async () => {
httpMock.scope(baseUrl).get('/').replyWithError({ statusCode: 429 });
httpMock
.scope(baseUrl)
.get('/')
.replyWithError(httpMock.error({ statusCode: 429 }));
await expect(
getDigest({ datasource: 'docker', packageName: 'some-dep' }, 'latest'),
).rejects.toThrow(EXTERNAL_HOST_ERROR);
});

it('should throw error for 5xx', async () => {
httpMock.scope(baseUrl).get('/').replyWithError({ statusCode: 504 });
httpMock
.scope(baseUrl)
.get('/')
.replyWithError(httpMock.error({ statusCode: 504 }));
await expect(
getDigest({ datasource: 'docker', packageName: 'some-dep' }, 'latest'),
).rejects.toThrow(EXTERNAL_HOST_ERROR);
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/datasource/npm/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ describe('modules/datasource/npm/get', () => {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer XXX",
"connection": "close",
"host": "test.org",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
Expand Down Expand Up @@ -509,6 +510,7 @@ describe('modules/datasource/npm/get', () => {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer XXX",
"connection": "close",
"host": "test.org",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
Expand Down Expand Up @@ -550,6 +552,7 @@ describe('modules/datasource/npm/get', () => {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer XXX",
"connection": "close",
"host": "test.org",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/packagist/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('modules/datasource/packagist/index', () => {
httpMock
.scope('https://composer.renovatebot.com')
.get('/packages.json')
.replyWithError({ code: 'ETIMEDOUT' });
.replyWithError(httpMock.error({ code: 'ETIMEDOUT' }));
httpMock
.scope(baseUrl)
.get('/packages.json')
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/repology/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const mockApiCall = (name: string, response: ResponseMock) => {
if (response.status) {
interceptor.reply(response.status, response.body);
} else {
interceptor.replyWithError({ code: response.code });
interceptor.replyWithError(httpMock.error({ code: response.code }));
}
};

Expand All @@ -49,7 +49,7 @@ const mockResolverCall = (
if (response.status) {
interceptor.reply(response.status, response.body);
} else {
interceptor.replyWithError({ code: response.code });
interceptor.replyWithError(httpMock.error({ code: response.code }));
}
};

Expand Down
4 changes: 2 additions & 2 deletions lib/modules/platform/gitea/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ describe('modules/platform/gitea/index', () => {
uid: 1,
archived: false,
})
.replyWithError(new Error('searchRepos()'));
.replyWithError(httpMock.error('searchRepos()'));
await initFakePlatform(scope);

await expect(gitea.getRepos()).rejects.toThrow('searchRepos()');
Expand Down Expand Up @@ -464,7 +464,7 @@ describe('modules/platform/gitea/index', () => {
const scope = httpMock
.scope('https://gitea.com/api/v1')
.get(`/repos/${initRepoCfg.repository}`)
.replyWithError(new Error('getRepo()'));
.replyWithError(httpMock.error('getRepo()'));
await initFakePlatform(scope);
await expect(gitea.initRepo(initRepoCfg)).rejects.toThrow('getRepo()');
});
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ describe('modules/platform/gitlab/index', () => {
httpMock
.scope(gitlabApiHost)
.get('/api/v4/users?username=someuser')
.reply(304, [])
.reply(200, [])
.get('/api/v4/users?username=someotheruser')
.reply(200, [{ id: 124 }])
.put('/api/v4/projects/undefined/merge_requests/42?assignee_ids[]=124')
Expand Down
5 changes: 4 additions & 1 deletion lib/util/http/github.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ describe('util/http/github', () => {

async function failWithError(error: string | Record<string, unknown>) {
const url = '/some-url';
httpMock.scope(githubApiHost).get(url).replyWithError(error);
httpMock
.scope(githubApiHost)
.get(url)
.replyWithError(httpMock.error(error));
await githubApi.getJsonUnchecked(url);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/util/http/gitlab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('util/http/gitlab', () => {
httpMock
.scope(gitlabApiHost)
.get('/api/v4/some-url')
.replyWithError({ code: 'EAI_AGAIN' });
.replyWithError(httpMock.error({ code: 'EAI_AGAIN' }));
await expect(gitlabApi.get('some-url')).rejects.toThrow(
EXTERNAL_HOST_ERROR,
);
Expand Down
6 changes: 4 additions & 2 deletions lib/util/http/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ describe('util/http/index', () => {
});

it('headJson', async () => {
httpMock.scope(baseUrl).head('/').reply(200, {});
httpMock.scope(baseUrl).head('/').reply(200, undefined, {
'content-type': 'application/json',
});
expect(await http.headJson('http://renovate.com', { baseUrl })).toEqual({
authorization: false,
body: {},
body: '',
headers: {
'content-type': 'application/json',
},
Expand Down
2 changes: 1 addition & 1 deletion lib/util/merge-confidence/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ describe('util/merge-confidence/index', () => {
httpMock
.scope(apiBaseUrl)
.get(`/api/mc/availability`)
.replyWithError({ code: 'ECONNRESET' });
.replyWithError(httpMock.error({ code: 'ECONNRESET' }));

await expect(
initMergeConfidence({ mergeConfidenceEndpoint: apiBaseUrl }),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
"lint-staged": "15.4.3",
"markdownlint-cli2": "0.17.2",
"memfs": "4.17.0",
"nock": "13.5.6",
"nock": "14.0.1",
"npm-run-all2": "7.0.2",
"nyc": "17.1.0",
"rimraf": "6.0.1",
Expand Down
62 changes: 53 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/http-mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'node:fs';
import type { Url } from 'node:url';
import is from '@sindresorhus/is';
import { codeBlock } from 'common-tags';
// eslint-disable-next-line no-restricted-imports
import nock from 'nock';
Expand Down Expand Up @@ -264,3 +265,10 @@ afterAll(() => {
afterEach(() => {
clear();
});

export function error(props: string | Record<string, unknown> = {}): Error {
if (is.string(props)) {
return new Error(props);
}
return Object.assign(new Error(), props);
}

0 comments on commit 0299455

Please sign in to comment.