From bb2fc1b7caffe85e550ac04f02c9f8da33f7978c Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Thu, 1 Mar 2018 10:21:26 +0100 Subject: [PATCH] refactor: move npm extract from workers to manager --- .../npm/extract.js} | 0 lib/workers/dep-type/index.js | 4 ++-- .../npm/__snapshots__/extract.spec.js.snap} | 2 +- .../npm/extract.spec.js} | 20 +++++++++---------- test/workers/dep-type/index.spec.js | 10 +++++----- 5 files changed, 18 insertions(+), 18 deletions(-) rename lib/{workers/dep-type/package-json.js => manager/npm/extract.js} (100%) rename test/{workers/dep-type/__snapshots__/package-json.spec.js.snap => manager/npm/__snapshots__/extract.spec.js.snap} (85%) rename test/{workers/dep-type/package-json.spec.js => manager/npm/extract.spec.js} (82%) diff --git a/lib/workers/dep-type/package-json.js b/lib/manager/npm/extract.js similarity index 100% rename from lib/workers/dep-type/package-json.js rename to lib/manager/npm/extract.js diff --git a/lib/workers/dep-type/index.js b/lib/workers/dep-type/index.js index 750c89ef43..511b50c4c1 100644 --- a/lib/workers/dep-type/index.js +++ b/lib/workers/dep-type/index.js @@ -1,6 +1,6 @@ const configParser = require('../../config'); const pkgWorker = require('../package'); -const packageJson = require('./package-json'); +const npmExtract = require('../../manager/npm/extract'); const dockerExtract = require('../../manager/docker/extract'); const meteorExtract = require('../../manager/meteor/extract'); const nodeExtract = require('../../manager/node/extract'); @@ -31,7 +31,7 @@ async function renovateDepType( const { manager } = config; if (manager === 'npm') { // Extract all dependencies from the package.json - deps = await packageJson.extractDependencies( + deps = await npmExtract.extractDependencies( packageContent, config.depType, packageLockParsed, diff --git a/test/workers/dep-type/__snapshots__/package-json.spec.js.snap b/test/manager/npm/__snapshots__/extract.spec.js.snap similarity index 85% rename from test/workers/dep-type/__snapshots__/package-json.spec.js.snap rename to test/manager/npm/__snapshots__/extract.spec.js.snap index a5113479c1..5090fa33da 100644 --- a/test/workers/dep-type/__snapshots__/package-json.spec.js.snap +++ b/test/manager/npm/__snapshots__/extract.spec.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`workers/dep-type/package-json .extractDependencies(packageJson, depType) each element contains non-null depType, depName, currentVersion 1`] = ` +exports[`workers/dep-type/package-json .extractDependencies(npmExtract, depType) each element contains non-null depType, depName, currentVersion 1`] = ` Array [ Object { "currentVersion": "6.5.0", diff --git a/test/workers/dep-type/package-json.spec.js b/test/manager/npm/extract.spec.js similarity index 82% rename from test/workers/dep-type/package-json.spec.js rename to test/manager/npm/extract.spec.js index 235a386c02..29a62c8e10 100644 --- a/test/workers/dep-type/package-json.spec.js +++ b/test/manager/npm/extract.spec.js @@ -1,6 +1,6 @@ const fs = require('fs'); const path = require('path'); -const packageJson = require('../../../lib/workers/dep-type/package-json'); +const npmExtract = require('../../../lib/manager/npm/extract'); function readFixture(fixture) { return fs.readFileSync( @@ -13,9 +13,9 @@ const input01Content = readFixture('inputs/01.json'); const input02Content = readFixture('inputs/02.json'); describe('workers/dep-type/package-json', () => { - describe('.extractDependencies(packageJson, depType)', () => { + describe('.extractDependencies(npmExtract, depType)', () => { it('returns an array of correct length (dependencies)', () => { - const extractedDependencies = packageJson.extractDependencies( + const extractedDependencies = npmExtract.extractDependencies( JSON.parse(input01Content), 'dependencies' ); @@ -23,7 +23,7 @@ describe('workers/dep-type/package-json', () => { extractedDependencies.should.have.length(6); }); it('returns an array of correct length (devDependencies)', () => { - const extractedDependencies = packageJson.extractDependencies( + const extractedDependencies = npmExtract.extractDependencies( JSON.parse(input01Content), 'devDependencies' ); @@ -31,7 +31,7 @@ describe('workers/dep-type/package-json', () => { extractedDependencies.should.have.length(4); }); it('each element contains non-null depType, depName, currentVersion', () => { - const extractedDependencies = packageJson.extractDependencies( + const extractedDependencies = npmExtract.extractDependencies( JSON.parse(input01Content), 'dependencies' ); @@ -41,7 +41,7 @@ describe('workers/dep-type/package-json', () => { .should.eql(true); }); it('supports null devDependencies indirect', () => { - const extractedDependencies = packageJson.extractDependencies( + const extractedDependencies = npmExtract.extractDependencies( JSON.parse(input02Content), 'dependencies' ); @@ -49,7 +49,7 @@ describe('workers/dep-type/package-json', () => { extractedDependencies.should.have.length(6); }); it('supports null', () => { - const extractedDependencies = packageJson.extractDependencies( + const extractedDependencies = npmExtract.extractDependencies( JSON.parse(input02Content), 'fooDependencies' ); @@ -60,7 +60,7 @@ describe('workers/dep-type/package-json', () => { const packageLockParsed = { dependencies: { chalk: { version: '2.0.1' } }, }; - const extractedDependencies = packageJson.extractDependencies( + const extractedDependencies = npmExtract.extractDependencies( { dependencies: { chalk: '^2.0.0', foo: '^1.0.0' } }, 'dependencies', packageLockParsed @@ -74,7 +74,7 @@ describe('workers/dep-type/package-json', () => { const yarnLockParsed = { object: { 'chalk@^2.0.0': { version: '2.0.1' } }, }; - const extractedDependencies = packageJson.extractDependencies( + const extractedDependencies = npmExtract.extractDependencies( { dependencies: { chalk: '^2.0.0', foo: '^1.0.0' } }, 'dependencies', undefined, @@ -86,7 +86,7 @@ describe('workers/dep-type/package-json', () => { expect(extractedDependencies[1].lockedVersion).toBeUndefined(); }); it('handles lock error', () => { - const extractedDependencies = packageJson.extractDependencies( + const extractedDependencies = npmExtract.extractDependencies( { dependencies: { chalk: '^2.0.0', foo: '^1.0.0' } }, 'dependencies', true diff --git a/test/workers/dep-type/index.spec.js b/test/workers/dep-type/index.spec.js index ae50573a3f..064c792f9e 100644 --- a/test/workers/dep-type/index.spec.js +++ b/test/workers/dep-type/index.spec.js @@ -1,10 +1,10 @@ const path = require('path'); const fs = require('fs'); -const packageJson = require('../../../lib/workers/dep-type/package-json'); +const npmExtract = require('../../../lib/manager/npm/extract'); const pkgWorker = require('../../../lib/workers/package/index'); const depTypeWorker = require('../../../lib/workers/dep-type/index'); -jest.mock('../../../lib/workers/dep-type/package-json'); +jest.mock('../../../lib/manager/npm/extract'); jest.mock('../../../lib/workers/package/index'); pkgWorker.renovatePackage = jest.fn(() => ['a']); @@ -27,12 +27,12 @@ describe('lib/workers/dep-type/index', () => { expect(res).toMatchObject([]); }); it('returns empty if no deps found', async () => { - packageJson.extractDependencies.mockReturnValueOnce([]); + npmExtract.extractDependencies.mockReturnValueOnce([]); const res = await depTypeWorker.renovateDepType({}, config); expect(res).toMatchObject([]); }); it('returns empty if all deps are filtered', async () => { - packageJson.extractDependencies.mockReturnValueOnce([ + npmExtract.extractDependencies.mockReturnValueOnce([ { depName: 'a' }, { depName: 'b' }, { depName: 'e' }, @@ -41,7 +41,7 @@ describe('lib/workers/dep-type/index', () => { expect(res).toMatchObject([]); }); it('returns combined upgrades if all deps are filtered', async () => { - packageJson.extractDependencies.mockReturnValueOnce([ + npmExtract.extractDependencies.mockReturnValueOnce([ { depName: 'a' }, { depName: 'c' }, { depName: 'd' }, -- GitLab