scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
76 lines • 1.44 kB
JavaScript
import { AbsConsole } from "scriptable-abstract";
class MockConsole extends 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()
}
]
}));
}
}
export {
MockConsole
};
//# sourceMappingURL=console.js.map