Files
superset2/.github/actions/file-changes-action/src/tests/UtilsHelper.test.ts
Jesse Yang a3bbbf8ea3 build: inline external Github Actions to unblock CI (#12241)
* build: inline cached-dependencies to unblock CI

* Run E2E on pull_request on;y

* Inline all external actions

* Checkout needed for internal actions

Also fixes pre-commit

* Add missing files
2021-01-04 14:16:07 +02:00

68 lines
2.0 KiB
TypeScript

import {Env, p, getTestEvents} from './mocks/env'
let env: Env
describe('Testing UtilsHelper.ts...', () => {
describe('...with push event...', () => {
beforeAll(() => {
env = new Env({}, {githubToken: 'TestToken'}, 'push')
})
afterEach(() => {
process.env = {...env.envStart}
jest.resetModules()
env = new Env({}, {}, 'push')
})
/**
* @function getErrorString
*/
describe('...with function getErrorString...', () => {
it('...can throw an error', () => {
const error = require('../UtilsHelper').getErrorString()
expect(JSON.stringify(JSON.parse(error))).toBe(
JSON.stringify({error: '500/undefined', payload: ''})
)
})
it('...can throw an error for my error', () => {
const {setFailed, error: coreError} = require('@actions/core')
const obj = {a: {}}
obj.a = {b: obj}
expect(() =>
require('../UtilsHelper').getErrorString(
'test',
200,
'test',
'test',
obj
)
).toThrowError(
JSON.stringify({
name: '500/undefined',
message: 'Error throwing error.'
})
)
// expect(JSON.stringify(JSON.parse(error))).toBe(JSON.stringify({error:'500/undefined', payload:''}))
expect(setFailed).toBeCalledWith(
expect.stringContaining('Error throwing error.')
)
expect(coreError).toBeCalledWith(
expect.stringContaining('Error throwing error.')
)
})
})
/**
* @function errorMessage
*/
describe('...with function errorMessage...', () => {
it.each(getTestEvents(p.errorMessageInputs, 'push'))(
'...for function %s',
(f, e, expected) => {
const error = require('../UtilsHelper').errorMessage(f, e)
expect(error).toBe(
`${expected}\nException: ${JSON.stringify(e, null, 2)}`
)
}
)
})
})
})