github-pages-deploy-action/node_modules/@jest/console/build/BufferedConsole.js

241 lines
4.4 KiB
JavaScript
Raw Normal View History

2020-03-31 20:42:07 +08:00
'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;
}
2020-04-30 20:40:07 +08:00
function _jestUtil() {
const data = require('jest-util');
2020-03-31 20:42:07 +08:00
2020-04-30 20:40:07 +08:00
_jestUtil = function () {
2020-03-31 20:42:07 +08:00
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 {
2020-04-30 20:40:07 +08:00
constructor() {
2020-03-31 20:42:07 +08:00
const buffer = [];
super({
write: message => {
2020-04-30 20:40:07 +08:00
BufferedConsole.write(buffer, 'log', message, null);
2020-03-31 20:42:07 +08:00
return true;
}
});
_defineProperty(this, '_buffer', void 0);
_defineProperty(this, '_counters', void 0);
_defineProperty(this, '_timers', void 0);
_defineProperty(this, '_groupDepth', void 0);
this._buffer = buffer;
this._counters = {};
this._timers = {};
this._groupDepth = 0;
}
2020-04-30 20:40:07 +08:00
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');
2020-03-31 20:42:07 +08:00
buffer.push({
message,
origin,
type
});
return buffer;
}
_log(type, message) {
BufferedConsole.write(
this._buffer,
type,
' '.repeat(this._groupDepth) + message,
2020-04-30 20:40:07 +08:00
3
2020-03-31 20:42:07 +08:00
);
}
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, ...rest) {
this._log('dir', (0, _util().format)(firstArg, ...rest));
}
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}: ${time}ms`));
delete this._timers[label];
}
}
warn(firstArg, ...rest) {
this._log('warn', (0, _util().format)(firstArg, ...rest));
}
getBuffer() {
return this._buffer.length ? this._buffer : undefined;
}
}
exports.default = BufferedConsole;
2020-04-30 20:40:07 +08:00
function invariant(condition, message) {
if (!condition) {
throw new Error(message);
}
}