kui-shell
Version:
This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool
95 lines • 4.32 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const Selectors = require("./selectors");
const keys_1 = require("./keys");
exports.timeout = Math.max(5000, parseInt(process.env.TIMEOUT) || 60000);
exports.waitTimeout = exports.timeout - 5000;
const grabFocus = (app) => __awaiter(void 0, void 0, void 0, function* () {
return app.client
.click(Selectors.CURRENT_PROMPT)
.then(() => app.client.waitForEnabled(Selectors.CURRENT_PROMPT_BLOCK))
.catch(err => {
console.error(err);
});
});
exports.command = (cmd, app, noNewline = false, noCopyPaste = false, noFocus = false) => __awaiter(void 0, void 0, void 0, function* () {
return app.client
.waitForExist(Selectors.CURRENT_PROMPT_BLOCK, exports.timeout - 5000)
.then(() => {
if (!noFocus)
return grabFocus(app);
})
.then(() => app.client.getAttribute(Selectors.CURRENT_PROMPT_BLOCK, 'data-input-count'))
.then((count) => __awaiter(void 0, void 0, void 0, function* () {
if (!noCopyPaste && cmd.length > 1) {
yield app.client.execute(text => navigator.clipboard.writeText(text).then(() => document.execCommand('paste')), cmd);
}
else {
const currentValue = yield app.client.getValue(Selectors.CURRENT_PROMPT);
const doThis = `${currentValue}${cmd}`;
yield app.client.setValue(Selectors.CURRENT_PROMPT, doThis);
}
if (noNewline !== true)
yield app.client.keys(keys_1.keys.ENTER);
return { app: app, count: parseInt(count) };
}));
});
exports.paste = (cmd, app, nLines = 1) => __awaiter(void 0, void 0, void 0, function* () {
return app.client
.waitForExist(Selectors.CURRENT_PROMPT_BLOCK)
.then(() => app.client.getAttribute(Selectors.CURRENT_PROMPT_BLOCK, 'data-input-count'))
.then((count) => __awaiter(void 0, void 0, void 0, function* () {
app.electron.clipboard.writeText(cmd);
yield app.client.execute(() => document.execCommand('paste'));
return { app: app, count: parseInt(count) + nLines - 1 };
}));
});
exports.waitForRepl = (app) => __awaiter(void 0, void 0, void 0, function* () {
yield app.client.waitForEnabled(Selectors.CURRENT_PROMPT);
return app;
});
exports.waitForSession = (ctx, noProxySessionWait = false) => {
if (process.env.MOCHA_RUN_TARGET === 'webpack' && process.env.KUI_USE_PROXY === 'true' && !noProxySessionWait) {
try {
return ctx.app.client.waitForExist(`${Selectors.CURRENT_TAB}.kui--session-init-done`);
}
catch (err) {
throw new Error('error waiting for proxy session init');
}
}
};
exports.getTextContent = (app, selector) => __awaiter(void 0, void 0, void 0, function* () {
return app.client
.execute(selector => {
try {
return document.querySelector(selector).textContent;
}
catch (err) {
console.error('error in getTextContent', err);
}
}, selector)
.then(_ => _.value);
});
exports.makeCustom = (selector, expect, exact) => ({
selector: selector,
expect: expect,
exact: exact
});
exports.exitCode = (statusCode) => statusCode;
exports.expectInput = (selector, expectedText) => (app) => __awaiter(void 0, void 0, void 0, function* () {
yield app.client.waitUntil(() => __awaiter(void 0, void 0, void 0, function* () {
const inputText = yield app.client.getValue(selector);
return inputText === expectedText;
}));
return app;
});
//# sourceMappingURL=cli.js.map