From f94d96c5960376b101519a67509a93e9bf3e0243 Mon Sep 17 00:00:00 2001 From: Daniel Kennedy Date: Fri, 30 Jan 2026 09:44:37 -0500 Subject: [PATCH] test: fix deprecated Jest matchers for v30 - Replace toThrowError() with toThrow() - Replace toBeCalledWith() with toHaveBeenCalledWith() - Update snapshots --- .../__tests__/artifact-http-client.test.ts | 10 +++---- .../artifact/__tests__/get-artifact.test.ts | 6 ++-- .../__tests__/upload-artifact.test.ts | 2 +- packages/artifact/__tests__/util.test.ts | 8 +++--- .../__snapshots__/intoto.test.ts.snap | 2 +- .../__snapshots__/provenance.test.ts.snap | 2 +- packages/attest/__tests__/attest.test.ts | 2 +- packages/cache/__tests__/cacheUtils.test.ts | 2 +- packages/cache/__tests__/restoreCache.test.ts | 8 +++--- .../cache/__tests__/restoreCacheV2.test.ts | 8 +++--- packages/cache/__tests__/saveCache.test.ts | 4 +-- packages/cache/__tests__/saveCacheV2.test.ts | 4 +-- packages/exec/__tests__/exec.test.ts | 28 +++++++++---------- .../__tests__/__snapshots__/lib.test.ts.snap | 2 +- 14 files changed, 44 insertions(+), 44 deletions(-) diff --git a/packages/artifact/__tests__/artifact-http-client.test.ts b/packages/artifact/__tests__/artifact-http-client.test.ts index 84a50a6f..80e81890 100644 --- a/packages/artifact/__tests__/artifact-http-client.test.ts +++ b/packages/artifact/__tests__/artifact-http-client.test.ts @@ -192,7 +192,7 @@ describe('artifact-http-client', () => { name: 'artifact', version: 4 }) - }).rejects.toThrowError( + }).rejects.toThrow( 'Failed to make request after 5 attempts: Failed request: (500) Internal Server Error' ) expect(mockHttpClient).toHaveBeenCalledTimes(1) @@ -227,7 +227,7 @@ describe('artifact-http-client', () => { name: 'artifact', version: 4 }) - }).rejects.toThrowError( + }).rejects.toThrow( 'Received non-retryable error: Failed request: (401) Unauthorized' ) expect(mockHttpClient).toHaveBeenCalledTimes(1) @@ -271,7 +271,7 @@ describe('artifact-http-client', () => { name: 'artifact', 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' ) expect(mockHttpClient).toHaveBeenCalledTimes(1) @@ -306,7 +306,7 @@ describe('artifact-http-client', () => { name: 'artifact', version: 4 }) - }).rejects.toThrowError(new NetworkError('ENOTFOUND').message) + }).rejects.toThrow(new NetworkError('ENOTFOUND').message) expect(mockHttpClient).toHaveBeenCalledTimes(1) expect(mockPost).toHaveBeenCalledTimes(1) }) @@ -341,7 +341,7 @@ describe('artifact-http-client', () => { name: 'artifact', version: 4 }) - }).rejects.toThrowError(new UsageError().message) + }).rejects.toThrow(new UsageError().message) expect(mockHttpClient).toHaveBeenCalledTimes(1) expect(mockPost).toHaveBeenCalledTimes(1) }) diff --git a/packages/artifact/__tests__/get-artifact.test.ts b/packages/artifact/__tests__/get-artifact.test.ts index 025fd6a6..00c08297 100644 --- a/packages/artifact/__tests__/get-artifact.test.ts +++ b/packages/artifact/__tests__/get-artifact.test.ts @@ -134,7 +134,7 @@ describe('get-artifact', () => { fixtures.token ) - expect(response).rejects.toThrowError(ArtifactNotFoundError) + expect(response).rejects.toThrow(ArtifactNotFoundError) }) it('should fail if non-200 response', async () => { @@ -155,7 +155,7 @@ describe('get-artifact', () => { 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) - expect(response).rejects.toThrowError(ArtifactNotFoundError) + expect(response).rejects.toThrow(ArtifactNotFoundError) }) it('should fail if non-200 response', async () => { diff --git a/packages/artifact/__tests__/upload-artifact.test.ts b/packages/artifact/__tests__/upload-artifact.test.ts index 20a42881..60be6d67 100644 --- a/packages/artifact/__tests__/upload-artifact.test.ts +++ b/packages/artifact/__tests__/upload-artifact.test.ts @@ -132,7 +132,7 @@ describe('upload-artifact', () => { fixtures.inputs.files, 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 () => { diff --git a/packages/artifact/__tests__/util.test.ts b/packages/artifact/__tests__/util.test.ts index daedd156..4109f455 100644 --- a/packages/artifact/__tests__/util.test.ts +++ b/packages/artifact/__tests__/util.test.ts @@ -26,7 +26,7 @@ describe('get-backend-ids-from-token', () => { 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwic2NwIjoiQWN0aW9ucy5FeGFtcGxlIEFjdGlvbnMuQW5vdGhlckV4YW1wbGU6dGVzdCIsImlhdCI6MTUxNjIzOTAyMn0.K0IEoULZteGevF38G94xiaA8zcZ5UlKWfGfqE6q3dhw' ) - expect(util.getBackendIdsFromToken).toThrowError( + expect(util.getBackendIdsFromToken).toThrow( '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' ) - expect(util.getBackendIdsFromToken).toThrowError( + expect(util.getBackendIdsFromToken).toThrow( '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', () => { 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", () => { @@ -56,7 +56,7 @@ describe('get-backend-ids-from-token', () => { 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c' ) - expect(util.getBackendIdsFromToken).toThrowError( + expect(util.getBackendIdsFromToken).toThrow( 'Failed to get backend IDs: The provided JWT token is invalid' ) }) diff --git a/packages/attest/__tests__/__snapshots__/intoto.test.ts.snap b/packages/attest/__tests__/__snapshots__/intoto.test.ts.snap index 0d3be79a..4cb05873 100644 --- a/packages/attest/__tests__/__snapshots__/intoto.test.ts.snap +++ b/packages/attest/__tests__/__snapshots__/intoto.test.ts.snap @@ -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`] = ` { diff --git a/packages/attest/__tests__/__snapshots__/provenance.test.ts.snap b/packages/attest/__tests__/__snapshots__/provenance.test.ts.snap index f4b22123..8309f53c 100644 --- a/packages/attest/__tests__/__snapshots__/provenance.test.ts.snap +++ b/packages/attest/__tests__/__snapshots__/provenance.test.ts.snap @@ -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`] = ` { diff --git a/packages/attest/__tests__/attest.test.ts b/packages/attest/__tests__/attest.test.ts index d8b07163..19119d3e 100644 --- a/packages/attest/__tests__/attest.test.ts +++ b/packages/attest/__tests__/attest.test.ts @@ -8,7 +8,7 @@ describe('attest', () => { predicate: {bar: 'baz'}, token: 'token' } - expect(attest(options)).rejects.toThrowError( + expect(attest(options)).rejects.toThrow( 'Must provide either subjectName and subjectDigest or subjects' ) }) diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index fad045b4..0d98cdb6 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -30,7 +30,7 @@ test('unlinkFile unlinks file', async () => { }) test('assertDefined throws if undefined', () => { - expect(() => cacheUtils.assertDefined('test', undefined)).toThrowError() + expect(() => cacheUtils.assertDefined('test', undefined)).toThrow() }) test('assertDefined returns value', () => { diff --git a/packages/cache/__tests__/restoreCache.test.ts b/packages/cache/__tests__/restoreCache.test.ts index 4b5c6f86..db73c691 100644 --- a/packages/cache/__tests__/restoreCache.test.ts +++ b/packages/cache/__tests__/restoreCache.test.ts @@ -29,7 +29,7 @@ beforeAll(() => { test('restore with no path should fail', async () => { const paths: string[] = [] 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` ) }) @@ -38,7 +38,7 @@ test('restore with too many keys should fail', async () => { const paths = ['node_modules'] const key = 'node-test' 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.` ) }) @@ -46,7 +46,7 @@ test('restore with too many keys should fail', async () => { test('restore with large key should fail', async () => { const paths = ['node_modules'] 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.` ) }) @@ -54,7 +54,7 @@ test('restore with large key should fail', async () => { test('restore with invalid key should fail', async () => { const paths = ['node_modules'] 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.` ) }) diff --git a/packages/cache/__tests__/restoreCacheV2.test.ts b/packages/cache/__tests__/restoreCacheV2.test.ts index 421069db..f2f30ae2 100644 --- a/packages/cache/__tests__/restoreCacheV2.test.ts +++ b/packages/cache/__tests__/restoreCacheV2.test.ts @@ -44,7 +44,7 @@ afterEach(() => { test('restore with no path should fail', async () => { const paths: string[] = [] 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` ) }) @@ -53,7 +53,7 @@ test('restore with too many keys should fail', async () => { const paths = ['node_modules'] const key = 'node-test' 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.` ) }) @@ -61,7 +61,7 @@ test('restore with too many keys should fail', async () => { test('restore with large key should fail', async () => { const paths = ['node_modules'] 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.` ) }) @@ -69,7 +69,7 @@ test('restore with large key should fail', async () => { test('restore with invalid key should fail', async () => { const paths = ['node_modules'] 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.` ) }) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index e0fd7f20..34a25e63 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__tests__/saveCache.test.ts @@ -40,7 +40,7 @@ beforeAll(() => { test('save with missing input should fail', async () => { const paths: string[] = [] 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` ) }) @@ -342,7 +342,7 @@ test('save with non existing path should not save cache', async () => { jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => { 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.` ) }) diff --git a/packages/cache/__tests__/saveCacheV2.test.ts b/packages/cache/__tests__/saveCacheV2.test.ts index 1916e4f8..d5a400b1 100644 --- a/packages/cache/__tests__/saveCacheV2.test.ts +++ b/packages/cache/__tests__/saveCacheV2.test.ts @@ -54,7 +54,7 @@ test('save with missing input should fail', async () => { const paths: string[] = [] 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` ) }) @@ -581,7 +581,7 @@ test('save with non existing path should not save cache using v2 saveCache', asy jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => { 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.` ) }) diff --git a/packages/exec/__tests__/exec.test.ts b/packages/exec/__tests__/exec.test.ts index b048aa36..4265f7cc 100644 --- a/packages/exec/__tests__/exec.test.ts +++ b/packages/exec/__tests__/exec.test.ts @@ -55,12 +55,12 @@ describe('@actions/exec', () => { expect(exitCode).toBe(0) if (IS_WINDOWS) { - expect(outstream.write).toBeCalledWith( + expect(outstream.write).toHaveBeenCalledWith( `[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 { - expect(outstream.write).toBeCalledWith( + expect(outstream.write).toHaveBeenCalledWith( `[command]${toolpath} -l -a${os.EOL}` ) } @@ -85,12 +85,12 @@ describe('@actions/exec', () => { expect(exitCode).toBe(0) if (IS_WINDOWS) { - expect(outstream.write).toBeCalledWith( + expect(outstream.write).toHaveBeenCalledWith( `[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 { - expect(outstream.write).toBeCalledWith( + expect(outstream.write).toHaveBeenCalledWith( `[command]${toolpath} -l -a${os.EOL}` ) } @@ -115,12 +115,12 @@ describe('@actions/exec', () => { expect(exitCode).toBe(0) if (IS_WINDOWS) { - expect(outstream.write).toBeCalledWith( + expect(outstream.write).toHaveBeenCalledWith( `[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 { - expect(outstream.write).toBeCalledWith( + expect(outstream.write).toHaveBeenCalledWith( `[command]${toolpath} -l -a${os.EOL}` ) } @@ -182,11 +182,11 @@ describe('@actions/exec', () => { expect(failed).toBe(true) if (IS_WINDOWS) { - expect(outstream.write).toBeCalledWith( + expect(outstream.write).toHaveBeenCalledWith( `[command]${toolpath} /c non-existent${os.EOL}` ) } else { - expect(outstream.write).toBeCalledWith( + expect(outstream.write).toHaveBeenCalledWith( `[command]${toolpath} -l non-existent${os.EOL}` ) } @@ -209,7 +209,7 @@ describe('@actions/exec', () => { ) expect(exitCode).toBe(0) - expect(outstream.write).toBeCalledWith( + expect(outstream.write).toHaveBeenCalledWith( Buffer.from('this is output to stderr') ) }) @@ -233,7 +233,7 @@ describe('@actions/exec', () => { }) expect(failed).toBe(true) - expect(errstream.write).toBeCalledWith( + expect(errstream.write).toHaveBeenCalledWith( Buffer.from('this is output to stderr') ) }) @@ -524,7 +524,7 @@ describe('@actions/exec', () => { const execOptions = getExecOptions() 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!` ) }) diff --git a/packages/github/__tests__/__snapshots__/lib.test.ts.snap b/packages/github/__tests__/__snapshots__/lib.test.ts.snap index a7f3608c..e0c249b7 100644 --- a/packages/github/__tests__/__snapshots__/lib.test.ts.snap +++ b/packages/github/__tests__/__snapshots__/lib.test.ts.snap @@ -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'"`;