How to use descMap method in wpt

Best JavaScript code snippet using wpt

schema_extractor.ts

Source:schema_extractor.ts Github

copy

Full Screen

1/**2 * @license3 * Copyright Google LLC All Rights Reserved.4 *5 * Use of this source code is governed by an MIT-style license that can be6 * found in the LICENSE file at https://angular.io/license7 */8const SVG_PREFIX = ':svg:';9// Element | Node interfaces10// see https://developer.mozilla.org/en-US/docs/Web/API/Element11// see https://developer.mozilla.org/en-US/docs/Web/API/Node12const ELEMENT_IF = '[Element]';13// HTMLElement interface14// see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement15const HTMLELEMENT_IF = '[HTMLElement]';16const HTMLELEMENT_TAGS =17 'abbr,address,article,aside,b,bdi,bdo,cite,code,dd,dfn,dt,em,figcaption,figure,footer,header,i,kbd,main,mark,nav,noscript,rb,rp,rt,rtc,ruby,s,samp,section,small,strong,sub,sup,u,var,wbr';18const ALL_HTML_TAGS =19 // https://www.w3.org/TR/html5/index.html20 'a,abbr,address,area,article,aside,audio,b,base,bdi,bdo,blockquote,body,br,button,canvas,caption,cite,code,col,colgroup,data,datalist,dd,del,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hr,html,i,iframe,img,input,ins,kbd,keygen,label,legend,li,link,main,map,mark,meta,meter,nav,noscript,object,ol,optgroup,option,output,p,param,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,section,select,small,source,span,strong,style,sub,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,u,ul,var,video,wbr,' +21 // https://html.spec.whatwg.org/22 'details,summary,menu,menuitem';23// Elements missing from Chrome (HtmlUnknownElement), to be manually added24const MISSING_FROM_CHROME: {[el: string]: string[]} = {25 'data^[HTMLElement]': ['value'],26 'keygen^[HTMLElement]': ['!autofocus', 'challenge', '!disabled', 'form', 'keytype', 'name'],27 // TODO(vicb): Figure out why Chrome and WhatWG do not agree on the props28 // 'menu^[HTMLElement]': ['type', 'label'],29 'menuitem^[HTMLElement]':30 ['type', 'label', 'icon', '!disabled', '!checked', 'radiogroup', '!default'],31 'summary^[HTMLElement]': [],32 'time^[HTMLElement]': ['dateTime'],33 ':svg:cursor^:svg:': [],34};35const _G: any = typeof window != 'undefined' && window || typeof global != 'undefined' && global ||36 typeof self != 'undefined' && self;37const document: any = typeof _G['document'] == 'object' ? _G['document'] : null;38export function extractSchema(): Map<string, string[]>|null {39 if (!document) return null;40 const SVGGraphicsElement = _G['SVGGraphicsElement'];41 if (!SVGGraphicsElement) return null;42 const element = document.createElement('video');43 const descMap: Map<string, string[]> = new Map();44 const visited: {[name: string]: boolean} = {};45 // HTML top level46 extractProperties(Node, element, visited, descMap, ELEMENT_IF, '');47 extractProperties(Element, element, visited, descMap, ELEMENT_IF, '');48 extractProperties(HTMLElement, element, visited, descMap, HTMLELEMENT_IF, ELEMENT_IF);49 extractProperties(HTMLElement, element, visited, descMap, HTMLELEMENT_TAGS, HTMLELEMENT_IF);50 extractProperties(HTMLMediaElement, element, visited, descMap, 'media', HTMLELEMENT_IF);51 // SVG top level52 const svgAnimation = document.createElementNS('http://www.w3.org/2000/svg', 'set');53 const svgPath = document.createElementNS('http://www.w3.org/2000/svg', 'path');54 const svgFeFuncA = document.createElementNS('http://www.w3.org/2000/svg', 'feFuncA');55 const svgGradient = document.createElementNS('http://www.w3.org/2000/svg', 'linearGradient');56 const svgText = document.createElementNS('http://www.w3.org/2000/svg', 'text');57 const SVGAnimationElement = _G['SVGAnimationElement'];58 const SVGGeometryElement = _G['SVGGeometryElement'];59 const SVGComponentTransferFunctionElement = _G['SVGComponentTransferFunctionElement'];60 const SVGGradientElement = _G['SVGGradientElement'];61 const SVGTextContentElement = _G['SVGTextContentElement'];62 const SVGTextPositioningElement = _G['SVGTextPositioningElement'];63 extractProperties(SVGElement, svgText, visited, descMap, SVG_PREFIX, HTMLELEMENT_IF);64 extractProperties(65 SVGGraphicsElement, svgText, visited, descMap, SVG_PREFIX + 'graphics', SVG_PREFIX);66 extractProperties(67 SVGAnimationElement, svgAnimation, visited, descMap, SVG_PREFIX + 'animation', SVG_PREFIX);68 extractProperties(69 SVGGeometryElement, svgPath, visited, descMap, SVG_PREFIX + 'geometry', SVG_PREFIX);70 extractProperties(71 SVGComponentTransferFunctionElement, svgFeFuncA, visited, descMap,72 SVG_PREFIX + 'componentTransferFunction', SVG_PREFIX);73 extractProperties(74 SVGGradientElement, svgGradient, visited, descMap, SVG_PREFIX + 'gradient', SVG_PREFIX);75 extractProperties(76 SVGTextContentElement, svgText, visited, descMap, SVG_PREFIX + 'textContent',77 SVG_PREFIX + 'graphics');78 extractProperties(79 SVGTextPositioningElement, svgText, visited, descMap, SVG_PREFIX + 'textPositioning',80 SVG_PREFIX + 'textContent');81 // Get all element types82 const types = Object.getOwnPropertyNames(window).filter(k => /^(HTML|SVG).*?Element$/.test(k));83 types.sort();84 types.forEach(type => {85 extractRecursiveProperties(visited, descMap, (window as any)[type]);86 });87 // Add elements missed by Chrome auto-detection88 Object.keys(MISSING_FROM_CHROME).forEach(elHierarchy => {89 descMap.set(elHierarchy, MISSING_FROM_CHROME[elHierarchy]);90 });91 assertNoMissingTags(descMap);92 return descMap;93}94function assertNoMissingTags(descMap: Map<string, string[]>): void {95 const extractedTags: string[] = [];96 Array.from(descMap.keys()).forEach((key: string) => {97 extractedTags.push(...key.split('|')[0].split('^')[0].split(','));98 });99 const missingTags = ALL_HTML_TAGS.split(',').filter(tag => extractedTags.indexOf(tag) == -1);100 if (missingTags.length) {101 throw new Error(`DOM schema misses tags: ${missingTags.join(',')}`);102 }103}104function extractRecursiveProperties(105 visited: {[name: string]: boolean}, descMap: Map<string, string[]>, type: Function): string {106 const name = extractName(type)!;107 if (visited[name]) {108 return name;109 }110 let superName: string;111 switch (name) {112 case ELEMENT_IF:113 // ELEMENT_IF is the top most interface (Element | Node)114 superName = '';115 break;116 case HTMLELEMENT_IF:117 superName = ELEMENT_IF;118 break;119 default:120 superName =121 extractRecursiveProperties(visited, descMap, type.prototype.__proto__.constructor);122 }123 let instance: HTMLElement|null = null;124 name.split(',').forEach(tagName => {125 instance = type['name'].startsWith('SVG') ?126 document.createElementNS('http://www.w3.org/2000/svg', tagName.replace(SVG_PREFIX, '')) :127 document.createElement(tagName);128 let htmlType: Function;129 switch (tagName) {130 case 'cite':131 // <cite> interface is `HTMLQuoteElement`132 htmlType = HTMLElement;133 break;134 default:135 htmlType = type;136 }137 if (!(instance instanceof htmlType)) {138 throw new Error(`Tag <${tagName}> is not an instance of ${htmlType['name']}`);139 }140 });141 extractProperties(type, instance, visited, descMap, name, superName);142 return name;143}144function extractProperties(145 type: Function, instance: any, visited: {[name: string]: boolean},146 descMap: Map<string, string[]>, name: string, superName: string) {147 if (!type) return;148 visited[name] = true;149 const fullName = name + (superName ? '^' + superName : '');150 const props: string[] = descMap.has(fullName) ? descMap.get(fullName)! : [];151 const prototype = type.prototype;152 const keys = Object.getOwnPropertyNames(prototype);153 keys.sort();154 keys.forEach((name) => {155 if (name.startsWith('on')) {156 props.push('*' + name.slice(2));157 } else {158 const typeCh = _TYPE_MNEMONICS[typeof instance[name]];159 const descriptor = Object.getOwnPropertyDescriptor(prototype, name);160 const isSetter = descriptor && descriptor.set;161 if (typeCh !== void 0 && !name.startsWith('webkit') && isSetter) {162 props.push(typeCh + name);163 }164 }165 });166 // There is no point in using `Node.nodeValue`, filter it out167 descMap.set(fullName, type === Node ? props.filter(p => p != '%nodeValue') : props);168}169function extractName(type: Function): string|null {170 let name = type['name'];171 // The polyfill @webcomponents/custom-element/src/native-shim.js overrides the172 // window.HTMLElement and does not have the name property. Check if this is the173 // case and if so, set the name manually.174 if (name === '' && type === HTMLElement) {175 name = 'HTMLElement';176 }177 switch (name) {178 // see https://www.w3.org/TR/html5/index.html179 // TODO(vicb): generate this map from all the element types180 case 'Element':181 return ELEMENT_IF;182 case 'HTMLElement':183 return HTMLELEMENT_IF;184 case 'HTMLImageElement':185 return 'img';186 case 'HTMLAnchorElement':187 return 'a';188 case 'HTMLDListElement':189 return 'dl';190 case 'HTMLDirectoryElement':191 return 'dir';192 case 'HTMLHeadingElement':193 return 'h1,h2,h3,h4,h5,h6';194 case 'HTMLModElement':195 return 'ins,del';196 case 'HTMLOListElement':197 return 'ol';198 case 'HTMLParagraphElement':199 return 'p';200 case 'HTMLQuoteElement':201 return 'q,blockquote,cite';202 case 'HTMLTableCaptionElement':203 return 'caption';204 case 'HTMLTableCellElement':205 return 'th,td';206 case 'HTMLTableColElement':207 return 'col,colgroup';208 case 'HTMLTableRowElement':209 return 'tr';210 case 'HTMLTableSectionElement':211 return 'tfoot,thead,tbody';212 case 'HTMLUListElement':213 return 'ul';214 case 'SVGGraphicsElement':215 return SVG_PREFIX + 'graphics';216 case 'SVGMPathElement':217 return SVG_PREFIX + 'mpath';218 case 'SVGSVGElement':219 return SVG_PREFIX + 'svg';220 case 'SVGTSpanElement':221 return SVG_PREFIX + 'tspan';222 default:223 const isSVG = name.startsWith('SVG');224 if (name.startsWith('HTML') || isSVG) {225 name = name.replace('HTML', '').replace('SVG', '').replace('Element', '');226 if (isSVG && name.startsWith('FE')) {227 name = 'fe' + name.substring(2);228 } else if (name) {229 name = name.charAt(0).toLowerCase() + name.substring(1);230 }231 return isSVG ? SVG_PREFIX + name : name.toLowerCase();232 }233 }234 return null;235}236const _TYPE_MNEMONICS: {[type: string]: string} = {237 'string': '',238 'number': '#',239 'boolean': '!',240 'object': '%',...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3client.runTest(url, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 client.descMap(data.data.testId, function(err, data) {9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14 });15 }16});17Pull requests are welcome. Please follow the [Airbnb JavaScript Style Guide](

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wpt = new wpt();3var options = {4};5wpt.runTest(options, function(err, data) {6 console.log(data);7 wpt.getTestResults(data.data.testId, function(err, data) {8 console.log(data);9 });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack Obama').get();3page.then(function(result) {4 console.log(result);5 console.log(result.infobox.description);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var fs = require('fs');3var tests = wpt.getTests();4var descMap = wpt.descMap(tests);5var descFile = fs.createWriteStream('testDesc.txt');6descFile.on('error', function(err) { console.log(err); });7descFile.write(JSON.stringify(descMap));8descFile.end();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful