Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: fix deprecated Jest matchers for v30
- Replace toThrowError() with toThrow()
- Replace toBeCalledWith() with toHaveBeenCalledWith()
- Update snapshots
  • Loading branch information
danwkennedy committed Jan 30, 2026
commit f94d96c5960376b101519a67509a93e9bf3e0243
10 changes: 5 additions & 5 deletions packages/artifact/__tests__/artifact-http-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
Expand Down Expand Up @@ -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)
})
Expand Down
6 changes: 3 additions & 3 deletions packages/artifact/__tests__/get-artifact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -155,7 +155,7 @@ describe('get-artifact', () => {
fixtures.token
)

expect(response).rejects.toThrowError(InvalidResponseError)
expect(response).rejects.toThrow(InvalidResponseError)
})
})

Expand Down Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/artifact/__tests__/upload-artifact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/artifact/__tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
})
Expand All @@ -38,15 +38,15 @@ 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'
)
})

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", () => {
Expand All @@ -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'
)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion packages/attest/__tests__/attest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/__tests__/cacheUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/cache/__tests__/restoreCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
)
})
Expand All @@ -38,23 +38,23 @@ 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.`
)
})

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.`
)
})

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.`
)
})
Expand Down
8 changes: 4 additions & 4 deletions packages/cache/__tests__/restoreCacheV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
)
})
Expand All @@ -53,23 +53,23 @@ 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.`
)
})

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.`
)
})

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.`
)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/cache/__tests__/saveCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
)
})
Expand Down Expand Up @@ -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.`
)
})
4 changes: 2 additions & 2 deletions packages/cache/__tests__/saveCacheV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
)
})
Expand Down Expand Up @@ -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.`
)
})
28 changes: 14 additions & 14 deletions packages/exec/__tests__/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@

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}`))

Check failure on line 61 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`

Check failure on line 61 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest, 20.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `␍⏎········Buffer.from(`hello${os.EOL}`)␍⏎······`

Check failure on line 61 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest-large, 20.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`

Check failure on line 61 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest, 24.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `␍⏎········Buffer.from(`hello${os.EOL}`)␍⏎······`

Check failure on line 61 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest-large, 24.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`

Check failure on line 61 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 24.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`
} else {
expect(outstream.write).toBeCalledWith(
expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} -l -a${os.EOL}`
)
}
Expand All @@ -85,12 +85,12 @@

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}`))

Check failure on line 91 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`

Check failure on line 91 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest, 20.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `␍⏎········Buffer.from(`hello${os.EOL}`)␍⏎······`

Check failure on line 91 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest-large, 20.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`

Check failure on line 91 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest, 24.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `␍⏎········Buffer.from(`hello${os.EOL}`)␍⏎······`

Check failure on line 91 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest-large, 24.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`

Check failure on line 91 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 24.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`
} else {
expect(outstream.write).toBeCalledWith(
expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} -l -a${os.EOL}`
)
}
Expand All @@ -115,12 +115,12 @@

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}`))

Check failure on line 121 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`

Check failure on line 121 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest, 20.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `␍⏎········Buffer.from(`hello${os.EOL}`)␍⏎······`

Check failure on line 121 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest-large, 20.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`

Check failure on line 121 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (windows-latest, 24.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `␍⏎········Buffer.from(`hello${os.EOL}`)␍⏎······`

Check failure on line 121 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (macos-latest-large, 24.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`

Check failure on line 121 in packages/exec/__tests__/exec.test.ts

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 24.x)

Replace `Buffer.from(`hello${os.EOL}`)` with `⏎········Buffer.from(`hello${os.EOL}`)⏎······`
} else {
expect(outstream.write).toBeCalledWith(
expect(outstream.write).toHaveBeenCalledWith(
`[command]${toolpath} -l -a${os.EOL}`
)
}
Expand Down Expand Up @@ -182,11 +182,11 @@

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}`
)
}
Expand All @@ -209,7 +209,7 @@
)

expect(exitCode).toBe(0)
expect(outstream.write).toBeCalledWith(
expect(outstream.write).toHaveBeenCalledWith(
Buffer.from('this is output to stderr')
)
})
Expand All @@ -233,7 +233,7 @@
})

expect(failed).toBe(true)
expect(errstream.write).toBeCalledWith(
expect(errstream.write).toHaveBeenCalledWith(
Buffer.from('this is output to stderr')
)
})
Expand Down Expand Up @@ -524,7 +524,7 @@
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!`
)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/github/__tests__/__snapshots__/lib.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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'"`;
Loading