Skip to content
Snippets Groups Projects
Unverified Commit 75df23bf authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

test(http): Disable http retries for tests inside constructor (#25711)

parent 03736619
No related branches found
No related tags found
No related merge requests found
...@@ -193,30 +193,6 @@ describe('util/http/index', () => { ...@@ -193,30 +193,6 @@ describe('util/http/index', () => {
); );
}); });
it('retries', async () => {
const NODE_ENV = process.env.NODE_ENV;
try {
delete process.env.NODE_ENV;
httpMock
.scope(baseUrl)
.head('/')
.reply(500)
.head('/')
.reply(200, undefined, { 'x-some-header': 'abc' });
expect(await http.head('http://renovate.com')).toEqual({
authorization: false,
body: '',
headers: {
'x-some-header': 'abc',
},
statusCode: 200,
});
expect(httpMock.allUsed()).toBeTrue();
} finally {
process.env.NODE_ENV = NODE_ENV;
}
});
it('limits concurrency by host', async () => { it('limits concurrency by host', async () => {
hostRules.add({ matchHost: 'renovate.com', concurrentRequestLimit: 1 }); hostRules.add({ matchHost: 'renovate.com', concurrentRequestLimit: 1 });
...@@ -314,6 +290,38 @@ describe('util/http/index', () => { ...@@ -314,6 +290,38 @@ describe('util/http/index', () => {
expect(res?.body.toString('utf-8')).toBe('test'); expect(res?.body.toString('utf-8')).toBe('test');
}); });
describe('retry', () => {
let NODE_ENV: string | undefined;
beforeAll(() => {
NODE_ENV = process.env.NODE_ENV;
delete process.env.NODE_ENV;
http = new Http('dummy');
});
afterAll(() => {
process.env.NODE_ENV = NODE_ENV;
});
it('works', async () => {
httpMock
.scope(baseUrl)
.head('/')
.reply(500)
.head('/')
.reply(200, undefined, { 'x-some-header': 'abc' });
expect(await http.head('http://renovate.com')).toEqual({
authorization: false,
body: '',
headers: {
'x-some-header': 'abc',
},
statusCode: 200,
});
expect(httpMock.allUsed()).toBeTrue();
});
});
describe('Schema support', () => { describe('Schema support', () => {
const SomeSchema = z const SomeSchema = z
.object({ x: z.number(), y: z.number() }) .object({ x: z.number(), y: z.number() })
......
...@@ -132,6 +132,10 @@ export class Http<Opts extends HttpOptions = HttpOptions> { ...@@ -132,6 +132,10 @@ export class Http<Opts extends HttpOptions = HttpOptions> {
options: HttpOptions = {}, options: HttpOptions = {},
) { ) {
this.options = merge<GotOptions>(options, { context: { hostType } }); this.options = merge<GotOptions>(options, { context: { hostType } });
if (process.env.NODE_ENV === 'test') {
this.options.retry = 0;
}
} }
protected getThrottle(url: string): Throttle | null { protected getThrottle(url: string): Throttle | null {
...@@ -167,9 +171,6 @@ export class Http<Opts extends HttpOptions = HttpOptions> { ...@@ -167,9 +171,6 @@ export class Http<Opts extends HttpOptions = HttpOptions> {
}; };
} }
if (process.env.NODE_ENV === 'test') {
options.retry = 0;
}
options.hooks = { options.hooks = {
beforeRedirect: [removeAuthorization], beforeRedirect: [removeAuthorization],
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment