diff --git a/.eslintrc.js b/.eslintrc.js
index 8dfbd0dfd..78f298a23 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -60,6 +60,9 @@ module.exports = {
},
],
+ // disallow direct `nock` module usage as it causes memory issues.
+ 'no-restricted-imports': [2, { paths: ['nock'] }],
+
// Makes no sense to allow type inference for expression parameters, but require typing the response
'@typescript-eslint/explicit-function-return-type': [
'error',
diff --git a/lib/config/presets/npm/index.spec.ts b/lib/config/presets/npm/index.spec.ts
index ea2633e50..1e251a9f6 100644
--- a/lib/config/presets/npm/index.spec.ts
+++ b/lib/config/presets/npm/index.spec.ts
@@ -1,4 +1,4 @@
-import nock from 'nock';
+import * as httpMock from '../../../../test/http-mock';
import { getName } from '../../../../test/util';
import { setAdminConfig } from '../../admin';
import * as npm from '.';
@@ -10,13 +10,12 @@ describe(getName(), () => {
beforeEach(() => {
jest.resetAllMocks();
setAdminConfig();
- nock.cleanAll();
});
afterEach(() => {
delete process.env.RENOVATE_CACHE_NPM_MINUTES;
});
it('should throw if no package', async () => {
- nock('https://registry.npmjs.org').get('/nopackage').reply(404);
+ httpMock.scope('https://registry.npmjs.org').get('/nopackage').reply(404);
await expect(
npm.getPreset({ packageName: 'nopackage', presetName: 'default' })
).rejects.toThrow(/dep not found/);
@@ -45,7 +44,8 @@ describe(getName(), () => {
'0.0.2': '2018-05-07T07:21:53+02:00',
},
};
- nock('https://registry.npmjs.org')
+ httpMock
+ .scope('https://registry.npmjs.org')
.get('/norenovateconfig')
.reply(200, presetPackage);
await expect(
@@ -77,7 +77,8 @@ describe(getName(), () => {
'0.0.2': '2018-05-07T07:21:53+02:00',
},
};
- nock('https://registry.npmjs.org')
+ httpMock
+ .scope('https://registry.npmjs.org')
.get('/presetnamenotfound')
.reply(200, presetPackage);
await expect(
@@ -112,7 +113,8 @@ describe(getName(), () => {
'0.0.2': '2018-05-07T07:21:53+02:00',
},
};
- nock('https://registry.npmjs.org')
+ httpMock
+ .scope('https://registry.npmjs.org')
.get('/workingpreset')
.reply(200, presetPackage);
const res = await npm.getPreset({ packageName: 'workingpreset' });
diff --git a/lib/datasource/sbt-package/index.spec.ts b/lib/datasource/sbt-package/index.spec.ts
index b91673e75..93be28038 100644
--- a/lib/datasource/sbt-package/index.spec.ts
+++ b/lib/datasource/sbt-package/index.spec.ts
@@ -1,10 +1,10 @@
-import nock from 'nock';
import { getPkgReleases } from '..';
+import * as httpMock from '../../../test/http-mock';
import { getName, loadFixture } from '../../../test/util';
import * as mavenVersioning from '../../versioning/maven';
import { MAVEN_REPO } from '../maven/common';
import { parseIndexDir } from '../sbt-plugin/util';
-import * as sbtPlugin from '.';
+import * as sbtPackage from '.';
const mavenIndexHtml = loadFixture(`maven-index.html`);
const sbtPluginIndex = loadFixture(`sbt-plugins-index.html`);
@@ -13,21 +13,27 @@ describe(getName(), () => {
it('parses Maven index directory', () => {
expect(parseIndexDir(mavenIndexHtml)).toMatchSnapshot();
});
+
it('parses sbt index directory', () => {
expect(parseIndexDir(sbtPluginIndex)).toMatchSnapshot();
});
describe('getPkgReleases', () => {
beforeEach(() => {
- nock.disableNetConnect();
- nock('https://failed_repo').get('/maven/org/scalatest/').reply(404, null);
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://failed_repo')
+ .get('/maven/org/scalatest/')
+ .reply(404, null);
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get('/maven2/com/example/')
.reply(200, 'empty_2.12/\n');
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get('/maven2/com/example/empty/')
.reply(200, '');
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get('/maven2/org/scalatest/')
.times(3)
.reply(
@@ -40,22 +46,28 @@ describe(getName(), () => {
'scalatest-flatspec_2.12' +
'scalatest-matchers-core_2.12'
);
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get('/maven2/org/scalatest/scalatest/')
.reply(200, "1.2.0/");
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get('/maven2/org/scalatest/scalatest_2.12/')
.reply(200, "4.5.6/");
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get('/maven2/org/scalatest/scalatest-app_2.12/')
.reply(200, "3.2.1/");
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get('/maven2/org/scalatest/scalatest-flatspec_2.12/')
.reply(200, "3.2.1/");
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get('/maven2/org/scalatest/scalatest-matchers-core_2.12/')
.reply(200, "3.2.1/");
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get(
'/maven2/org/scalatest/scalatest-app_2.12/6.5.4/scalatest-app_2.12-6.5.4.pom'
)
@@ -68,7 +80,8 @@ describe(getName(), () => {
'' +
''
);
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get(
'/maven2/org/scalatest/scalatest-flatspec_2.12/6.5.4/scalatest-flatspec_2.12-6.5.4.pom'
)
@@ -80,7 +93,8 @@ describe(getName(), () => {
'' +
''
);
- nock('https://repo.maven.apache.org')
+ httpMock
+ .scope('https://repo.maven.apache.org')
.get(
'/maven2/org/scalatest/scalatest-matchers-core_2.12/6.5.4/scalatest-matchers-core_2.12-6.5.4.pom'
)
@@ -91,10 +105,12 @@ describe(getName(), () => {
''
);
- nock('https://dl.bintray.com')
+ httpMock
+ .scope('https://dl.bintray.com')
.get('/sbt/sbt-plugin-releases/com.github.gseitz/')
.reply(200, '');
- nock('https://dl.bintray.com')
+ httpMock
+ .scope('https://dl.bintray.com')
.get('/sbt/sbt-plugin-releases/org.foundweekends/sbt-bintray/')
.reply(
200,
@@ -106,7 +122,8 @@ describe(getName(), () => {
'