-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added debug output Resolves #47 * Fix name of utils mocks in unit tests
- Loading branch information
Showing
8 changed files
with
192 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const utilsMocks = { | ||
actionsCoreDebug: jest.fn().mockName('Mock: "@actions/core".debug()'), | ||
actionsCoreError: jest.fn().mockName('Mock: "@actions/core".error()'), | ||
}; | ||
|
||
jest.mock('@actions/core', () => ({ | ||
debug: utilsMocks.actionsCoreDebug, | ||
error: utilsMocks.actionsCoreError, | ||
})); | ||
|
||
describe('Utils functionality testing', () => { | ||
it('should report about error in stringifying of additional data for debug', async () => { | ||
const error = new Error('Test error'); | ||
const stringifyMock = jest.spyOn(JSON, 'stringify').mockImplementation(() => { throw new Error('Test error'); }); | ||
|
||
const { debug } = jest.requireActual('../../../src/utils.ts'); | ||
const { actionsCoreDebug, actionsCoreError } = utilsMocks; | ||
|
||
expect(() => debug('Test')).not.toThrow(); | ||
expect(stringifyMock).toBeCalledTimes(1); | ||
expect(actionsCoreDebug).toBeCalledTimes(2); | ||
expect(actionsCoreError).toBeCalledTimes(1); | ||
|
||
expect(actionsCoreError).lastCalledWith(error); | ||
expect(actionsCoreDebug).nthCalledWith(1, `[DEBUG] Can't stringify additional debug data for the message: Test. Error: Test error`); | ||
expect(actionsCoreDebug).nthCalledWith(2, `[DEBUG] Test`); | ||
|
||
stringifyMock.mockRestore(); | ||
}); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { debug as coreDebug, error as coreError } from '@actions/core'; | ||
|
||
/** | ||
* Wrapper to display debug messages | ||
* @param {string} message - Debug message to display | ||
* @param {?=} data - Additional data that should be displayed in the debug output | ||
*/ | ||
function debug(message: string, data?: unknown) { | ||
let additionalData; | ||
try { | ||
additionalData = JSON.stringify(data); | ||
} catch (error) { | ||
const { message: errorMessage } = error as Error; | ||
coreDebug(`[DEBUG] Can't stringify additional debug data for the message: ${message}. Error: ${errorMessage}`); | ||
coreError(error as Error); | ||
} | ||
|
||
if (additionalData) { | ||
coreDebug(`[DEBUG] ${message}\n${additionalData}`); | ||
} else { | ||
coreDebug(`[DEBUG] ${message}`); | ||
} | ||
} | ||
|
||
export { | ||
debug, | ||
}; |