test: fix deprecated Jest matchers for v30

- Replace toThrowError() with toThrow()
- Replace toBeCalledWith() with toHaveBeenCalledWith()
- Update snapshots
This commit is contained in:
Daniel Kennedy
2026-01-30 09:44:37 -05:00
parent 59d7acc324
commit f94d96c596
14 changed files with 44 additions and 44 deletions
@@ -192,7 +192,7 @@ describe('artifact-http-client', () => {
name: 'artifact', name: 'artifact',
version: 4 version: 4
}) })
}).rejects.toThrowError( }).rejects.toThrow(
'Failed to make request after 5 attempts: Failed request: (500) Internal Server Error' 'Failed to make request after 5 attempts: Failed request: (500) Internal Server Error'
) )
expect(mockHttpClient).toHaveBeenCalledTimes(1) expect(mockHttpClient).toHaveBeenCalledTimes(1)
@@ -227,7 +227,7 @@ describe('artifact-http-client', () => {
name: 'artifact', name: 'artifact',
version: 4 version: 4
}) })
}).rejects.toThrowError( }).rejects.toThrow(
'Received non-retryable error: Failed request: (401) Unauthorized' 'Received non-retryable error: Failed request: (401) Unauthorized'
) )
expect(mockHttpClient).toHaveBeenCalledTimes(1) expect(mockHttpClient).toHaveBeenCalledTimes(1)
@@ -271,7 +271,7 @@ describe('artifact-http-client', () => {
name: 'artifact', name: 'artifact',
version: 4 version: 4
}) })
}).rejects.toThrowError( }).rejects.toThrow(
'Failed to CreateArtifact: Received non-retryable error: Failed request: (409) Conflict: an artifact with this name already exists on the workflow run' 'Failed to CreateArtifact: Received non-retryable error: Failed request: (409) Conflict: an artifact with this name already exists on the workflow run'
) )
expect(mockHttpClient).toHaveBeenCalledTimes(1) expect(mockHttpClient).toHaveBeenCalledTimes(1)
@@ -306,7 +306,7 @@ describe('artifact-http-client', () => {
name: 'artifact', name: 'artifact',
version: 4 version: 4
}) })
}).rejects.toThrowError(new NetworkError('ENOTFOUND').message) }).rejects.toThrow(new NetworkError('ENOTFOUND').message)
expect(mockHttpClient).toHaveBeenCalledTimes(1) expect(mockHttpClient).toHaveBeenCalledTimes(1)
expect(mockPost).toHaveBeenCalledTimes(1) expect(mockPost).toHaveBeenCalledTimes(1)
}) })
@@ -341,7 +341,7 @@ describe('artifact-http-client', () => {
name: 'artifact', name: 'artifact',
version: 4 version: 4
}) })
}).rejects.toThrowError(new UsageError().message) }).rejects.toThrow(new UsageError().message)
expect(mockHttpClient).toHaveBeenCalledTimes(1) expect(mockHttpClient).toHaveBeenCalledTimes(1)
expect(mockPost).toHaveBeenCalledTimes(1) expect(mockPost).toHaveBeenCalledTimes(1)
}) })
@@ -134,7 +134,7 @@ describe('get-artifact', () => {
fixtures.token fixtures.token
) )
expect(response).rejects.toThrowError(ArtifactNotFoundError) expect(response).rejects.toThrow(ArtifactNotFoundError)
}) })
it('should fail if non-200 response', async () => { it('should fail if non-200 response', async () => {
@@ -155,7 +155,7 @@ describe('get-artifact', () => {
fixtures.token fixtures.token
) )
expect(response).rejects.toThrowError(InvalidResponseError) expect(response).rejects.toThrow(InvalidResponseError)
}) })
}) })
@@ -223,7 +223,7 @@ describe('get-artifact', () => {
const response = getArtifactInternal(fixtures.artifacts[0].name) const response = getArtifactInternal(fixtures.artifacts[0].name)
expect(response).rejects.toThrowError(ArtifactNotFoundError) expect(response).rejects.toThrow(ArtifactNotFoundError)
}) })
it('should fail if non-200 response', async () => { it('should fail if non-200 response', async () => {
@@ -132,7 +132,7 @@ describe('upload-artifact', () => {
fixtures.inputs.files, fixtures.inputs.files,
fixtures.inputs.rootDirectory fixtures.inputs.rootDirectory
) )
await expect(uploadResp).rejects.toThrowError(FilesNotFoundError) await expect(uploadResp).rejects.toThrow(FilesNotFoundError)
}) })
it('should reject if no backend IDs are found', async () => { it('should reject if no backend IDs are found', async () => {
+4 -4
View File
@@ -26,7 +26,7 @@ describe('get-backend-ids-from-token', () => {
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwic2NwIjoiQWN0aW9ucy5FeGFtcGxlIEFjdGlvbnMuQW5vdGhlckV4YW1wbGU6dGVzdCIsImlhdCI6MTUxNjIzOTAyMn0.K0IEoULZteGevF38G94xiaA8zcZ5UlKWfGfqE6q3dhw' 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwic2NwIjoiQWN0aW9ucy5FeGFtcGxlIEFjdGlvbnMuQW5vdGhlckV4YW1wbGU6dGVzdCIsImlhdCI6MTUxNjIzOTAyMn0.K0IEoULZteGevF38G94xiaA8zcZ5UlKWfGfqE6q3dhw'
) )
expect(util.getBackendIdsFromToken).toThrowError( expect(util.getBackendIdsFromToken).toThrow(
'Failed to get backend IDs: The provided JWT token is invalid' 'Failed to get backend IDs: The provided JWT token is invalid'
) )
}) })
@@ -38,7 +38,7 @@ describe('get-backend-ids-from-token', () => {
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwic2NwIjoiQWN0aW9ucy5FeGFtcGxlIEFjdGlvbnMuQW5vdGhlckV4YW1wbGU6dGVzdCBBY3Rpb25zLlJlc3VsdHM6Y2U3ZjU0YzctNjFjNy00YWFlLTg4N2YtMzBkYTQ3NWY1ZjFhIiwiaWF0IjoxNTE2MjM5MDIyfQ.7D0_LRfRFRZFImHQ7GxH2S6ZyFjjZ5U0ujjGCfle1XE' 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwic2NwIjoiQWN0aW9ucy5FeGFtcGxlIEFjdGlvbnMuQW5vdGhlckV4YW1wbGU6dGVzdCBBY3Rpb25zLlJlc3VsdHM6Y2U3ZjU0YzctNjFjNy00YWFlLTg4N2YtMzBkYTQ3NWY1ZjFhIiwiaWF0IjoxNTE2MjM5MDIyfQ.7D0_LRfRFRZFImHQ7GxH2S6ZyFjjZ5U0ujjGCfle1XE'
) )
expect(util.getBackendIdsFromToken).toThrowError( expect(util.getBackendIdsFromToken).toThrow(
'Failed to get backend IDs: The provided JWT token is invalid' 'Failed to get backend IDs: The provided JWT token is invalid'
) )
}) })
@@ -46,7 +46,7 @@ describe('get-backend-ids-from-token', () => {
it('should throw an error when the token is in an invalid format', () => { it('should throw an error when the token is in an invalid format', () => {
jest.spyOn(config, 'getRuntimeToken').mockReturnValue('token') jest.spyOn(config, 'getRuntimeToken').mockReturnValue('token')
expect(util.getBackendIdsFromToken).toThrowError('Invalid token specified') expect(util.getBackendIdsFromToken).toThrow('Invalid token specified')
}) })
it("should throw an error when the token doesn't have the right field", () => { it("should throw an error when the token doesn't have the right field", () => {
@@ -56,7 +56,7 @@ describe('get-backend-ids-from-token', () => {
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
) )
expect(util.getBackendIdsFromToken).toThrowError( expect(util.getBackendIdsFromToken).toThrow(
'Failed to get backend IDs: The provided JWT token is invalid' 'Failed to get backend IDs: The provided JWT token is invalid'
) )
}) })
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`buildIntotoStatement returns an intoto statement 1`] = ` exports[`buildIntotoStatement returns an intoto statement 1`] = `
{ {
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`provenance functions buildSLSAProvenancePredicate returns a provenance hydrated from an OIDC token 1`] = ` exports[`provenance functions buildSLSAProvenancePredicate returns a provenance hydrated from an OIDC token 1`] = `
{ {
+1 -1
View File
@@ -8,7 +8,7 @@ describe('attest', () => {
predicate: {bar: 'baz'}, predicate: {bar: 'baz'},
token: 'token' token: 'token'
} }
expect(attest(options)).rejects.toThrowError( expect(attest(options)).rejects.toThrow(
'Must provide either subjectName and subjectDigest or subjects' 'Must provide either subjectName and subjectDigest or subjects'
) )
}) })
+1 -1
View File
@@ -30,7 +30,7 @@ test('unlinkFile unlinks file', async () => {
}) })
test('assertDefined throws if undefined', () => { test('assertDefined throws if undefined', () => {
expect(() => cacheUtils.assertDefined('test', undefined)).toThrowError() expect(() => cacheUtils.assertDefined('test', undefined)).toThrow()
}) })
test('assertDefined returns value', () => { test('assertDefined returns value', () => {
+4 -4
View File
@@ -29,7 +29,7 @@ beforeAll(() => {
test('restore with no path should fail', async () => { test('restore with no path should fail', async () => {
const paths: string[] = [] const paths: string[] = []
const key = 'node-test' const key = 'node-test'
await expect(restoreCache(paths, key)).rejects.toThrowError( await expect(restoreCache(paths, key)).rejects.toThrow(
`Path Validation Error: At least one directory or file path is required` `Path Validation Error: At least one directory or file path is required`
) )
}) })
@@ -38,7 +38,7 @@ test('restore with too many keys should fail', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const key = 'node-test' const key = 'node-test'
const restoreKeys = [...Array(20).keys()].map(x => x.toString()) const restoreKeys = [...Array(20).keys()].map(x => x.toString())
await expect(restoreCache(paths, key, restoreKeys)).rejects.toThrowError( await expect(restoreCache(paths, key, restoreKeys)).rejects.toThrow(
`Key Validation Error: Keys are limited to a maximum of 10.` `Key Validation Error: Keys are limited to a maximum of 10.`
) )
}) })
@@ -46,7 +46,7 @@ test('restore with too many keys should fail', async () => {
test('restore with large key should fail', async () => { test('restore with large key should fail', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const key = 'foo'.repeat(512) // Over the 512 character limit const key = 'foo'.repeat(512) // Over the 512 character limit
await expect(restoreCache(paths, key)).rejects.toThrowError( await expect(restoreCache(paths, key)).rejects.toThrow(
`Key Validation Error: ${key} cannot be larger than 512 characters.` `Key Validation Error: ${key} cannot be larger than 512 characters.`
) )
}) })
@@ -54,7 +54,7 @@ test('restore with large key should fail', async () => {
test('restore with invalid key should fail', async () => { test('restore with invalid key should fail', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const key = 'comma,comma' const key = 'comma,comma'
await expect(restoreCache(paths, key)).rejects.toThrowError( await expect(restoreCache(paths, key)).rejects.toThrow(
`Key Validation Error: ${key} cannot contain commas.` `Key Validation Error: ${key} cannot contain commas.`
) )
}) })
+4 -4
View File
@@ -44,7 +44,7 @@ afterEach(() => {
test('restore with no path should fail', async () => { test('restore with no path should fail', async () => {
const paths: string[] = [] const paths: string[] = []
const key = 'node-test' const key = 'node-test'
await expect(restoreCache(paths, key)).rejects.toThrowError( await expect(restoreCache(paths, key)).rejects.toThrow(
`Path Validation Error: At least one directory or file path is required` `Path Validation Error: At least one directory or file path is required`
) )
}) })
@@ -53,7 +53,7 @@ test('restore with too many keys should fail', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const key = 'node-test' const key = 'node-test'
const restoreKeys = [...Array(20).keys()].map(x => x.toString()) const restoreKeys = [...Array(20).keys()].map(x => x.toString())
await expect(restoreCache(paths, key, restoreKeys)).rejects.toThrowError( await expect(restoreCache(paths, key, restoreKeys)).rejects.toThrow(
`Key Validation Error: Keys are limited to a maximum of 10.` `Key Validation Error: Keys are limited to a maximum of 10.`
) )
}) })
@@ -61,7 +61,7 @@ test('restore with too many keys should fail', async () => {
test('restore with large key should fail', async () => { test('restore with large key should fail', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const key = 'foo'.repeat(512) // Over the 512 character limit const key = 'foo'.repeat(512) // Over the 512 character limit
await expect(restoreCache(paths, key)).rejects.toThrowError( await expect(restoreCache(paths, key)).rejects.toThrow(
`Key Validation Error: ${key} cannot be larger than 512 characters.` `Key Validation Error: ${key} cannot be larger than 512 characters.`
) )
}) })
@@ -69,7 +69,7 @@ test('restore with large key should fail', async () => {
test('restore with invalid key should fail', async () => { test('restore with invalid key should fail', async () => {
const paths = ['node_modules'] const paths = ['node_modules']
const key = 'comma,comma' const key = 'comma,comma'
await expect(restoreCache(paths, key)).rejects.toThrowError( await expect(restoreCache(paths, key)).rejects.toThrow(
`Key Validation Error: ${key} cannot contain commas.` `Key Validation Error: ${key} cannot contain commas.`
) )
}) })
+2 -2
View File
@@ -40,7 +40,7 @@ beforeAll(() => {
test('save with missing input should fail', async () => { test('save with missing input should fail', async () => {
const paths: string[] = [] const paths: string[] = []
const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
await expect(saveCache(paths, primaryKey)).rejects.toThrowError( await expect(saveCache(paths, primaryKey)).rejects.toThrow(
`Path Validation Error: At least one directory or file path is required` `Path Validation Error: At least one directory or file path is required`
) )
}) })
@@ -342,7 +342,7 @@ test('save with non existing path should not save cache', async () => {
jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => { jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => {
return [] return []
}) })
await expect(saveCache([path], primaryKey)).rejects.toThrowError( await expect(saveCache([path], primaryKey)).rejects.toThrow(
`Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.` `Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.`
) )
}) })
+2 -2
View File
@@ -54,7 +54,7 @@ test('save with missing input should fail', async () => {
const paths: string[] = [] const paths: string[] = []
const key = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' const key = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43'
await expect(saveCache(paths, key)).rejects.toThrowError( await expect(saveCache(paths, key)).rejects.toThrow(
`Path Validation Error: At least one directory or file path is required` `Path Validation Error: At least one directory or file path is required`
) )
}) })
@@ -581,7 +581,7 @@ test('save with non existing path should not save cache using v2 saveCache', asy
jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => { jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => {
return [] return []
}) })
await expect(saveCache([path], key)).rejects.toThrowError( await expect(saveCache([path], key)).rejects.toThrow(
`Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.` `Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.`
) )
}) })
+14 -14
View File
@@ -55,12 +55,12 @@ describe('@actions/exec', () => {
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(outstream.write).toBeCalledWith( expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} /c echo hello${os.EOL}` `[command]${toolpath} /c echo hello${os.EOL}`
) )
expect(outstream.write).toBeCalledWith(Buffer.from(`hello${os.EOL}`)) expect(outstream.write).toHaveBeenCalledWith(Buffer.from(`hello${os.EOL}`))
} else { } else {
expect(outstream.write).toBeCalledWith( expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} -l -a${os.EOL}` `[command]${toolpath} -l -a${os.EOL}`
) )
} }
@@ -85,12 +85,12 @@ describe('@actions/exec', () => {
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(outstream.write).toBeCalledWith( expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} /c echo hello${os.EOL}` `[command]${toolpath} /c echo hello${os.EOL}`
) )
expect(outstream.write).toBeCalledWith(Buffer.from(`hello${os.EOL}`)) expect(outstream.write).toHaveBeenCalledWith(Buffer.from(`hello${os.EOL}`))
} else { } else {
expect(outstream.write).toBeCalledWith( expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} -l -a${os.EOL}` `[command]${toolpath} -l -a${os.EOL}`
) )
} }
@@ -115,12 +115,12 @@ describe('@actions/exec', () => {
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(outstream.write).toBeCalledWith( expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} /c echo hello${os.EOL}` `[command]${toolpath} /c echo hello${os.EOL}`
) )
expect(outstream.write).toBeCalledWith(Buffer.from(`hello${os.EOL}`)) expect(outstream.write).toHaveBeenCalledWith(Buffer.from(`hello${os.EOL}`))
} else { } else {
expect(outstream.write).toBeCalledWith( expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} -l -a${os.EOL}` `[command]${toolpath} -l -a${os.EOL}`
) )
} }
@@ -182,11 +182,11 @@ describe('@actions/exec', () => {
expect(failed).toBe(true) expect(failed).toBe(true)
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(outstream.write).toBeCalledWith( expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} /c non-existent${os.EOL}` `[command]${toolpath} /c non-existent${os.EOL}`
) )
} else { } else {
expect(outstream.write).toBeCalledWith( expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} -l non-existent${os.EOL}` `[command]${toolpath} -l non-existent${os.EOL}`
) )
} }
@@ -209,7 +209,7 @@ describe('@actions/exec', () => {
) )
expect(exitCode).toBe(0) expect(exitCode).toBe(0)
expect(outstream.write).toBeCalledWith( expect(outstream.write).toHaveBeenCalledWith(
Buffer.from('this is output to stderr') Buffer.from('this is output to stderr')
) )
}) })
@@ -233,7 +233,7 @@ describe('@actions/exec', () => {
}) })
expect(failed).toBe(true) expect(failed).toBe(true)
expect(errstream.write).toBeCalledWith( expect(errstream.write).toHaveBeenCalledWith(
Buffer.from('this is output to stderr') Buffer.from('this is output to stderr')
) )
}) })
@@ -524,7 +524,7 @@ describe('@actions/exec', () => {
const execOptions = getExecOptions() const execOptions = getExecOptions()
execOptions.cwd = 'nonexistent/path' execOptions.cwd = 'nonexistent/path'
await expect(exec.exec('ls', ['-all'], execOptions)).rejects.toThrowError( await expect(exec.exec('ls', ['-all'], execOptions)).rejects.toThrow(
`The cwd: ${execOptions.cwd} does not exist!` `The cwd: ${execOptions.cwd} does not exist!`
) )
}) })
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`@actions/context return error for context.repo when repository doesn't exist 1`] = `"context.repo requires a GITHUB_REPOSITORY environment variable like 'owner/repo'"`; exports[`@actions/context return error for context.repo when repository doesn't exist 1`] = `"context.repo requires a GITHUB_REPOSITORY environment variable like 'owner/repo'"`;