UNPKG

@redhat-developer/page-objects

Version:

Page Object API implementation for a VS Code editor used by ExTester framework.

134 lines 5.43 kB
"use strict"; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License", destination); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocatorLoader = void 0; const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const compare_versions_1 = require("compare-versions"); const clone_deep_1 = __importDefault(require("clone-deep")); /** * Utility for loading locators for a given vscode version */ class LocatorLoader { baseVersion; baseFolder; version; locators; /** * Construct new loader for a given vscode version * @param version select version of vscode */ constructor(version, baseVersion, baseFolder) { this.version = version; if (version.endsWith('-insider')) { this.version = version.substring(0, version.indexOf('-insider')); } this.baseVersion = baseVersion; this.baseFolder = path.resolve(baseFolder); const temp = require(path.resolve(baseFolder, baseVersion)); this.locators = temp.locators; } /** * Loads locators for the selected vscode version * @returns object containing all locators */ loadLocators() { let versions = fs .readdirSync(this.baseFolder) .filter((file) => file.endsWith('.js')) .map((file) => path.basename(file, '.js')); if ((0, compare_versions_1.compareVersions)(this.baseVersion, this.version) === 0) { return this.locators; } if ((0, compare_versions_1.compareVersions)(this.baseVersion, this.version) < 0) { versions = versions.filter((ver) => (0, compare_versions_1.compareVersions)(this.baseVersion, ver) < 0 && (0, compare_versions_1.compareVersions)(ver, this.version) <= 0).sort(compare_versions_1.compareVersions); } else { versions = versions .filter((ver) => (0, compare_versions_1.compareVersions)(this.baseVersion, ver) > 0 && (0, compare_versions_1.compareVersions)(ver, this.version) >= 0) .sort(compare_versions_1.compareVersions) .reverse(); } for (const version of versions) { const diff = require(path.join(this.baseFolder, version)).diff; const newLocators = mergeLocators(this.locators, diff); this.locators = newLocators; } return this.locators; } } exports.LocatorLoader = LocatorLoader; function mergeLocators(original, diff) { const target = (0, clone_deep_1.default)(original); const targetDiff = diff.locators; merge(target, targetDiff); return target; } function merge(target, obj) { for (const key in obj) { if (key === '__proto__' || !Object.prototype.hasOwnProperty.call(obj, key)) { continue; } const oldVal = obj[key]; const newVal = target[key]; if (typeof newVal === 'object' && typeof oldVal === 'object') { target[key] = merge(newVal, oldVal); } else { target[key] = (0, clone_deep_1.default)(oldVal); } } return target; } //# sourceMappingURL=loader.js.map