From f28c90bc6ce661f2ea04ecd3a4e7a5f5c7d36acc Mon Sep 17 00:00:00 2001 From: cornholio <0@mcornholio.ru> Date: Sun, 4 Mar 2018 21:31:57 +0300 Subject: [PATCH] Fixed re-pulling with lockfileS --- lib/install/index.js | 4 ++-- test/unit/install/index.test.js | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/install/index.js b/lib/install/index.js index fd9d3d4..e866f7e 100644 --- a/lib/install/index.js +++ b/lib/install/index.js @@ -129,7 +129,7 @@ function install({force = false, config, rePull = false, lockfile = null}) { return pushBackends(missingBackends, newPkgJsonHash, config, rePull) .catch(error => { if (error instanceof errors.RePullNeeded) { - return install({force: true, rePull: true, config}); + return install({force: true, rePull: true, config, lockfile}); } throw error; @@ -142,7 +142,7 @@ function install({force = false, config, rePull = false, lockfile = null}) { return pushBackends(config.backends, newPkgJsonHash, config, rePull) .catch(error => { if (error instanceof errors.RePullNeeded) { - return install({force: true, rePull: true, config}); + return install({force: true, rePull: true, config, lockfile}); } throw error; diff --git a/test/unit/install/index.test.js b/test/unit/install/index.test.js index 051ed98..da96ed0 100644 --- a/test/unit/install/index.test.js +++ b/test/unit/install/index.test.js @@ -1040,8 +1040,8 @@ describe('install', () => { fakeBackends[1].backend.pull = () => Promise.reject(new errors.BundleNotFoundError); const backendMock0 = sandbox.mock(fakeBackends[0].backend); - npmWrapper.installAll.restore(); + npmWrapper.installAll.restore(); sandbox.stub(npmWrapper, 'installAll').callsFake(() => { mockfs({ 'package.json': JSON.stringify(PKGJSON), @@ -1051,13 +1051,39 @@ describe('install', () => { return Promise.resolve(); }); - backendMock0.expects('push').withArgs('PKGJSONHashWithNewLockfile').resolves(); const checkResult = checkMockResult.bind(null, [backendMock0], done); install({config}).then(checkResult, checkResult); }); + + it('re-pulling should work after hash recalculation', done => { + const backendMock0 = sandbox.mock(fakeBackends[0].backend); + + backendMock0.expects('pull').withArgs('PKGJSONHash').rejects(new errors.BundleNotFoundError); + fakeBackends[1].backend.pull = () => Promise.reject(new errors.BundleNotFoundError); + + backendMock0.expects('push') + .withArgs('PKGJSONHashWithNewLockfile') + .rejects(new errors.BundleAlreadyExistsError); + + backendMock0.expects('pull').withArgs('PKGJSONHashWithNewLockfile').resolves(); + + npmWrapper.installAll.restore(); + sandbox.stub(npmWrapper, 'installAll').callsFake(() => { + mockfs({ + 'package.json': JSON.stringify(PKGJSON), + 'package-lock.json': JSON.stringify(LOCKFILE), + }); + + return Promise.resolve(); + }); + + const checkResult = checkMockResult.bind(null, [backendMock0], done); + + install({config}).then(checkResult, checkResult); + }); }); });