From 01f29ae455c76dcd2f61d019d444d14171d5677c Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Mon, 29 Jul 2019 11:27:32 +0200 Subject: [PATCH] fix(composer): default packagist datasource --- lib/datasource/packagist/index.js | 15 ++-- .../__snapshots__/packagist.spec.js.snap | 85 +++++++++++++++++++ test/datasource/packagist.spec.js | 11 +++ 3 files changed, 103 insertions(+), 8 deletions(-) diff --git a/lib/datasource/packagist/index.js b/lib/datasource/packagist/index.js index 6ee2be8783..8adeb74eb9 100644 --- a/lib/datasource/packagist/index.js +++ b/lib/datasource/packagist/index.js @@ -255,15 +255,14 @@ async function getPkgReleases({ lookupName, registryUrls }) { logger.trace(`getPkgReleases(${lookupName})`); let res; - if (is.nonEmptyArray(registryUrls)) { - for (const regUrl of registryUrls) { - res = await packageLookup(regUrl, lookupName); - if (res) { - break; - } + const registries = is.nonEmptyArray(registryUrls) + ? registryUrls + : ['https://packagist.org']; + for (const regUrl of registries) { + res = await packageLookup(regUrl, lookupName); + if (res) { + break; } - } /* istanbul ignore next */ else { - logger.debug({ lookupName }, 'No registryUrls defined'); } return res; } diff --git a/test/datasource/__snapshots__/packagist.spec.js.snap b/test/datasource/__snapshots__/packagist.spec.js.snap index 9ddefe86fb..34885f5022 100644 --- a/test/datasource/__snapshots__/packagist.spec.js.snap +++ b/test/datasource/__snapshots__/packagist.spec.js.snap @@ -1,5 +1,90 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`datasource/packagist getPkgReleases adds packagist source implicitly 1`] = ` +Object { + "homepage": "https://github.com/drewm/mailchimp-api", + "name": "drewm/mailchimp-api", + "releases": Array [ + Object { + "gitRef": "v1.0", + "releaseTimestamp": "2014-05-30T16:51:39+00:00", + "version": "1.0", + }, + Object { + "gitRef": "v1.1", + "releaseTimestamp": "2015-07-07T15:38:25+00:00", + "version": "1.1", + }, + Object { + "gitRef": "v2.0", + "releaseTimestamp": "2016-01-17T13:08:01+00:00", + "version": "2.0", + }, + Object { + "gitRef": "v2.1", + "releaseTimestamp": "2016-01-30T16:12:54+00:00", + "version": "2.1", + }, + Object { + "gitRef": "v2.1.1", + "releaseTimestamp": "2016-04-06T08:37:20+00:00", + "version": "2.1.1", + }, + Object { + "gitRef": "v2.1.2", + "releaseTimestamp": "2016-04-06T12:41:37+00:00", + "version": "2.1.2", + }, + Object { + "gitRef": "v2.1.3", + "releaseTimestamp": "2016-04-12T09:09:47+00:00", + "version": "2.1.3", + }, + Object { + "gitRef": "v2.2", + "releaseTimestamp": "2016-04-23T12:43:28+00:00", + "version": "2.2", + }, + Object { + "gitRef": "v2.2.1", + "releaseTimestamp": "2016-04-23T18:00:21+00:00", + "version": "2.2.1", + }, + Object { + "gitRef": "v2.2.2", + "releaseTimestamp": "2016-07-01T09:58:24+00:00", + "version": "2.2.2", + }, + Object { + "gitRef": "v2.2.3", + "releaseTimestamp": "2016-07-01T15:53:33+00:00", + "version": "2.2.3", + }, + Object { + "gitRef": "v2.2.4", + "releaseTimestamp": "2016-07-01T15:53:33+00:00", + "version": "2.2.4", + }, + Object { + "gitRef": "v2.3", + "releaseTimestamp": "2016-12-21T14:50:24+00:00", + "version": "2.3", + }, + Object { + "gitRef": "v2.4", + "releaseTimestamp": "2017-02-16T13:24:20+00:00", + "version": "2.4", + }, + Object { + "gitRef": "v2.5", + "releaseTimestamp": "2018-02-16T15:31:05+00:00", + "version": "2.5", + }, + ], + "sourceUrl": "https://github.com/drewm/mailchimp-api", +} +`; + exports[`datasource/packagist getPkgReleases processes real versioned data 1`] = ` Object { "homepage": "https://github.com/drewm/mailchimp-api", diff --git a/test/datasource/packagist.spec.js b/test/datasource/packagist.spec.js index 8046ab8a1a..19d03c2a7c 100644 --- a/test/datasource/packagist.spec.js +++ b/test/datasource/packagist.spec.js @@ -219,5 +219,16 @@ describe('datasource/packagist', () => { }) ).toMatchSnapshot(); }); + it('adds packagist source implicitly', async () => { + got.mockReturnValueOnce({ + body: JSON.parse(mailchimpJson), + }); + expect( + await datasource.getPkgReleases({ + ...config, + lookupName: 'drewm/mailchimp-api', + }) + ).toMatchSnapshot(); + }); }); }); -- GitLab