mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-07 18:03:16 +08:00
core: Add new utility method to extract AnnotationProperties from Error instances
This commit is contained in:
26
packages/core/__tests__/utils.test.ts
Normal file
26
packages/core/__tests__/utils.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import {toAnnotationProperties} from '../src/utils'
|
||||
|
||||
describe('@actions/core/src/utils', () => {
|
||||
describe('.toAnnotationProperties', () => {
|
||||
it('extracts title only from Error instance without a parseable stack', () => {
|
||||
const error = new TypeError('Test error')
|
||||
error.stack = ''
|
||||
expect(toAnnotationProperties(error)).toEqual({
|
||||
title: 'TypeError',
|
||||
file: undefined,
|
||||
startLine: undefined,
|
||||
startColumn: undefined
|
||||
})
|
||||
})
|
||||
|
||||
it('extracts AnnotationProperties from Error instance', () => {
|
||||
const error = new ReferenceError('Test error')
|
||||
expect(toAnnotationProperties(error)).toEqual({
|
||||
title: 'ReferenceError',
|
||||
file: expect.stringMatching(/utils\.test\.ts$/),
|
||||
startLine: expect.any(Number),
|
||||
startColumn: expect.any(Number)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user