import { codeBlock } from 'common-tags'; import { Fixtures } from '~test/fixtures.ts'; import * as httpMock from '~test/http-mock.ts'; import { regEx } from '../../../util/regex.ts'; import * as mavenVersioning from '../../versioning/maven/index.ts'; import { getPkgReleases } from '../index.ts'; import { MAVEN_REPO } from '../maven/common.ts'; import { extractPageLinks } from '../sbt-package/util.ts'; import { SbtPluginDatasource } from './index.ts'; const mavenIndexHtml = Fixtures.get(`maven-index.html`); const sbtPluginIndex = Fixtures.get(`sbt-plugins-index.html`); describe('modules/datasource/sbt-plugin/index', () => { it('parses Maven index directory', () => { expect( extractPageLinks(mavenIndexHtml, (x) => regEx(/^\.+/).test(x) ? null : x, ), ).toEqual([ 'autofix-3.0.6_2.11', 'sbt-scalatest_2.12_1.0', 'scalatest', 'scalatest-app_native0.4_3', 'scalatest_2.12', 'scalatest_2.13', 'scalatest_2.13.0-RC1', 'scalatest_3', 'scalatest_sjs1.0.0-M7_2.13.0-RC2', 'test-interface', ]); }); it('parses sbt index directory', () => { expect( extractPageLinks(sbtPluginIndex, (x) => regEx(/^\.+/).test(x) ? null : x, ), ).toEqual([ 'au.com.onegeek', 'ch', 'com.github.DavidPerezIngeniero', 'org.portable-scala', 'scalajs-react-interface', 'uk.co.josephearl', 'woshilaiceshide', ]); }); it('uses proper hostType', () => { const ds = new SbtPluginDatasource(); expect(ds).toMatchObject({ id: SbtPluginDatasource.id, http: { hostType: 'sbt' }, }); }); describe('getPkgReleases', () => { 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://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); await expect( getPkgReleases({ versioning: mavenVersioning.id, datasource: SbtPluginDatasource.id, packageName: 'org.scalatest:scalatest', registryUrls: ['https://failed_repo/maven'], }), ).resolves.toBeNull(); await expect( getPkgReleases({ versioning: mavenVersioning.id, datasource: SbtPluginDatasource.id, packageName: 'org.scalatest:scalaz', registryUrls: [], }), ).resolves.toBeNull(); }); it('fetches sbt plugins', async () => { httpMock .scope('https://repo.maven.apache.org/maven2/') .get('/org/foundweekends/sbt-bintray/') .reply( 200, codeBlock`
../
scala_2.12/`, ) .get('/org/foundweekends/sbt-bintray/scala_2.12/') .reply( 200, codeBlock`
../
sbt_1.0/`, ) .get('/org/foundweekends/sbt-bintray/scala_2.12/sbt_1.0/') .reply( 200, codeBlock`
../
0.5.5/`, ); httpMock .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); await expect( getPkgReleases({ versioning: mavenVersioning.id, datasource: SbtPluginDatasource.id, packageName: 'org.foundweekends:sbt-bintray', registryUrls: [], }), ).resolves.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/maven2/') .get('/org/foundweekends/sbt-bintray/') .reply( 200, codeBlock`
../
scala_2.12/`, ) .get('/org/foundweekends/sbt-bintray/scala_2.12/') .reply( 200, codeBlock`
../
sbt_1.0/`, ) .get('/org/foundweekends/sbt-bintray/scala_2.12/sbt_1.0/') .reply( 200, codeBlock`
../
0.5.5/`, ); httpMock .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); await expect( getPkgReleases({ versioning: mavenVersioning.id, datasource: SbtPluginDatasource.id, packageName: 'org.foundweekends:sbt-bintray_2.12', registryUrls: [], }), ).resolves.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` ../ sbt-coursier_2.10_0.13/ sbt-coursier_2.12_1.0/ sbt-coursier_2.12_1.0.0-M5/ sbt-coursier_2.12_1.0.0-M6/ `, ) .get('/io/get-coursier/sbt-coursier_2.12_1.0/') .reply( 200, codeBlock` 2.0.0-RC2/ 2.0.0-RC6-1/ 2.0.0-RC6-2/ 2.0.0-RC6-6/ `, ) .get( '/io/get-coursier/sbt-coursier_2.12_1.0/2.0.0-RC6-6/sbt-coursier-2.0.0-RC6-6.pom', ) .reply( 200, codeBlock`