gauge-ts
Version:
Typescript runner for Gauge
63 lines (62 loc) • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Screenshot = void 0;
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
const Util_1 = require("../utils/Util");
// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
class Screenshot {
static customScreenshotWriter;
static customScreenGrabber;
static async capture() {
try {
if (Screenshot.customScreenshotWriter != null) {
const out = Screenshot.customScreenshotWriter();
if (out.constructor.name === Promise.name) {
return await out;
}
return out;
// biome-ignore lint/style/noUselessElse: <explanation>
}
else if (Screenshot.customScreenGrabber != null) {
let data;
const out = Screenshot.customScreenGrabber();
if (out.constructor.name === Promise.name) {
data = await out;
}
else {
data = out;
}
const file = Util_1.Util.getUniqueScreenshotFileName();
(0, node_fs_1.writeFileSync)(file, data);
return (0, node_path_1.basename)(file);
// biome-ignore lint/style/noUselessElse: <explanation>
}
else {
return Screenshot.captureScreenshot();
}
}
catch (error) {
console.log(error);
}
return Promise.resolve("");
}
static captureScreenshot() {
try {
const filename = Util_1.Util.getUniqueScreenshotFileName();
Util_1.Util.spawn("gauge_screenshot", [filename]);
return (0, node_path_1.basename)(filename);
}
catch (error) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`\nFailed to take screenshot using gauge_screenshot.\n${error}`);
}
}
static setCustomScreenGrabber(grabber) {
Screenshot.customScreenGrabber = grabber;
}
static setCustomScreenshotWriter(writer) {
Screenshot.customScreenshotWriter = writer;
}
}
exports.Screenshot = Screenshot;