2021-10-27 09:53:02 -05:00
|
|
|
import { warningUtils } from '@verdaccio/core';
|
2020-08-13 16:27:00 -05:00
|
|
|
import { logger, setup } from '../src';
|
2020-04-13 07:34:26 -05:00
|
|
|
|
2021-10-27 09:53:02 -05:00
|
|
|
const mockWarningUtils = jest.fn();
|
|
|
|
|
|
|
|
jest.mock('@verdaccio/core', () => {
|
|
|
|
const original = jest.requireActual('@verdaccio/core');
|
|
|
|
return {
|
|
|
|
warningUtils: {
|
|
|
|
...original.warningUtils,
|
|
|
|
emit: (...args) => {
|
|
|
|
mockWarningUtils(...args);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-04-13 07:34:26 -05:00
|
|
|
describe('logger', () => {
|
2021-10-27 09:53:02 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
test.skip('should write message logger', () => {
|
2021-06-12 02:25:53 -05:00
|
|
|
jest.spyOn(process.stdout, 'write');
|
2020-08-13 16:27:00 -05:00
|
|
|
setup([
|
|
|
|
{
|
|
|
|
level: 'info',
|
|
|
|
},
|
|
|
|
]);
|
2020-04-13 07:34:26 -05:00
|
|
|
|
2020-08-13 16:27:00 -05:00
|
|
|
logger.info({ packageName: 'test' }, `publishing or updating a new version for @{packageName}`);
|
2021-06-12 02:25:53 -05:00
|
|
|
// FIXME: check expect
|
2020-08-13 16:27:00 -05:00
|
|
|
// expect(spyOn).toHaveBeenCalledTimes(2);
|
|
|
|
});
|
2021-09-19 13:20:46 -05:00
|
|
|
|
|
|
|
test('throw deprecation warning if multiple loggers configured', () => {
|
|
|
|
setup([
|
|
|
|
{
|
|
|
|
level: 'info',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
level: 'http',
|
|
|
|
},
|
|
|
|
]);
|
2021-10-27 09:53:02 -05:00
|
|
|
expect(mockWarningUtils).toHaveBeenCalledWith(warningUtils.Codes.VERDEP002);
|
2021-09-19 13:20:46 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('regression: do not throw deprecation warning if no logger config is provided', () => {
|
|
|
|
setup();
|
2021-10-27 09:53:02 -05:00
|
|
|
expect(mockWarningUtils).not.toHaveBeenCalled();
|
2021-09-19 13:20:46 -05:00
|
|
|
});
|
2020-04-13 07:34:26 -05:00
|
|
|
});
|