UNPKG

appwright

Version:

E2E mobile app testing done right, with the Playwright test runner

67 lines (66 loc) 2.71 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.boxedStep = boxedStep; exports.validateBuildPath = validateBuildPath; exports.getLatestBuildToolsVersions = getLatestBuildToolsVersions; exports.longestDeterministicGroup = longestDeterministicGroup; exports.basePath = basePath; const test_1 = __importDefault(require("@playwright/test")); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); function boxedStep(target, context) { return function replacementMethod(...args) { const path = this.selector ? `("${this.selector}")` : ""; const argsString = args.length ? "(" + Array.from(args) .map((a) => JSON.stringify(a)) .join(" , ") + ")" : ""; const name = `${context.name}${path}${argsString}`; return test_1.default.step(name, async () => { return await target.call(this, ...args); }, { box: true }); }; } function validateBuildPath(buildPath, expectedExtension) { if (!buildPath) { throw new Error(`Build path not found. Please set the build path in appwright.config.ts`); } if (!buildPath.endsWith(expectedExtension)) { throw new Error(`File path is not supported for the given combination of platform and provider. Please provide build with ${expectedExtension} file extension in the appwright.config.ts`); } if (!fs_1.default.existsSync(buildPath)) { throw new Error(`File not found at given path: ${buildPath} Please provide the correct path of the build.`); } } function getLatestBuildToolsVersions(versions) { return versions.sort((a, b) => (a > b ? -1 : 1))[0]; } function longestDeterministicGroup(pattern) { const patternToString = pattern.toString(); const matches = [...patternToString.matchAll(/\(([^)]+)\)/g)].map((match) => match[1]); if (!matches || !matches.length) { return undefined; } const noSpecialChars = matches.filter((match) => { if (!match) { return false; } const regexSpecialCharsPattern = /[.*+?^${}()|[\]\\]/; return !regexSpecialCharsPattern.test(match); }); const longestString = noSpecialChars.reduce((max, str) => (str.length > max.length ? str : max), ""); if (longestString == "") { return undefined; } return longestString; } function basePath() { return path_1.default.join(process.cwd(), "playwright-report", "data", "videos-store"); }