theia-extension-tester
Version:
A testing library built on Selenium to test Eclipse Theia extensions / plugins. Eclipse Che is supported as well.
93 lines • 3.92 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 });
exports.parseObjectJsonArgument = exports.complexParse = exports.parseFileJsonArgument = exports.getBrowserLocation = exports.getBrowserName = void 0;
const fs = require("fs-extra");
const path = require("path");
function getBrowserName(browser) {
browser = path.parse(browser).base.toLowerCase();
const chrome = 'chrome';
const firefox = 'firefox';
const edge = 'MicrosoftEdge';
const opera = 'opera';
const safari = 'safari';
const supportedBrowsers = {
chrome, firefox, edge, opera, safari
};
for (const supportedBrowser of Object.keys(supportedBrowsers)) {
if (browser.includes(supportedBrowser)) {
return supportedBrowsers[supportedBrowser];
}
}
throw new Error(`Could not find supported browser for "${browser}".`);
}
exports.getBrowserName = getBrowserName;
function getBrowserLocation(browser) {
return __awaiter(this, void 0, void 0, function* () {
if (yield fs.pathExists(browser)) {
return browser;
}
return undefined;
});
}
exports.getBrowserLocation = getBrowserLocation;
function parseFileJsonArgument(fileOrJson, optional = true, name) {
return __awaiter(this, void 0, void 0, function* () {
if (fileOrJson === undefined) {
if (optional) {
return {};
}
else {
throw new Error(`"${name}" option is undefined.`);
}
}
try {
if (fileOrJson.trimStart().startsWith('{')) {
return JSON.parse(fileOrJson);
}
else if (yield fs.pathExists(fileOrJson)) {
return yield fs.readJson(fileOrJson);
}
else {
throw new Error(`Invalid value for "${name !== null && name !== void 0 ? name : 'unknown'} option": "${fileOrJson}"`);
}
}
catch (e) {
console.error(`Could not parse "${name !== null && name !== void 0 ? name : 'unknown'}" option. Reason: ${e instanceof Error ? e.message : e}`);
if (e instanceof SyntaxError) {
console.error(`JSON value:\n${fileOrJson}`);
}
process.exit(1);
}
});
}
exports.parseFileJsonArgument = parseFileJsonArgument;
function complexParse(rules, options) {
const valueType = typeof options.object;
if (valueType === 'undefined' && options.optional) {
return undefined;
}
if (!Object.keys(rules).includes(valueType) && options.passThrough) {
return options.object;
}
return rules[valueType](options.object);
}
exports.complexParse = complexParse;
function parseObjectJsonArgument(options) {
return __awaiter(this, void 0, void 0, function* () {
return complexParse({
'string': (value) => __awaiter(this, void 0, void 0, function* () { return yield parseFileJsonArgument(value, options.optional, options.name); }),
'object': (value) => options.stringifyObject ? JSON.stringify(value) : value
}, options);
});
}
exports.parseObjectJsonArgument = parseObjectJsonArgument;
//# sourceMappingURL=parser.js.map