diff --git a/lib/api/npm.js b/lib/api/npm.js index 3a60f114d4284c89ae97a7507a8fc8724a5e3efd..00824525db7816420ab3f95829a49ec7f5c5d219 100644 --- a/lib/api/npm.js +++ b/lib/api/npm.js @@ -81,7 +81,12 @@ async function getDependency(name, logger) { }; Object.keys(dep.versions).forEach(version => { // We don't use any of the version payload currently - dep.versions[version] = { time: res.body.time[version] }; + dep.versions[version] = { + // fall back to arbitrary time for old npm servers + time: res.body.time + ? res.body.time[version] + : '2017-01-01T12:00:00.000Z', + }; }); npmCache[cacheKey] = dep; logger.trace({ dependency: dep }, 'dependency'); diff --git a/test/api/__snapshots__/npm.spec.js.snap b/test/api/__snapshots__/npm.spec.js.snap index 134266500f14e03696a20dde060ed4a9ed368b59..b86e4548788b260a1e10062f4f868a959a741a50 100644 --- a/test/api/__snapshots__/npm.spec.js.snap +++ b/test/api/__snapshots__/npm.spec.js.snap @@ -139,6 +139,33 @@ Array [ ] `; +exports[`api/npm should use dummy time if missing 1`] = ` +Object { + "dist-tags": Object { + "latest": "0.0.1", + }, + "homepage": "https://google.com", + "name": undefined, + "renovate-config": undefined, + "repositoryUrl": "https://google.com", + "versions": Object { + "0.0.1": Object { + "time": "2017-01-01T12:00:00.000Z", + }, + }, +} +`; + +exports[`api/npm should use dummy time if missing 2`] = ` +Array [ + "https://registry.npmjs.org/foobar", + Object { + "headers": Object {}, + "json": true, + }, +] +`; + exports[`api/npm should use homepage 1`] = ` Object { "dist-tags": Object { diff --git a/test/api/npm.spec.js b/test/api/npm.spec.js index 9e1aeccc3332fd86b79db40d96c151c1e8cad7f8..ce9132a59e456de7e15ea1b0c24676d254fcc2ac 100644 --- a/test/api/npm.spec.js +++ b/test/api/npm.spec.js @@ -100,4 +100,13 @@ describe('api/npm', () => { const call = got.mock.calls[0]; expect(call).toMatchSnapshot(); }); + it('should use dummy time if missing', async () => { + const noTimeResponse = { ...npmResponse }; + delete noTimeResponse.body.time; + got.mockImplementation(() => Promise.resolve(noTimeResponse)); + const res = await npm.getDependency('foobar', logger); + expect(res).toMatchSnapshot(); + const call = got.mock.calls[0]; + expect(call).toMatchSnapshot(); + }); });