"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");

var _iterator = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol/iterator"));

var _symbol = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/symbol"));

var _index = _interopRequireDefault(require("./index"));

var __read = void 0 && (void 0).__read || function (o, n) {
  var m = typeof _symbol["default"] === "function" && o[_iterator["default"]];
  if (!m) return o;
  var i = m.call(o),
      r,
      ar = [],
      e;

  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
      ar.push(r.value);
    }
  } catch (error) {
    e = {
      error: error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"])) m.call(i);
    } finally {
      if (e) throw e.error;
    }
  }

  return ar;
};

var __spread = void 0 && (void 0).__spread || function () {
  for (var ar = [], i = 0; i < arguments.length; i++) {
    ar = ar.concat(__read(arguments[i]));
  }

  return ar;
};

var isCallReport = false;
jest.mock('./report-v3', function () {
  return {
    reportV3: function reportV3() {
      isCallReport = true;
    }
  };
}); // eslint-disable-next-line no-console

var originalLog = console.log; // eslint-disable-next-line no-console

var originalWarn = console.warn; // eslint-disable-next-line no-console

var originalError = console.error;
var logMessage = [];
var warnMessage = [];
var errorMessage = [];
beforeAll(function () {
  // eslint-disable-next-line no-console
  console.log = jest.fn(function () {
    var args = [];

    for (var _i = 0; _i < arguments.length; _i++) {
      args[_i] = arguments[_i];
    }

    return logMessage.push.apply(logMessage, __spread(args));
  }); // eslint-disable-next-line no-console

  console.warn = jest.fn(function () {
    var args = [];

    for (var _i = 0; _i < arguments.length; _i++) {
      args[_i] = arguments[_i];
    }

    return warnMessage.push.apply(warnMessage, __spread(args));
  }); // eslint-disable-next-line no-console

  console.error = jest.fn(function () {
    var args = [];

    for (var _i = 0; _i < arguments.length; _i++) {
      args[_i] = arguments[_i];
    }

    return errorMessage.push.apply(errorMessage, __spread(args));
  });
});
afterAll(function () {
  // eslint-disable-next-line no-console
  console.log = originalLog; // eslint-disable-next-line no-console

  console.warn = originalWarn; // eslint-disable-next-line no-console

  console.error = originalError;
});
describe('test logger', function () {
  test('level', function () {
    var infoLogger = new _index["default"]('', true, 'INFO');
    infoLogger.info('test1'); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore

    expect(logMessage).toStrictEqual([infoLogger.getPrintPrefix('INFO'), 'test1']);
    infoLogger.warn('test2'); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore

    expect(warnMessage).toStrictEqual([infoLogger.getPrintPrefix('WARN'), 'test2']);
    infoLogger.error('test3'); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore

    expect(errorMessage).toStrictEqual([infoLogger.getPrintPrefix('ERROR'), 'test3']); // 清空消息

    logMessage.splice(0, logMessage.length);
    warnMessage.splice(0, warnMessage.length);
    errorMessage.splice(0, errorMessage.length);
    var warnLogger = new _index["default"]('', true, 'WARN');
    warnLogger.info('test1');
    expect(logMessage).toStrictEqual([]);
    warnLogger.warn('test2'); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore

    expect(warnMessage).toStrictEqual([warnLogger.getPrintPrefix('WARN'), 'test2']);
    warnLogger.error('test3'); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore

    expect(errorMessage).toStrictEqual([warnLogger.getPrintPrefix('ERROR'), 'test3']); // 清空消息

    logMessage.splice(0, logMessage.length);
    warnMessage.splice(0, warnMessage.length);
    errorMessage.splice(0, errorMessage.length);
    var errorLogger = new _index["default"]('', true, 'ERROR');
    errorLogger.info('test1');
    expect(logMessage).toStrictEqual([]);
    errorLogger.warn('test2');
    expect(warnMessage).toStrictEqual([]);
    errorLogger.error('test3'); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore

    expect(errorMessage).toStrictEqual([errorLogger.getPrintPrefix('ERROR'), 'test3']); // 清空消息

    logMessage.splice(0, logMessage.length);
    warnMessage.splice(0, warnMessage.length);
    errorMessage.splice(0, errorMessage.length);
    var offLogger = new _index["default"]('', true, 'OFF');
    offLogger.info('test1');
    expect(logMessage).toStrictEqual([]);
    offLogger.warn('test2');
    expect(warnMessage).toStrictEqual([]);
    offLogger.error('test3');
    expect(errorMessage).toStrictEqual([]);
  });
  test('unique id', function () {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    var startId = _index["default"].id; // eslint-disable-next-line no-new

    new _index["default"]('', true, 'OFF'); // eslint-disable-next-line no-new

    new _index["default"]('', true, 'OFF');
    var last = new _index["default"]('', true, 'OFF'); // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore

    expect(last.id).toStrictEqual(startId + 3);
  });
  test('report', function () {
    var logger1 = new _index["default"]('', false, 'OFF');
    logger1.report(null);
    expect(isCallReport).toBeTruthy();
    isCallReport = false;
    var logger2 = new _index["default"]('', true, 'OFF');
    logger2.report(null);
    expect(isCallReport).toBeFalsy();
  });
});