MCPcopy
hub / github.com/ampproject/amphtml / templateFunc

Function templateFunc

build-system/tasks/e2e/describes-e2e.js:381–506  ·  view source on GitHub ↗
(suiteName, spec, fn, describeFunc)

Source from the content-addressed store, hash-verified

379
380 */
381 const templateFunc = function (suiteName, spec, fn, describeFunc) {
382 const fixture = factory(spec);
383 let environments = spec.environments || 'ampdoc-preset';
384 if (typeof environments === 'string') {
385 environments = envPresets[environments];
386 }
387 if (!environments) {
388 throw new Error('Invalid environment preset: ' + spec.environments);
389 }
390 const variants = Object.create(null);
391 environments.forEach((environment) => {
392 const o = EnvironmentVariantMap[environment];
393 variants[o.name] = o.value;
394 });
395
396 // Use chrome as default if no browser is specified
397 if (!Array.isArray(spec.browsers)) {
398 spec.browsers = ['chrome'];
399 }
400
401 /**
402 * Initializes the describe object for all applicable browsers.
403 */
404 function createBrowserDescribe() {
405 const allowedBrowsers = getAllowedBrowsers();
406 spec.browsers
407 .filter((x) => allowedBrowsers.has(x))
408 .forEach((browserName) => {
409 describe(browserName, function () {
410 createVariantDescribe(browserName);
411 });
412 });
413 }
414
415 /**
416 * @return {Set<string>}
417 */
418 function getAllowedBrowsers() {
419 const {browsers} = getConfig();
420
421 const allowedBrowsers = browsers
422 ? new Set(browsers.split(',').map((x) => x.trim()))
423 : supportedBrowsers;
424
425 if (process.platform !== 'darwin' && allowedBrowsers.has('safari')) {
426 // silently skip safari tests
427 allowedBrowsers.delete('safari');
428 }
429
430 return allowedBrowsers;
431 }
432
433 /**
434 * @param {BrowserNameDef} browserName
435 */
436 function createVariantDescribe(browserName) {
437 for (const name in variants) {
438 it.configure = function () {

Callers 2

mainFuncFunction · 0.70
describeEnvFunction · 0.70

Calls 4

createBrowserDescribeFunction · 0.85
factoryFunction · 0.50
createMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected