mirror of
https://github.com/actions/configure-pages.git
synced 2026-04-03 16:22:24 +00:00
Add error-utils helper and tests
This commit is contained in:
38
src/error-utils.test.js
Normal file
38
src/error-utils.test.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const { convertErrorToAnnotationProperties } = require('./error-utils')
|
||||
|
||||
describe('error-utils', () => {
|
||||
describe('convertErrorToAnnotationProperties', () => {
|
||||
it('throws a TypeError if the first argument is not an Error instance', () => {
|
||||
expect(() => convertErrorToAnnotationProperties('not an Error')).toThrow(
|
||||
TypeError,
|
||||
'error must be an instance of Error'
|
||||
)
|
||||
})
|
||||
|
||||
it('throws an Error if the first argument is an Error instance without a parseable stack', () => {
|
||||
const error = new Error('Test error')
|
||||
error.stack = ''
|
||||
expect(() => convertErrorToAnnotationProperties(error)).toThrow(Error, 'Error stack is empty or unparseable')
|
||||
})
|
||||
|
||||
it('returns an AnnotationProperties-compatible object', () => {
|
||||
const result = convertErrorToAnnotationProperties(new TypeError('Test error'))
|
||||
expect(result).toEqual({
|
||||
title: 'TypeError',
|
||||
file: __filename,
|
||||
startLine: expect.any(Number),
|
||||
startColumn: expect.any(Number)
|
||||
})
|
||||
})
|
||||
|
||||
it('returns an AnnotationProperties-compatible object with a custom title', () => {
|
||||
const result = convertErrorToAnnotationProperties(new TypeError('Test error'), 'custom title')
|
||||
expect(result).toEqual({
|
||||
title: 'custom title',
|
||||
file: __filename,
|
||||
startLine: expect.any(Number),
|
||||
startColumn: expect.any(Number)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user