diff --git a/lib/modules/datasource/sbt-plugin/index.spec.ts b/lib/modules/datasource/sbt-plugin/index.spec.ts index c541938f76f734cbdad272a34cdfe94a43c00bd1..a44dc2ebd30bdc74a4692ba987bdfb398bfc69a6 100644 --- a/lib/modules/datasource/sbt-plugin/index.spec.ts +++ b/lib/modules/datasource/sbt-plugin/index.spec.ts @@ -37,42 +37,127 @@ describe('modules/datasource/sbt-plugin/index', () => { }); describe('getPkgReleases', () => { - beforeEach(() => { + it('returns null in case of errors', async () => { + httpMock + .scope('https://failed_repo/maven/') + .get('/org/scalatest/') + .reply(404) + .get('/org/scalatest/scalatest/') + .reply(404) + .get('/org.scalatest/') + .reply(404) + .get('/org.scalatest/scalatest/') + .reply(404); + httpMock - .scope('https://failed_repo') - .get('/maven/org/scalatest/') + .scope('https://repo.maven.apache.org/maven2/') + .get('/org/scalatest/') + .reply(404) + .get('/org/scalatest/scalaz/') .reply(404); + + httpMock + .scope('https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/') + .get('/org.scalatest/scalaz/') + .reply(404) + .get('/org.scalatest/') + .reply(404) + .get('/org/scalatest/scalaz/') + .reply(404) + .get('/org/scalatest/') + .reply(404); + + expect( + await getPkgReleases({ + versioning: mavenVersioning.id, + datasource: SbtPluginDatasource.id, + packageName: 'org.scalatest:scalatest', + registryUrls: ['https://failed_repo/maven'], + }), + ).toBeNull(); + expect( + await getPkgReleases({ + versioning: mavenVersioning.id, + datasource: SbtPluginDatasource.id, + packageName: 'org.scalatest:scalaz', + registryUrls: [], + }), + ).toBeNull(); + }); + + it('fetches sbt plugins', async () => { httpMock - .scope('https://repo.maven.apache.org') - .get('/maven2/org/scalatest/') + .scope('https://repo.maven.apache.org/maven2/') + .get('/org/foundweekends/sbt-bintray/') .reply( 200, codeBlock` - <a href="../">../</a> - <a href="scalatest/">scalatest/</a> - <a href="scalatest_2.12/">scalatest_2.12/</a> - <a href="scalatest_sjs2.12/">scalatest_sjs2.12/</a> - <a href="scalatest_native2.12/">scalatest_native2.12/</a> + <html> + <head> </head> + <body> + <pre><a href="../">../</a></pre> + <pre><a href="scala_2.12/">scala_2.12/</a></pre> + </body> + </html> `, - ); - httpMock - .scope('https://repo.maven.apache.org') - .get('/maven2/org/scalatest/scalatest/') + ) + .get('/org/foundweekends/sbt-bintray/scala_2.12/') + .reply( + 200, + codeBlock` + <html> + <head> </head> + <body> + <pre><a href="../">../</a></pre> + <pre><a href="sbt_1.0/">sbt_1.0/</a></pre> + </body> + </html> + `, + ) + .get('/org/foundweekends/sbt-bintray/scala_2.12/sbt_1.0/') .reply( 200, codeBlock` - <a href='../'>../</a> - <a href='1.2.0/'>1.2.0/</a> + <html> + <head> </head> + <body> + <pre><a href="../">../</a></pre> + <pre><a href="0.5.5/">0.5.5/</a></pre> + </body> + </html> `, ); + httpMock - .scope('https://repo.maven.apache.org') - .get('/maven2/org/scalatest/scalatest_2.12/') - .reply(200, "<a href='1.2.3/'>4.5.6/</a>"); + .scope('https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/') + .get('/org.foundweekends/sbt-bintray/') + .reply(404) + .get('/org.foundweekends/') + .reply(404) + .get('/org/foundweekends/sbt-bintray/') + .reply(404) + .get('/org/foundweekends/') + .reply(404); + + expect( + await getPkgReleases({ + versioning: mavenVersioning.id, + datasource: SbtPluginDatasource.id, + packageName: 'org.foundweekends:sbt-bintray', + registryUrls: [], + }), + ).toEqual({ + dependencyUrl: + 'https://repo.maven.apache.org/maven2/org/foundweekends/sbt-bintray', + registryUrl: 'https://repo.maven.apache.org/maven2', + releases: [{ version: '0.5.5' }], + }); + }); + it('fetches sbt plugins 2', async () => { httpMock - .scope('https://repo.maven.apache.org') - .get('/maven2/org/foundweekends/sbt-bintray/') + .scope('https://repo.maven.apache.org/maven2/') + .get('/org/foundweekends/sbt-bintray/') .reply( 200, codeBlock` @@ -84,10 +169,8 @@ describe('modules/datasource/sbt-plugin/index', () => { </body> </html> `, - ); - httpMock - .scope('https://repo.maven.apache.org') - .get('/maven2/org/foundweekends/sbt-bintray/scala_2.12/') + ) + .get('/org/foundweekends/sbt-bintray/scala_2.12/') .reply( 200, codeBlock` @@ -99,10 +182,8 @@ describe('modules/datasource/sbt-plugin/index', () => { </body> </html> `, - ); - httpMock - .scope('https://repo.maven.apache.org') - .get('/maven2/org/foundweekends/sbt-bintray/scala_2.12/sbt_1.0/') + ) + .get('/org/foundweekends/sbt-bintray/scala_2.12/sbt_1.0/') .reply( 200, codeBlock` @@ -117,8 +198,35 @@ describe('modules/datasource/sbt-plugin/index', () => { ); httpMock - .scope('https://repo.maven.apache.org') - .get('/maven2/io/get-coursier/') + .scope('https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/') + .get('/org.foundweekends/sbt-bintray/') + .reply(404) + .get('/org.foundweekends/') + .reply(404) + .get('/org/foundweekends/sbt-bintray/') + .reply(404) + .get('/org/foundweekends/') + .reply(404); + + expect( + await getPkgReleases({ + versioning: mavenVersioning.id, + datasource: SbtPluginDatasource.id, + packageName: 'org.foundweekends:sbt-bintray_2.12', + registryUrls: [], + }), + ).toEqual({ + dependencyUrl: + 'https://repo.maven.apache.org/maven2/org/foundweekends/sbt-bintray', + registryUrl: 'https://repo.maven.apache.org/maven2', + releases: [{ version: '0.5.5' }], + }); + }); + + it('extracts URL from Maven POM file', async () => { + httpMock + .scope('https://repo.maven.apache.org/maven2/') + .get('/io/get-coursier/') .reply( 200, codeBlock` @@ -132,10 +240,8 @@ describe('modules/datasource/sbt-plugin/index', () => { >sbt-coursier_2.12_1.0.0-M6/</a > `, - ); - httpMock - .scope('https://repo.maven.apache.org') - .get('/maven2/io/get-coursier/sbt-coursier_2.12_1.0/') + ) + .get('/io/get-coursier/sbt-coursier_2.12_1.0/') .reply( 200, codeBlock` @@ -144,11 +250,9 @@ describe('modules/datasource/sbt-plugin/index', () => { <a href="2.0.0-RC6-2/">2.0.0-RC6-2/</a> <a href="2.0.0-RC6-6/">2.0.0-RC6-6/</a> `, - ); - httpMock - .scope('https://repo.maven.apache.org') + ) .get( - '/maven2/io/get-coursier/sbt-coursier_2.12_1.0/2.0.0-RC6-6/sbt-coursier-2.0.0-RC6-6.pom', + '/io/get-coursier/sbt-coursier_2.12_1.0/2.0.0-RC6-6/sbt-coursier-2.0.0-RC6-6.pom', ) .reply( 200, @@ -160,64 +264,29 @@ describe('modules/datasource/sbt-plugin/index', () => { </scm> </project> `, - ); - }); - - // TODO: fix mocks - afterEach(() => httpMock.clear(false)); - - it('returns null in case of errors', async () => { - expect( - await getPkgReleases({ - versioning: mavenVersioning.id, - datasource: SbtPluginDatasource.id, - packageName: 'org.scalatest:scalatest', - registryUrls: ['https://failed_repo/maven'], - }), - ).toBeNull(); - expect( - await getPkgReleases({ - versioning: mavenVersioning.id, - datasource: SbtPluginDatasource.id, - packageName: 'org.scalatest:scalaz', - registryUrls: [], - }), - ).toBeNull(); - }); - - it('fetches sbt plugins', async () => { - expect( - await getPkgReleases({ - versioning: mavenVersioning.id, - datasource: SbtPluginDatasource.id, - packageName: 'org.foundweekends:sbt-bintray', - registryUrls: [], - }), - ).toEqual({ - dependencyUrl: - 'https://repo.maven.apache.org/maven2/org/foundweekends/sbt-bintray', - registryUrl: 'https://repo.maven.apache.org/maven2', - releases: [{ version: '0.5.5' }], - }); - }); + ) - it('fetches sbt plugins 2', async () => { - expect( - await getPkgReleases({ - versioning: mavenVersioning.id, - datasource: SbtPluginDatasource.id, - packageName: 'org.foundweekends:sbt-bintray_2.12', - registryUrls: [], - }), - ).toEqual({ - dependencyUrl: - 'https://repo.maven.apache.org/maven2/org/foundweekends/sbt-bintray', - registryUrl: 'https://repo.maven.apache.org/maven2', - releases: [{ version: '0.5.5' }], - }); - }); + .get('/io/get-coursier/sbt-coursier/') + .reply(404) + .get('/io/get-coursier/sbt-coursier_2.10_0.13/') + .reply(404) + .get('/io/get-coursier/sbt-coursier_2.12_1.0.0-M5/') + .reply(404) + .get('/io/get-coursier/sbt-coursier_2.12_1.0.0-M6/') + .reply(404) + .get( + '/io/get-coursier/sbt-coursier_2.10_0.13/2.0.0-RC6-6/sbt-coursier_2.10_0.13-2.0.0-RC6-6.pom', + ) + .reply(404) + .get( + '/io/get-coursier/sbt-coursier_2.10_0.13/2.0.0-RC6-6/sbt-coursier-2.0.0-RC6-6.pom', + ) + .reply(404) + .get( + '/io/get-coursier/sbt-coursier_2.12_1.0/2.0.0-RC6-6/sbt-coursier_2.12_1.0-2.0.0-RC6-6.pom', + ) + .reply(404); - it('extracts URL from Maven POM file', async () => { expect( await getPkgReleases({ versioning: mavenVersioning.id,