refactor: remove "error" reporting level, move reportMessage to logger (#7642)

This commit is contained in:
Joshua Chen 2022-06-17 20:51:00 +08:00 committed by GitHub
parent 1b9bec1042
commit bfba6a8b02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 117 additions and 116 deletions

View file

@ -124,3 +124,33 @@ describe('success', () => {
expect(consoleMock.mock.calls).toMatchSnapshot();
});
});
describe('report', () => {
beforeAll(() => jest.clearAllMocks());
it('works with all severities', () => {
const consoleLog = jest.spyOn(console, 'info').mockImplementation(() => {});
const consoleWarn = jest
.spyOn(console, 'warn')
.mockImplementation(() => {});
logger.report('ignore')('hey');
logger.report('log')('hey');
logger.report('warn')('hey');
expect(() =>
logger.report('throw')('hey'),
).toThrowErrorMatchingInlineSnapshot(`"hey"`);
expect(() =>
// @ts-expect-error: for test
logger.report('foo')('hey'),
).toThrowErrorMatchingInlineSnapshot(
`"Unexpected "reportingSeverity" value: foo."`,
);
expect(consoleLog).toBeCalledTimes(1);
expect(consoleLog).toBeCalledWith(
expect.stringMatching(/.*\[INFO\].* hey/),
);
expect(consoleWarn).toBeCalledTimes(1);
expect(consoleWarn).toBeCalledWith(
expect.stringMatching(/.*\[WARNING\].* hey/),
);
});
});