2026-07-28 18:39:15 -04:00
import { getJavaDistribution } from '../../src/distributions/distribution-factory.js' ;
2026-07-29 00:09:37 -04:00
import { RetryingHttpClient } from '../../src/retrying-http-client.js' ;
2026-07-29 00:50:01 -04:00
import {
JAVA_PACKAGE_CAPABILITIES ,
JavaDistribution
} from '../../src/distributions/package-types.js' ;
2026-07-29 15:46:29 -04:00
import os from 'os' ;
import { validateJavaPlatform } from '../../src/distributions/platform-types.js' ;
import { normalizeArchitecture } from '../../src/distributions/platform-types.js' ;
const supportedDistributionsOnCurrentPlatform = Object . values (
JavaDistribution
) . filter ( distributionName = > {
try {
validateJavaPlatform ( distributionName , process . platform , 'x64' , '25' ) ;
return distributionName !== JavaDistribution . JdkFile ;
} catch {
return false ;
}
} ) ;
2026-07-29 00:50:01 -04:00
const installerOptions = ( packageType : string , version = '25' ) = > ( {
version ,
architecture : 'x64' ,
packageType ,
checkLatest : false
} ) ;
2026-07-28 18:39:15 -04:00
describe ( 'getJavaDistribution' , ( ) = > {
2026-07-29 15:46:29 -04:00
it . each ( supportedDistributionsOnCurrentPlatform ) (
'uses the shared retrying HTTP client for %s' ,
2026-07-29 17:53:33 -04:00
async distributionName = > {
const distribution = await getJavaDistribution ( distributionName , {
2026-07-29 15:46:29 -04:00
version : '25' ,
architecture : 'x64' ,
packageType : 'jdk' ,
checkLatest : false
} ) ;
2026-07-29 00:09:37 -04:00
2026-07-29 15:46:29 -04:00
expect ( distribution ) . not . toBeNull ( ) ;
expect ( distribution ! [ 'http' ] ) . toBeInstanceOf ( RetryingHttpClient ) ;
}
) ;
2026-07-29 00:09:37 -04:00
2026-07-29 00:50:01 -04:00
it . each (
Object . entries ( JAVA_PACKAGE_CAPABILITIES ) . flatMap (
( [ distributionName , packageTypes ] ) = >
2026-07-29 15:46:29 -04:00
supportedDistributionsOnCurrentPlatform . includes (
distributionName as JavaDistribution
) || distributionName === JavaDistribution . JdkFile
? packageTypes . map ( packageType = > [ distributionName , packageType ] )
: [ ]
2026-07-29 00:50:01 -04:00
)
2026-07-29 17:53:33 -04:00
) (
'accepts %s with java-package %s' ,
async ( distributionName , packageType ) = > {
expect (
await getJavaDistribution (
distributionName ,
installerOptions ( packageType as string )
)
) . not . toBeNull ( ) ;
}
) ;
2026-07-29 00:50:01 -04:00
it . each ( Object . entries ( JAVA_PACKAGE_CAPABILITIES ) ) (
'rejects unsupported java-package values for %s' ,
2026-07-29 17:53:33 -04:00
async ( distributionName , packageTypes ) = > {
await expect (
2026-07-29 00:50:01 -04:00
getJavaDistribution ( distributionName , installerOptions ( 'jdk+typo' ) )
2026-07-29 17:53:33 -04:00
) . rejects . toThrow (
2026-07-29 00:50:01 -04:00
` Java package 'jdk+typo' is not supported for distribution ' ${ distributionName } '. Supported package types: ${ packageTypes . join ( ', ' ) } . `
) ;
}
) ;
2026-07-29 17:53:33 -04:00
it ( "rejects java-package 'jdk+jmods' for non-Temurin distributions" , async ( ) = > {
await expect (
2026-07-29 00:50:01 -04:00
getJavaDistribution ( 'zulu' , installerOptions ( 'jdk+jmods' ) )
2026-07-29 17:53:33 -04:00
) . rejects . toThrow (
2026-07-29 00:50:01 -04:00
"Java package 'jdk+jmods' is not supported for distribution 'zulu'. Supported package types: jdk, jre, jdk+fx, jre+fx, jdk+crac, jre+crac."
2026-07-28 18:39:15 -04:00
) ;
} ) ;
2026-07-29 00:50:01 -04:00
2026-10-02 00:09:56 -04:00
it . each ( [ '8' , '23.x' , '23.0.1.1' , '23.0.1.1+1' , '<24' ] ) (
2026-07-29 00:50:01 -04:00
"rejects Temurin java-package 'jdk+jmods' for version %s" ,
2026-07-29 17:53:33 -04:00
async version = > {
await expect (
2026-07-29 00:50:01 -04:00
getJavaDistribution (
JavaDistribution . Temurin ,
installerOptions ( 'jdk+jmods' , version )
)
2026-07-29 17:53:33 -04:00
) . rejects . toThrow (
2026-07-29 00:50:01 -04:00
` Java package 'jdk+jmods' is not supported for distribution 'temurin'. Supported package types: jdk, jre, jdk+jmods. Package 'jdk+jmods' requires Java 24 or later; requested version ' ${ version } '. `
) ;
}
) ;
2026-10-02 00:09:56 -04:00
it . each ( [ '24' , '24.0.1.1' , '25.0.4.1+1' , '25-ea' , '>=21' , 'latest' ] ) (
2026-07-29 00:50:01 -04:00
"accepts Temurin java-package 'jdk+jmods' for version %s" ,
2026-07-29 17:53:33 -04:00
async version = > {
2026-07-29 00:50:01 -04:00
expect (
2026-07-29 17:53:33 -04:00
await getJavaDistribution (
2026-07-29 00:50:01 -04:00
JavaDistribution . Temurin ,
installerOptions ( 'jdk+jmods' , version )
)
) . not . toBeNull ( ) ;
}
) ;
2026-07-29 17:53:33 -04:00
it ( 'preserves unsupported distribution handling' , async ( ) = > {
2026-07-29 00:50:01 -04:00
expect (
2026-07-29 17:53:33 -04:00
await getJavaDistribution (
2026-07-29 00:50:01 -04:00
'not-a-distribution' ,
installerOptions ( 'not-a-package' )
)
) . toBeNull ( ) ;
} ) ;
2026-07-29 15:46:29 -04:00
2026-07-31 15:48:18 -04:00
it . each ( [ 'adopt' , 'adopt-hotspot' , 'adopt-openj9' ] ) (
'does not support legacy Adopt distribution %s' ,
async distributionName = > {
expect (
await getJavaDistribution ( distributionName , installerOptions ( 'jdk' ) )
) . toBeNull ( ) ;
}
) ;
2026-07-29 15:46:29 -04:00
it . each ( [
[ 'amd64' , 'x64' ] ,
[ 'ia32' , 'x86' ] ,
[ 'arm64' , 'aarch64' ]
2026-07-29 17:53:33 -04:00
] ) ( 'passes normalized architecture %s as %s' , async ( input , expected ) = > {
const normalized = await getJavaDistribution ( JavaDistribution . JdkFile , {
2026-07-29 15:46:29 -04:00
. . . installerOptions ( 'jdk' ) ,
architecture : input
} ) ;
expect ( normalized ! [ 'architecture' ] ) . toBe ( expected ) ;
} ) ;
2026-07-29 17:53:33 -04:00
it ( 'uses the runner architecture when the input is empty' , async ( ) = > {
const distribution = await getJavaDistribution ( JavaDistribution . Temurin , {
2026-07-29 15:46:29 -04:00
. . . installerOptions ( 'jdk' ) ,
architecture : ''
} ) ;
const expected = normalizeArchitecture ( os . arch ( ) ) ;
expect ( distribution ! [ 'architecture' ] ) . toBe ( expected ) ;
} ) ;
2026-07-29 17:53:33 -04:00
it ( 'rejects an unsupported combination before creating an HTTP client' , async ( ) = > {
await expect (
2026-07-29 15:46:29 -04:00
getJavaDistribution ( JavaDistribution . Oracle , {
. . . installerOptions ( 'jdk' ) ,
architecture : 'x86'
} )
2026-07-29 17:53:33 -04:00
) . rejects . toThrow ( /does not support operating system/ ) ;
2026-07-29 15:46:29 -04:00
} ) ;
2026-07-28 18:39:15 -04:00
} ) ;