@rstest/core
Version:
The Rsbuild-based test tool.
143 lines (142 loc) • 7.45 kB
JavaScript
import 'module';
/*#__PURE__*/ import.meta.url;
export const __webpack_ids__ = [
"813"
];
export const __webpack_modules__ = {
"./src/runtime/worker/console.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
createCustomConsole: ()=>createCustomConsole
});
var node_assert__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:assert");
var node_console__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("node:console");
var node_util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("node:util");
var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/utils/index.ts");
const RealDate = Date;
function createCustomConsole({ rpc, testPath, printConsoleTrace }) {
const getConsoleTrace = ()=>{
const limit = Error.stackTraceLimit;
Error.stackTraceLimit = 4;
const stack = new Error('STACK_TRACE').stack;
const trace = stack?.split('\n').slice(4).join('\n');
Error.stackTraceLimit = limit;
return trace;
};
class CustomConsole extends node_console__WEBPACK_IMPORTED_MODULE_1__.Console {
_counters = {};
_timers = {};
_groupDepth = 0;
Console = node_console__WEBPACK_IMPORTED_MODULE_1__.Console;
getPrettyName(type) {
switch(type){
case 'error':
return _utils__WEBPACK_IMPORTED_MODULE_3__.$_.red(type);
case 'warn':
return _utils__WEBPACK_IMPORTED_MODULE_3__.$_.yellow(type);
case 'info':
return _utils__WEBPACK_IMPORTED_MODULE_3__.$_.cyan(type);
default:
return _utils__WEBPACK_IMPORTED_MODULE_3__.$_.gray(type);
}
}
_log(name, message, type = 'stdout') {
rpc.onConsoleLog({
content: ' '.repeat(this._groupDepth) + message,
name: this.getPrettyName(name),
testPath,
type,
trace: printConsoleTrace ? getConsoleTrace() : void 0
});
}
assert(value, message) {
try {
(0, node_assert__WEBPACK_IMPORTED_MODULE_0__.strict)(value, message);
} catch (error) {
if (!(error instanceof node_assert__WEBPACK_IMPORTED_MODULE_0__.AssertionError)) throw error;
this._log('assert', error.toString().replaceAll(/:\n\n.*\n/gs, ''), 'stderr');
}
}
count(label = 'default') {
if (!this._counters[label]) this._counters[label] = 0;
this._log('count', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(`${label}: ${++this._counters[label]}`));
}
countReset(label = 'default') {
this._counters[label] = 0;
}
debug(firstArg, ...args) {
this._log('debug', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(firstArg, ...args));
}
dir(firstArg, options = {}) {
const representation = (0, node_util__WEBPACK_IMPORTED_MODULE_2__.inspect)(firstArg, options);
this._log('dir', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.formatWithOptions)(options, representation));
}
dirxml(firstArg, ...args) {
this._log('dirxml', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(firstArg, ...args));
}
error(firstArg, ...args) {
this._log('error', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(firstArg, ...args), 'stderr');
}
group(title, ...args) {
this._groupDepth++;
if (null != title || args.length > 0) this._log('group', _utils__WEBPACK_IMPORTED_MODULE_3__.$_.bold((0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(title, ...args)));
}
groupCollapsed(title, ...args) {
this._groupDepth++;
if (null != title || args.length > 0) this._log('groupCollapsed', _utils__WEBPACK_IMPORTED_MODULE_3__.$_.bold((0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(title, ...args)));
}
groupEnd() {
if (this._groupDepth > 0) this._groupDepth--;
}
info(firstArg, ...args) {
this._log('info', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(firstArg, ...args));
}
log(firstArg, ...args) {
this._log('log', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(firstArg, ...args));
}
time(label = 'default') {
if (null != this._timers[label]) return;
this._timers[label] = new RealDate();
}
timeEnd(label = 'default') {
const startTime = this._timers[label];
if (null != startTime) {
const endTime = RealDate.now();
const time = endTime - startTime.getTime();
this._log('time', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(`${label}: ${(0, _utils__WEBPACK_IMPORTED_MODULE_3__.AS)(time)}`));
delete this._timers[label];
}
}
timeLog(label = 'default', ...data) {
const startTime = this._timers[label];
if (null != startTime) {
const endTime = new RealDate();
const time = endTime.getTime() - startTime.getTime();
this._log('time', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(`${label}: ${(0, _utils__WEBPACK_IMPORTED_MODULE_3__.AS)(time)}`, ...data));
}
}
warn(firstArg, ...args) {
this._log('warn', (0, node_util__WEBPACK_IMPORTED_MODULE_2__.format)(firstArg, ...args), 'stderr');
}
getBuffer() {}
}
return new CustomConsole(process.stdout, process.stderr);
}
},
"./src/utils/index.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Kn: ()=>helper.Kn,
AS: ()=>helper.AS,
n1: ()=>constants.n1,
XQ: ()=>helper.XQ,
$_: ()=>helper.$_,
Yz: ()=>helper.Yz
});
var constants = __webpack_require__("./src/utils/constants.ts");
var helper = __webpack_require__("./src/utils/helper.ts");
__webpack_require__("./src/utils/logger.ts");
__webpack_require__("fs");
__webpack_require__("node:fs/promises");
__webpack_require__("node:module");
__webpack_require__("pathe");
}
};