chore: increase test coverage

This commit is contained in:
Tom Keller
2022-10-18 20:12:45 -07:00
parent 475e183cb5
commit 19a173d3ee
2 changed files with 29 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
import * as helpers from '../src/helpers';
describe('helpers', () => {
beforeEach(() => {
jest.resetModules();
jest.clearAllMocks();
});
test('removes brackets from GitHub Actor', () => {
expect(helpers.sanitizeGithubActor('foo[bot]')).toEqual('foo_bot_');
});
test('removes special characters from worflow names', () => {
expect(helpers.sanitizeGithubWorkflowName('sdf234@#$%$^&*()_+{}|:"<>?')).toEqual('sdf234@__________+___:_<>?');
});
test('can sleep', async () => {
const sleep = helpers.defaultSleep(10);
await expect(Promise.race([sleep, new Promise((_res, rej) => setTimeout(rej, 20))])).resolves;
});
test("backoff function doesn't retry non-retryable errors", async () => {
const fn = jest.fn().mockRejectedValue('i am not retryable');
await expect(helpers.retryAndBackoff(fn, false)).rejects.toMatch('i am not retryable');
expect(fn).toHaveBeenCalledTimes(1);
});
});