123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- 'use strict';
-
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- exports.default = void 0;
-
- function _assert() {
- const data = _interopRequireDefault(require('assert'));
-
- _assert = function () {
- return data;
- };
-
- return data;
- }
-
- function _console() {
- const data = require('console');
-
- _console = function () {
- return data;
- };
-
- return data;
- }
-
- function _util() {
- const data = require('util');
-
- _util = function () {
- return data;
- };
-
- return data;
- }
-
- function _chalk() {
- const data = _interopRequireDefault(require('chalk'));
-
- _chalk = function () {
- return data;
- };
-
- return data;
- }
-
- function _jestUtil() {
- const data = require('jest-util');
-
- _jestUtil = function () {
- return data;
- };
-
- return data;
- }
-
- function _interopRequireDefault(obj) {
- return obj && obj.__esModule ? obj : {default: obj};
- }
-
- function _defineProperty(obj, key, value) {
- if (key in obj) {
- Object.defineProperty(obj, key, {
- value: value,
- enumerable: true,
- configurable: true,
- writable: true
- });
- } else {
- obj[key] = value;
- }
- return obj;
- }
-
- class BufferedConsole extends _console().Console {
- constructor() {
- super({
- write: message => {
- BufferedConsole.write(this._buffer, 'log', message, null);
- return true;
- }
- });
-
- _defineProperty(this, '_buffer', []);
-
- _defineProperty(this, '_counters', {});
-
- _defineProperty(this, '_timers', {});
-
- _defineProperty(this, '_groupDepth', 0);
-
- _defineProperty(this, 'Console', _console().Console);
- }
-
- static write(buffer, type, message, level) {
- const stackLevel = level != null ? level : 2;
- const rawStack = new (_jestUtil().ErrorWithStack)(
- undefined,
- BufferedConsole.write
- ).stack;
- invariant(rawStack, 'always have a stack trace');
- const origin = rawStack
- .split('\n')
- .slice(stackLevel)
- .filter(Boolean)
- .join('\n');
- buffer.push({
- message,
- origin,
- type
- });
- return buffer;
- }
-
- _log(type, message) {
- BufferedConsole.write(
- this._buffer,
- type,
- ' '.repeat(this._groupDepth) + message,
- 3
- );
- }
-
- assert(value, message) {
- try {
- (0, _assert().default)(value, message);
- } catch (error) {
- this._log('assert', error.toString());
- }
- }
-
- count(label = 'default') {
- if (!this._counters[label]) {
- this._counters[label] = 0;
- }
-
- this._log(
- 'count',
- (0, _util().format)(`${label}: ${++this._counters[label]}`)
- );
- }
-
- countReset(label = 'default') {
- this._counters[label] = 0;
- }
-
- debug(firstArg, ...rest) {
- this._log('debug', (0, _util().format)(firstArg, ...rest));
- }
-
- dir(firstArg, options = {}) {
- const representation = (0, _util().inspect)(firstArg, options);
-
- this._log('dir', (0, _util().formatWithOptions)(options, representation));
- }
-
- dirxml(firstArg, ...rest) {
- this._log('dirxml', (0, _util().format)(firstArg, ...rest));
- }
-
- error(firstArg, ...rest) {
- this._log('error', (0, _util().format)(firstArg, ...rest));
- }
-
- group(title, ...rest) {
- this._groupDepth++;
-
- if (title || rest.length > 0) {
- this._log(
- 'group',
- _chalk().default.bold((0, _util().format)(title, ...rest))
- );
- }
- }
-
- groupCollapsed(title, ...rest) {
- this._groupDepth++;
-
- if (title || rest.length > 0) {
- this._log(
- 'groupCollapsed',
- _chalk().default.bold((0, _util().format)(title, ...rest))
- );
- }
- }
-
- groupEnd() {
- if (this._groupDepth > 0) {
- this._groupDepth--;
- }
- }
-
- info(firstArg, ...rest) {
- this._log('info', (0, _util().format)(firstArg, ...rest));
- }
-
- log(firstArg, ...rest) {
- this._log('log', (0, _util().format)(firstArg, ...rest));
- }
-
- time(label = 'default') {
- if (this._timers[label]) {
- return;
- }
-
- this._timers[label] = new Date();
- }
-
- timeEnd(label = 'default') {
- const startTime = this._timers[label];
-
- if (startTime) {
- const endTime = new Date();
- const time = endTime.getTime() - startTime.getTime();
-
- this._log(
- 'time',
- (0, _util().format)(`${label}: ${(0, _jestUtil().formatTime)(time)}`)
- );
-
- delete this._timers[label];
- }
- }
-
- timeLog(label = 'default', ...data) {
- const startTime = this._timers[label];
-
- if (startTime) {
- const endTime = new Date();
- const time = endTime.getTime() - startTime.getTime();
-
- this._log(
- 'time',
- (0, _util().format)(
- `${label}: ${(0, _jestUtil().formatTime)(time)}`,
- ...data
- )
- );
- }
- }
-
- warn(firstArg, ...rest) {
- this._log('warn', (0, _util().format)(firstArg, ...rest));
- }
-
- getBuffer() {
- return this._buffer.length ? this._buffer : undefined;
- }
- }
-
- exports.default = BufferedConsole;
-
- function invariant(condition, message) {
- if (!condition) {
- throw new Error(message);
- }
- }
|