Avoid deprecated methods in tests.

This commit is contained in:
Fabio Niephaus 2024-02-13 15:38:39 +01:00
parent 2408275e34
commit 6df9f698c6
No known key found for this signature in database
GPG Key ID: F21CF5275F31DFD6
2 changed files with 60 additions and 55 deletions

View File

@ -101,14 +101,14 @@ describe('dependency cache', () => {
}) })
it('throws error if unsupported package manager specified', () => { it('throws error if unsupported package manager specified', () => {
return expect(restore('ant')).rejects.toThrowError( return expect(restore('ant')).rejects.toThrow(
'unknown package manager specified: ant' 'unknown package manager specified: ant'
) )
}) })
describe('for maven', () => { describe('for maven', () => {
it('throws error if no pom.xml found', async () => { it('throws error if no pom.xml found', async () => {
await expect(restore('maven')).rejects.toThrowError( await expect(restore('maven')).rejects.toThrow(
`No file in ${projectRoot( `No file in ${projectRoot(
workspace workspace
)} matched to [**/pom.xml], make sure you have checked out the target repository` )} matched to [**/pom.xml], make sure you have checked out the target repository`
@ -118,14 +118,14 @@ describe('dependency cache', () => {
createFile(join(workspace, 'pom.xml')) createFile(join(workspace, 'pom.xml'))
await restore('maven') await restore('maven')
expect(spyCacheRestore).toBeCalled() expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith('maven cache is not found') expect(spyInfo).toHaveBeenCalledWith('maven cache is not found')
}) })
}) })
describe('for gradle', () => { describe('for gradle', () => {
it('throws error if no build.gradle found', async () => { it('throws error if no build.gradle found', async () => {
await expect(restore('gradle')).rejects.toThrowError( await expect(restore('gradle')).rejects.toThrow(
`No file in ${projectRoot( `No file in ${projectRoot(
workspace workspace
)} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt], make sure you have checked out the target repository` )} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt], make sure you have checked out the target repository`
@ -135,17 +135,17 @@ describe('dependency cache', () => {
createFile(join(workspace, 'build.gradle')) createFile(join(workspace, 'build.gradle'))
await restore('gradle') await restore('gradle')
expect(spyCacheRestore).toBeCalled() expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith('gradle cache is not found') expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found')
}) })
it('downloads cache based on build.gradle.kts', async () => { it('downloads cache based on build.gradle.kts', async () => {
createFile(join(workspace, 'build.gradle.kts')) createFile(join(workspace, 'build.gradle.kts'))
await restore('gradle') await restore('gradle')
expect(spyCacheRestore).toBeCalled() expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith('gradle cache is not found') expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found')
}) })
}) })
it('downloads cache based on buildSrc/Versions.kt', async () => { it('downloads cache based on buildSrc/Versions.kt', async () => {
@ -153,13 +153,13 @@ describe('dependency cache', () => {
createFile(join(workspace, 'buildSrc', 'Versions.kt')) createFile(join(workspace, 'buildSrc', 'Versions.kt'))
await restore('gradle') await restore('gradle')
expect(spyCacheRestore).toBeCalled() expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith('gradle cache is not found') expect(spyInfo).toHaveBeenCalledWith('gradle cache is not found')
}) })
describe('for sbt', () => { describe('for sbt', () => {
it('throws error if no build.sbt found', async () => { it('throws error if no build.sbt found', async () => {
await expect(restore('sbt')).rejects.toThrowError( await expect(restore('sbt')).rejects.toThrow(
`No file in ${projectRoot( `No file in ${projectRoot(
workspace workspace
)} matched to [**/*.sbt,**/project/build.properties,**/project/**.{scala,sbt}], make sure you have checked out the target repository` )} matched to [**/*.sbt,**/project/build.properties,**/project/**.{scala,sbt}], make sure you have checked out the target repository`
@ -169,9 +169,9 @@ describe('dependency cache', () => {
createFile(join(workspace, 'build.sbt')) createFile(join(workspace, 'build.sbt'))
await restore('sbt') await restore('sbt')
expect(spyCacheRestore).toBeCalled() expect(spyCacheRestore).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith('sbt cache is not found') expect(spyInfo).toHaveBeenCalledWith('sbt cache is not found')
}) })
}) })
}) })
@ -191,7 +191,7 @@ describe('dependency cache', () => {
}) })
it('throws error if unsupported package manager specified', () => { it('throws error if unsupported package manager specified', () => {
return expect(save('ant')).rejects.toThrowError( return expect(save('ant')).rejects.toThrow(
'unknown package manager specified: ant' 'unknown package manager specified: ant'
) )
}) })
@ -201,10 +201,10 @@ describe('dependency cache', () => {
createStateForMissingBuildFile() createStateForMissingBuildFile()
await save('maven') await save('maven')
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalled() expect(spyInfo).toHaveBeenCalled()
expect(spyInfo).toBeCalledWith( expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/) expect.stringMatching(/^Cache saved with the key:.*/)
) )
}) })
@ -225,24 +225,26 @@ describe('dependency cache', () => {
it('uploads cache even if no pom.xml found', async () => { it('uploads cache even if no pom.xml found', async () => {
createStateForMissingBuildFile() createStateForMissingBuildFile()
await save('maven') await save('maven')
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
}) })
it('does not upload cache if no restore run before', async () => { it('does not upload cache if no restore run before', async () => {
createFile(join(workspace, 'pom.xml')) createFile(join(workspace, 'pom.xml'))
await save('maven') await save('maven')
expect(spyCacheSave).not.toBeCalled() expect(spyCacheSave).not.toHaveBeenCalled()
expect(spyWarning).toBeCalledWith('Error retrieving key from state.') expect(spyWarning).toHaveBeenCalledWith(
'Error retrieving key from state.'
)
}) })
it('uploads cache', async () => { it('uploads cache', async () => {
createFile(join(workspace, 'pom.xml')) createFile(join(workspace, 'pom.xml'))
createStateForSuccessfulRestore() createStateForSuccessfulRestore()
await save('maven') await save('maven')
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith( expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/) expect.stringMatching(/^Cache saved with the key:.*/)
) )
}) })
@ -252,24 +254,26 @@ describe('dependency cache', () => {
createStateForMissingBuildFile() createStateForMissingBuildFile()
await save('gradle') await save('gradle')
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
}) })
it('does not upload cache if no restore run before', async () => { it('does not upload cache if no restore run before', async () => {
createFile(join(workspace, 'build.gradle')) createFile(join(workspace, 'build.gradle'))
await save('gradle') await save('gradle')
expect(spyCacheSave).not.toBeCalled() expect(spyCacheSave).not.toHaveBeenCalled()
expect(spyWarning).toBeCalledWith('Error retrieving key from state.') expect(spyWarning).toHaveBeenCalledWith(
'Error retrieving key from state.'
)
}) })
it('uploads cache based on build.gradle', async () => { it('uploads cache based on build.gradle', async () => {
createFile(join(workspace, 'build.gradle')) createFile(join(workspace, 'build.gradle'))
createStateForSuccessfulRestore() createStateForSuccessfulRestore()
await save('gradle') await save('gradle')
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith( expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/) expect.stringMatching(/^Cache saved with the key:.*/)
) )
}) })
@ -278,9 +282,9 @@ describe('dependency cache', () => {
createStateForSuccessfulRestore() createStateForSuccessfulRestore()
await save('gradle') await save('gradle')
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith( expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/) expect.stringMatching(/^Cache saved with the key:.*/)
) )
}) })
@ -290,9 +294,9 @@ describe('dependency cache', () => {
createStateForSuccessfulRestore() createStateForSuccessfulRestore()
await save('gradle') await save('gradle')
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith( expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/) expect.stringMatching(/^Cache saved with the key:.*/)
) )
}) })
@ -301,24 +305,26 @@ describe('dependency cache', () => {
it('uploads cache even if no build.sbt found', async () => { it('uploads cache even if no build.sbt found', async () => {
createStateForMissingBuildFile() createStateForMissingBuildFile()
await save('sbt') await save('sbt')
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
}) })
it('does not upload cache if no restore run before', async () => { it('does not upload cache if no restore run before', async () => {
createFile(join(workspace, 'build.sbt')) createFile(join(workspace, 'build.sbt'))
await save('sbt') await save('sbt')
expect(spyCacheSave).not.toBeCalled() expect(spyCacheSave).not.toHaveBeenCalled()
expect(spyWarning).toBeCalledWith('Error retrieving key from state.') expect(spyWarning).toHaveBeenCalledWith(
'Error retrieving key from state.'
)
}) })
it('uploads cache', async () => { it('uploads cache', async () => {
createFile(join(workspace, 'build.sbt')) createFile(join(workspace, 'build.sbt'))
createStateForSuccessfulRestore() createStateForSuccessfulRestore()
await save('sbt') await save('sbt')
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
expect(spyInfo).toBeCalledWith( expect(spyInfo).toHaveBeenCalledWith(
expect.stringMatching(/^Cache saved with the key:.*/) expect.stringMatching(/^Cache saved with the key:.*/)
) )
}) })

View File

@ -27,7 +27,6 @@
import {run as cleanup} from '../src/cleanup' import {run as cleanup} from '../src/cleanup'
import * as core from '@actions/core' import * as core from '@actions/core'
import * as cache from '@actions/cache' import * as cache from '@actions/cache'
import * as util from '../src/utils'
describe('cleanup', () => { describe('cleanup', () => {
let spyWarning: jest.SpyInstance<void, Parameters<typeof core.warning>> let spyWarning: jest.SpyInstance<void, Parameters<typeof core.warning>>
@ -62,8 +61,8 @@ describe('cleanup', () => {
return name === 'cache' ? 'gradle' : '' return name === 'cache' ? 'gradle' : ''
}) })
await cleanup() await cleanup()
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
expect(spyWarning).not.toBeCalled() expect(spyWarning).not.toHaveBeenCalled()
}) })
it('does not fail even though the save process throws error', async () => { it('does not fail even though the save process throws error', async () => {
@ -74,7 +73,7 @@ describe('cleanup', () => {
return name === 'cache' ? 'gradle' : '' return name === 'cache' ? 'gradle' : ''
}) })
await cleanup() await cleanup()
expect(spyCacheSave).toBeCalled() expect(spyCacheSave).toHaveBeenCalled()
}) })
}) })