Add test for explicit Gradle Wrapper passing

Signed-off-by: Anders Fischer-Nielsen <andersfischern@me.com>
This commit is contained in:
Anders Fischer-Nielsen 2022-09-12 13:50:06 +02:00
parent bf387dd8b2
commit 738cf2c7af
No known key found for this signature in database

View file

@ -92,6 +92,36 @@ test('will use Gradle Wrapper for cleanup if specified', async () => {
expect(fs.existsSync(gradleCurrent)).toBe(true)
})
test('will use Gradle Wrapper with specified Gradle executable for cleanup if specified', async () => {
const projectRoot = prepareTestProject()
const gradleUserHome = path.resolve(projectRoot, 'HOME')
const tmpDir = path.resolve(projectRoot, 'tmp')
const cacheCleaner = new CacheCleaner(gradleUserHome, tmpDir, 'wrapper', './gradlew')
// Initialize HOME with 2 different Gradle versions
await runGradleWrapperBuild(projectRoot, 'build')
await runGradleBuild(projectRoot, 'build')
await cacheCleaner.prepare()
// Run with only one of these versions
await runGradleBuild(projectRoot, 'build')
const gradle733 = path.resolve(gradleUserHome, "caches/7.3.3")
const wrapper733 = path.resolve(gradleUserHome, "wrapper/dists/gradle-7.3.3-bin")
const gradleCurrent = path.resolve(gradleUserHome, "caches/7.5.1")
expect(fs.existsSync(gradle733)).toBe(true)
expect(fs.existsSync(wrapper733)).toBe(true)
expect(fs.existsSync(gradleCurrent)).toBe(true)
await cacheCleaner.forceCleanup()
expect(fs.existsSync(gradle733)).toBe(false)
expect(fs.existsSync(wrapper733)).toBe(false)
expect(fs.existsSync(gradleCurrent)).toBe(true)
})
async function runGradleBuild(projectRoot: string, args: string, version: string = '3.1'): Promise<void> {
const status31 = await exec.exec(`gradle -g HOME --no-daemon --build-cache -Dcommons_math3_version="${version}" ${args}`, [], {
cwd: projectRoot