UNPKG

@wordpress/e2e-test-utils

Version:
47 lines (43 loc) 1.7 kB
/* wp:polyfill */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createEmbeddingMatcher = createEmbeddingMatcher; var _path = require("path"); /** * External dependencies */ /** * Creates a function to determine if a request has a parameter with a certain value. * * @param {string} parameterName The query parameter to check. * @param {string} value The value to check for. * @return {Function} Function that determines if a request's query parameter is the specified value. */ function parameterEquals(parameterName, value) { return request => new URL(request.url()).searchParams.get(parameterName) === value; } /** * Creates a function to determine if a request is a REST request of a given * path, accounting for variance in site permalink configuration. * * @param {string} path REST path to test. * * @return {Function} Function that determines if a request is a REST request of * a given path, accounting for variance in site permalink * configuration. */ function isRESTRoute(path) { return request => parameterEquals('rest_route', path)(request) || new URL(request.url()).pathname.endsWith((0, _path.join)('/wp-json', path)); } /** * Creates a function to determine if a request is embedding a certain URL. * * @param {string} url The URL to check against a request. * @return {Function} Function that determines if a request is for the embed API, embedding a specific URL. */ function createEmbeddingMatcher(url) { return request => isRESTRoute('/oembed/1.0/proxy')(request) && parameterEquals('url', url)(request); } //# sourceMappingURL=create-embedding-matcher.js.map