scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
99 lines • 2.48 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var console_exports = {};
__export(console_exports, {
MockConsole: () => MockConsole
});
module.exports = __toCommonJS(console_exports);
var import_scriptable_abstract = require("scriptable-abstract");
class MockConsole extends import_scriptable_abstract.AbsConsole {
constructor() {
super({
logs: []
});
}
/**
* @inheritdoc
*/
log(...values) {
const message = values.map((v) => String(v)).join(" ");
this.addLog("log", message);
}
/**
* @inheritdoc
*/
warn(...values) {
const message = values.map((v) => String(v)).join(" ");
this.addLog("warn", message);
}
/**
* @inheritdoc
*/
error(...values) {
const message = values.map((v) => String(v)).join(" ");
this.addLog("error", message);
}
/**
* @additional
* Clear all logs from the console state
*/
clear() {
this.setState({
logs: []
});
}
/**
* @additional
* Get all logs from the console state
*/
getLogs() {
return Object.freeze(
this.state.logs.map((log) => {
switch (log.type) {
case "warn":
return `[WARN] ${log.message}`;
case "error":
return `[ERROR] ${log.message}`;
default:
return log.message;
}
})
);
}
/**
* @internal
* Add a log entry to the state
*/
addLog(type, message) {
this.setState((state) => ({
logs: [
...state.logs,
{
type,
message,
timestamp: Date.now()
}
]
}));
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockConsole
});
//# sourceMappingURL=console.js.map