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' ,
distributionName => {
const distribution = getJavaDistribution ( distributionName , {
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
)
)( 'accepts %s with java-package %s' , ( distributionName , packageType ) => {
expect (
getJavaDistribution (
distributionName ,
installerOptions ( packageType as string )
)
). not . toBeNull ();
});
it . each ( Object . entries ( JAVA_PACKAGE_CAPABILITIES ))(
'rejects unsupported java-package values for %s' ,
( distributionName , packageTypes ) => {
expect (() =>
getJavaDistribution ( distributionName , installerOptions ( 'jdk+typo' ))
). toThrow (
`Java package 'jdk+typo' is not supported for distribution ' ${ distributionName } '. Supported package types: ${ packageTypes . join ( ', ' ) } .`
);
}
);
2026-07-28 18:39:15 -04:00
it ( "rejects java-package 'jdk+jmods' for non-Temurin distributions" , () => {
expect (() =>
2026-07-29 00:50:01 -04:00
getJavaDistribution ( 'zulu' , installerOptions ( 'jdk+jmods' ))
2026-07-28 18:39:15 -04:00
). 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
it . each ([ '8' , '23.x' , '23.0.1.1' , '<24' ])(
"rejects Temurin java-package 'jdk+jmods' for version %s" ,
version => {
expect (() =>
getJavaDistribution (
JavaDistribution . Temurin ,
installerOptions ( 'jdk+jmods' , version )
)
). toThrow (
`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 } '.`
);
}
);
it . each ([ '24' , '24.0.1.1' , '25-ea' , '>=21' , 'latest' ])(
"accepts Temurin java-package 'jdk+jmods' for version %s" ,
version => {
expect (
getJavaDistribution (
JavaDistribution . Temurin ,
installerOptions ( 'jdk+jmods' , version )
)
). not . toBeNull ();
}
);
it ( 'preserves unsupported distribution handling' , () => {
expect (
getJavaDistribution (
'not-a-distribution' ,
installerOptions ( 'not-a-package' )
)
). toBeNull ();
});
2026-07-29 15:46:29 -04:00
it . each ([
[ 'amd64' , 'x64' ],
[ 'ia32' , 'x86' ],
[ 'arm64' , 'aarch64' ]
])( 'passes normalized architecture %s as %s' , ( input , expected ) => {
const normalized = getJavaDistribution ( JavaDistribution . JdkFile , {
... installerOptions ( 'jdk' ),
architecture : input
});
expect ( normalized ! [ 'architecture' ]). toBe ( expected );
});
it ( 'uses the runner architecture when the input is empty' , () => {
const distribution = getJavaDistribution ( JavaDistribution . Temurin , {
... installerOptions ( 'jdk' ),
architecture : ''
});
const expected = normalizeArchitecture ( os . arch ());
expect ( distribution ! [ 'architecture' ]). toBe ( expected );
});
it ( 'rejects an unsupported combination before creating an HTTP client' , () => {
expect (() =>
getJavaDistribution ( JavaDistribution . Oracle , {
... installerOptions ( 'jdk' ),
architecture : 'x86'
})
). toThrow ( /does not support operating system/ );
});
2026-07-28 18:39:15 -04:00
});