How to use genNodeList method in Playwright Internal

Best JavaScript code snippet using playwright-internal

aql-profiler.js

Source:aql-profiler.js Github

copy

Full Screen

...432 profHelper.assertIsLevel2Profile(profile);433 // This can't work because of the missing blocks in the stats:434 // profHelper.assertStatsNodesMatchPlanNodes(profile);435 const batches = Math.ceil(rows / defaultBatchSize);436 const expected = genNodeList(rows, batches);437 // Like profHelper.getCompactStatsNodes(), but allows for missing stats438 // nodes.439 const actual = profHelper.zipPlanNodesIntoStatsNodes(profile).map(440 node => (441 node.fromStats ?442 {443 type: node.type,444 calls: node.fromStats.calls,445 items: node.fromStats.items,446 } : {})447 );448 profHelper.assertNodesItemsAndCalls(expected, actual,449 {query, rows, batches, expected, actual});450 }...

Full Screen

Full Screen

aql-profiler-test-helper.js

Source:aql-profiler-test-helper.js Github

copy

Full Screen

...422/// called before the query is executed423/// @param bind function: (rows) => ({rows})424/// must return the bind parameters for the query425/// Example for genNodeList:426/// genNodeList(2500, 3) ===427/// [428/// { type : SingletonNode, calls : 1, items : 1 },429/// { type : EnumerateListNode, calls : 3, items : 2500 },430/// { type : ReturnNode, calls : 3, items : 2500 }431/// ]432/// The number of calls may be a range [min, max], e.g.:433/// { type : EnumerateCollectionNode, calls : [3,5] , items : 2500 }434////////////////////////////////////////////////////////////////////////////////435function runDefaultChecks (436 {437 query,438 genNodeList,439 prepare = () => {},440 bind = rows => ({rows}),441 options = {},442 additionalTestRowCounts = [],443 }444) {445 const testRowCounts = _.uniq(defaultTestRowCounts.concat(additionalTestRowCounts).sort());446 for (const rows of testRowCounts) {447 prepare(rows);448 const profile = db._query(query, bind(rows),449 _.merge(options, {profile: 2, defaultBatchSize})450 ).getExtra();451 assertIsLevel2Profile(profile);452 assertStatsNodesMatchPlanNodes(profile);453 const batches = Math.ceil(rows / defaultBatchSize);454 const expected = genNodeList(rows, batches);455 const actual = getCompactStatsNodes(profile);456 assertNodesItemsAndCalls(expected, actual,457 {query, bind: bind(rows), rows, batches, expected, actual});458 }459}460////////////////////////////////////////////////////////////////////////////////461/// @brief Get an array of arrays of numbers. Each inner array is of length462/// numberOfShards. Specifies the number of rows per shard.463/// @param numberOfShards The number of shards464////////////////////////////////////////////////////////////////////////////////465function clusterTestRowCounts({numberOfShards}) {466 const testRowCounts = [];467 const empty = _.fill(Array(numberOfShards), 0);468 // all shards empty469 // e.g. [0, 0, 0, 0, 0]470 let array = empty.slice();471 testRowCounts.push(array.slice());472 for (const rows of defaultClusterTestRowCounts) {473 // first shard has "rows" documents474 // e.g. [rows, 0, 0, 0, 0]475 array = empty.slice();476 array[0] = rows;477 testRowCounts.push(array);478 if (numberOfShards > 1) {479 // last shard has "rows" documents480 // e.g. [0, 0, 0, 0, rows]481 array = empty.slice();482 array[array.length-1] = rows;483 testRowCounts.push(array);484 }485 // all shards have "rows" documents486 // e.g. [rows, rows, rows, rows, rows]487 array = _.fill(Array(numberOfShards), rows);488 testRowCounts.push(array);489 }490 return testRowCounts;491}492////////////////////////////////////////////////////////////////////////////////493/// @brief Common checks for cluster tests494/// @param col ArangoCollection object495/// @param exampleDocumentsByShard Object, keys are shard ids and values are496/// arrays of documents which the specified shard is responsible for.497/// @param query string - is assumed to have no bind parameter498/// @param genNodeList function: (rowsByShard) => [ { type, calls, items } ]499/// must generate the list of expected nodes, gets a { shard => rows }500/// map (string to number).501////////////////////////////////////////////////////////////////////////////////502function runClusterChecks (503 {504 col,505 exampleDocumentsByShard,506 query,507 genNodeList,508 options = {},509 }510) {511 const numberOfShards = Object.keys(exampleDocumentsByShard).length;512 const testRowCounts = clusterTestRowCounts({numberOfShards});513 const prepareCollection = rowCounts => {514 col.truncate();515 let i = 0;516 for (const [id, exampleDocs] of _.entries(exampleDocumentsByShard)) {517 let num = rowCounts[i];518 const docs = _.takeWhile(exampleDocs, () => num-- > 0);519 col.insert(docs);520 i++;521 }522 const countByShard = col.count(true);523 assert.assertEqual(_.values(countByShard).sort(), rowCounts.slice().sort());524 return countByShard;525 };526 for (const rowCounts of testRowCounts) {527 const rowsByShard = prepareCollection(rowCounts);528 const profile = db._query(query, {},529 _.merge(options, {profile: 2, defaultBatchSize})530 ).getExtra();531 assertIsLevel2Profile(profile);532 assertStatsNodesMatchPlanNodes(profile);533 const expected = genNodeList(rowsByShard);534 const actual = getCompactStatsNodes(profile);535 assertNodesItemsAndCalls(expected, actual,536 {query: query, rowCounts, rowsByShard, expected, actual});537 }538}539////////////////////////////////////////////////////////////////////////////////540/// @brief Fill the passed collections with a balanced binary tree.541/// All existing documents will be deleted in both collections!542/// @param vertexCol A document ArangoCollection543/// @param edgeCol An edge ArangoCollection544/// @param numVertices Number of vertices the binary tree should contain545////////////////////////////////////////////////////////////////////////////////546function createBinaryTree (vertexCol, edgeCol, numVertices) {547 // clear collections...

Full Screen

Full Screen

aql-profiler-noncluster.js

Source:aql-profiler-noncluster.js Github

copy

Full Screen

1 /*jshint globalstrict:true, strict:true, esnext: true */2"use strict";3////////////////////////////////////////////////////////////////////////////////4/// DISCLAIMER5///6/// Copyright 2018 ArangoDB GmbH, Cologne, Germany7///8/// Licensed under the Apache License, Version 2.0 (the "License");9/// you may not use this file except in compliance with the License.10/// You may obtain a copy of the License at11///12/// http://www.apache.org/licenses/LICENSE-2.013///14/// Unless required by applicable law or agreed to in writing, software15/// distributed under the License is distributed on an "AS IS" BASIS,16/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.17/// See the License for the specific language governing permissions and18/// limitations under the License.19///20/// Copyright holder is ArangoDB GmbH, Cologne, Germany21///22/// @author Tobias Gödderz23////////////////////////////////////////////////////////////////////////////////24// contains common code for aql-profiler* tests25const profHelper = require("@arangodb/aql-profiler-test-helper");26const _ = require('lodash');27const db = require('@arangodb').db;28const jsunity = require("jsunity");29////////////////////////////////////////////////////////////////////////////////30/// @file test suite for AQL tracing/profiling: noncluster tests31/// Contains tests for EnumerateCollectionBlock, IndexBlock and TraversalBlock.32/// The main test suite (including comments) is in aql-profiler.js.33////////////////////////////////////////////////////////////////////////////////34function ahuacatlProfilerTestSuite () {35 // import some names from profHelper directly into our namespace:36 const colName = profHelper.colName;37 const edgeColName = profHelper.edgeColName;38 const viewName = profHelper.viewName;39 const defaultBatchSize = profHelper.defaultBatchSize;40 const { CalculationNode, CollectNode, DistributeNode, EnumerateCollectionNode,41 EnumerateListNode, EnumerateViewNode, FilterNode, GatherNode, IndexNode,42 InsertNode, LimitNode, NoResultsNode, RemoteNode, RemoveNode, ReplaceNode,43 ReturnNode, ScatterNode, ShortestPathNode, SingletonNode, SortNode,44 SubqueryNode, TraversalNode, UpdateNode, UpsertNode } = profHelper;45 const { CalculationBlock, CountCollectBlock, DistinctCollectBlock,46 EnumerateCollectionBlock, EnumerateListBlock, FilterBlock,47 HashedCollectBlock, IndexBlock, LimitBlock, NoResultsBlock, RemoteBlock,48 ReturnBlock, ShortestPathBlock, SingletonBlock, SortBlock,49 SortedCollectBlock, SortingGatherBlock, SubqueryBlock, TraversalBlock,50 UnsortingGatherBlock, RemoveBlock, InsertBlock, UpdateBlock, ReplaceBlock,51 UpsertBlock, ScatterBlock, DistributeBlock, IResearchViewUnorderedBlock,52 IResearchViewBlock, IResearchViewOrderedBlock } = profHelper;53 return {54////////////////////////////////////////////////////////////////////////////////55/// @brief set up56////////////////////////////////////////////////////////////////////////////////57 setUp : function () {58 },59////////////////////////////////////////////////////////////////////////////////60/// @brief tear down61////////////////////////////////////////////////////////////////////////////////62 tearDown : function () {63 db._drop(colName);64 db._drop(edgeColName);65 db._dropView(viewName);66 },67////////////////////////////////////////////////////////////////////////////////68/// @brief test EnumerateCollectionBlock69////////////////////////////////////////////////////////////////////////////////70 testEnumerateCollectionBlock1: function () {71 const col = db._create(colName);72 const prepare = (rows) => {73 col.truncate();74 col.insert(_.range(1, rows + 1).map((i) => ({value: i})));75 };76 const bind = () => ({'@col': colName});77 const query = `FOR d IN @@col RETURN d.value`;78 const genNodeList = (rows, batches) => {79 if (db._engine().name === 'mmfiles') {80 // mmfiles lies about hasMore when asked for exactly the number of81 // arguments left in the collection, so we have 1 more call when82 // defaultBatchSize divides the actual number of rows.83 // rocksdb on the other hand is exact.84 batches = Math.floor(rows / defaultBatchSize) + 1;85 }86 return [87 {type: SingletonBlock, calls: 1, items: 1},88 {type: EnumerateCollectionBlock, calls: batches, items: rows},89 {type: CalculationBlock, calls: batches, items: rows},90 {type: ReturnBlock, calls: batches, items: rows}91 ];92 };93 profHelper.runDefaultChecks(94 {query, genNodeList, prepare, bind}95 );96 },97////////////////////////////////////////////////////////////////////////////////98/// @brief test IndexBlock99////////////////////////////////////////////////////////////////////////////////100 testIndexBlock1 : function () {101 const col = db._create(colName);102 col.ensureIndex({ type: "hash", fields: [ "value" ] });103 const prepare = (rows) => {104 col.truncate();105 col.insert(_.range(1, rows + 1).map((i) => ({value: i})));106 };107 const bind = (rows) => ({'@col': colName, rows});108 const query = `FOR i IN 1..@rows FOR d IN @@col FILTER i == d.value RETURN d.value`;109 const genNodeList = (rows, batches) => {110 // IndexBlock returns HASMORE when asked for the exact number of items111 // it has left. This could be improved.112 const optimalBatches = Math.ceil(rows / defaultBatchSize);113 const maxIndexBatches = Math.floor(rows / defaultBatchSize) + 1;114 const indexBatches = [optimalBatches, maxIndexBatches];115 return [116 {type: SingletonBlock, calls: 1, items: 1},117 {type: CalculationBlock, calls: 1, items: 1},118 {type: EnumerateListBlock, calls: batches, items: rows},119 {type: IndexBlock, calls: indexBatches, items: rows},120 {type: CalculationBlock, calls: indexBatches, items: rows},121 {type: ReturnBlock, calls: indexBatches, items: rows}122 ];123 };124 profHelper.runDefaultChecks(125 {query, genNodeList, prepare, bind}126 );127 },128////////////////////////////////////////////////////////////////////////////////129/// @brief test IndexBlock, asking for every third document130////////////////////////////////////////////////////////////////////////////////131 testIndexBlock2 : function () {132 const col = db._create(colName);133 col.ensureIndex({ type: "hash", fields: [ "value" ] });134 const prepare = (rows) => {135 col.truncate();136 col.insert(_.range(1, rows + 1).map((i) => ({value: i})));137 };138 const bind = (rows) => ({'@col': colName, rows});139 const query = `FOR i IN 0..FLOOR(@rows / 3)140 FOR d IN @@col141 FILTER i*3+1 == d.value142 RETURN d.value`;143 const genNodeList = (rows) => {144 const enumRows = Math.floor(rows / 3) + 1;145 const enumBatches = Math.ceil(enumRows / defaultBatchSize);146 const indexRows = Math.ceil(rows / 3);147 const optimalBatches = Math.ceil(indexRows / defaultBatchSize);148 // IndexBlock returns HASMORE when asked for the exact number of items149 // it has left. This could be improved.150 const maxIndexBatches = Math.max(1, Math.floor(indexRows / defaultBatchSize) + 1);151 // Number of calls made to the index block. See comment for152 // maxIndexBatches. As of now, maxIndexBatches is exact, but we don't153 // want to fail when this improves.154 const indexBatches = [155 optimalBatches,156 maxIndexBatches157 ];158 return [159 {type: SingletonBlock, calls: 1, items: 1},160 {type: CalculationBlock, calls: 1, items: 1},161 {type: EnumerateListBlock, calls: enumBatches, items: enumRows},162 {type: IndexBlock, calls: indexBatches, items: indexRows},163 {type: CalculationBlock, calls: indexBatches, items: indexRows},164 {type: ReturnBlock, calls: indexBatches, items: indexRows}165 ];166 };167 profHelper.runDefaultChecks(168 {query, genNodeList, prepare, bind}169 );170 },171////////////////////////////////////////////////////////////////////////////////172/// @brief test TraversalBlock: traverse a tree173////////////////////////////////////////////////////////////////////////////////174 testTraversalBlock1: function () {175 const col = db._createDocumentCollection(colName);176 const edgeCol = db._createEdgeCollection(edgeColName);177 const prepare = (rows) => {178 profHelper.createBinaryTree(col, edgeCol, rows);179 };180 const query = `FOR v IN 0..@rows OUTBOUND @root @@edgeCol RETURN v`;181 const rootNodeId = `${colName}/1`;182 const bind = rows => ({183 rows: rows,184 root: rootNodeId,185 '@edgeCol': edgeColName,186 });187 const genNodeList = (rows, batches) => {188 return [189 {type: SingletonBlock, calls: 1, items: 1},190 {type: TraversalBlock, calls: rows % defaultBatchSize === 0 ? batches + 1 : batches, items: rows},191 {type: ReturnBlock, calls: rows % defaultBatchSize === 0 ? batches + 1 : batches, items: rows}192 ];193 };194 profHelper.runDefaultChecks(195 {query, genNodeList, prepare, bind}196 );197 },198////////////////////////////////////////////////////////////////////////////////199/// @brief test TraversalBlock: traverse ~half a tree200////////////////////////////////////////////////////////////////////////////////201 testTraversalBlock2: function () {202 const col = db._createDocumentCollection(colName);203 const edgeCol = db._createEdgeCollection(edgeColName);204 const prepare = (rows) => {205 profHelper.createBinaryTree(col, edgeCol, rows);206 };207 const query = `FOR v IN 0..@depth OUTBOUND @root @@edgeCol RETURN v`;208 const rootNodeId = `${colName}/1`;209 // actual tree depth:210 // const treeDepth = rows => Math.ceil(Math.log2(rows));211 // tree is perfect up to this depth:212 const maxFullDepth = rows => Math.floor(Math.log2(rows));213 // substract one to get rid of ~half the nodes, but never go below 0214 const depth = rows => Math.max(0, maxFullDepth(rows) - 1);215 const bind = rows => ({216 depth: depth(rows),217 root: rootNodeId,218 '@edgeCol': edgeColName,219 });220 const visitedNodes = rows => Math.pow(2, depth(rows)+1)-1;221 const genNodeList = (rows, batches) => {222 rows = visitedNodes(rows);223 batches = Math.ceil(rows / defaultBatchSize);224 return [225 {type: SingletonBlock, calls: 1, items: 1},226 {type: TraversalBlock, calls: batches, items: rows},227 {type: ReturnBlock, calls: batches, items: rows}228 ];229 };230 profHelper.runDefaultChecks(231 {query, genNodeList, prepare, bind}232 );233 },234////////////////////////////////////////////////////////////////////////////////235/// @brief test TraversalBlock: skip ~half a tree236////////////////////////////////////////////////////////////////////////////////237 testTraversalBlock3: function () {238 const col = db._createDocumentCollection(colName);239 const edgeCol = db._createEdgeCollection(edgeColName);240 const prepare = (rows) => {241 profHelper.createBinaryTree(col, edgeCol, rows);242 };243 const query = `FOR v IN @depth..@rows OUTBOUND @root @@edgeCol RETURN v`;244 const rootNodeId = `${colName}/1`;245 // actual tree depth:246 // const treeDepth = rows => Math.ceil(Math.log2(rows));247 // tree is perfect up to this depth:248 const maxFullDepth = rows => Math.floor(Math.log2(rows));249 // substract one to leave ~half the nodes, but never go below 0250 const depth = rows => Math.max(0, maxFullDepth(rows) - 1);251 const bind = rows => ({252 rows: rows,253 depth: depth(rows),254 root: rootNodeId,255 '@edgeCol': edgeColName,256 });257 const skippedNodes = rows => Math.pow(2, depth(rows))-1;258 const visitedNodes = rows => rows - skippedNodes(rows);259 const genNodeList = (rows, batches) => {260 rows = visitedNodes(rows);261 batches = Math.max(1, Math.ceil(rows / defaultBatchSize));262 return [263 {type: SingletonBlock, calls: 1, items: 1},264 {type: TraversalBlock, calls: batches, items: rows},265 {type: ReturnBlock, calls: batches, items: rows}266 ];267 };268 profHelper.runDefaultChecks(269 {query, genNodeList, prepare, bind}270 );271 },272////////////////////////////////////////////////////////////////////////////////273/// @brief test EnumerateViewBlock1274////////////////////////////////////////////////////////////////////////////////275 testEnumerateViewBlock1: function () {276 const col = db._create(colName);277 const view = db._createView(viewName, "arangosearch", { links: { [colName]: { includeAllFields: true } } });278 const prepare = (rows) => {279 col.truncate();280 col.insert(_.range(1, rows + 1).map((i) => ({value: i})));281 };282 const bind = () => ({'@view': viewName});283 const query = `FOR d IN @@view SEARCH d.value != 0 OPTIONS { waitForSync: true } RETURN d.value`;284 const genNodeList = (rows, batches) => {285 // EnumerateViewBlock returns HASMORE when asked for the exact number286 // of items it has left. This could be improved.287 const optimalBatches = Math.ceil(rows / defaultBatchSize);288 const maxViewBatches = Math.floor(rows / defaultBatchSize) + 1;289 const viewBatches = [optimalBatches, maxViewBatches];290 return [291 {type: SingletonBlock, calls: 1, items: 1},292 {type: EnumerateViewNode, calls: viewBatches, items: rows},293 {type: CalculationBlock, calls: rows % defaultBatchSize === 0 ? batches + 1 : batches, items: rows},294 {type: ReturnBlock, calls: rows % defaultBatchSize === 0 ? batches + 1 : batches, items: rows}295 ];296 };297 profHelper.runDefaultChecks(298 {query, genNodeList, prepare, bind}299 );300 },301////////////////////////////////////////////////////////////////////////////////302/// @brief test EnumerateViewBlock2303////////////////////////////////////////////////////////////////////////////////304 testEnumerateViewBlock2: function () {305 const col = db._create(colName);306 const view = db._createView(viewName, "arangosearch", { links: { [colName]: { includeAllFields: true } } });307 const prepare = (rows) => {308 col.truncate();309 col.insert(_.range(1, rows + 1).map((i) => ({value: i})));310 };311 const bind = () => ({'@view': viewName});312 const query = `FOR d IN @@view SEARCH d.value != 0 OPTIONS { waitForSync: true } SORT d.value DESC RETURN d.value`;313 const genNodeList = (rows, batches) => {314 // EnumerateViewBlock returns HASMORE when asked for the exact number315 // of items it has left. This could be improved.316 const optimalBatches = Math.ceil(rows / defaultBatchSize);317 const maxViewBatches = Math.floor(rows / defaultBatchSize) + 1;318 const viewBatches = [optimalBatches, maxViewBatches];319 return [320 {type: SingletonBlock, calls: 1, items: 1},321 {type: EnumerateViewNode, calls: viewBatches, items: rows},322 {type: CalculationBlock, calls: rows % defaultBatchSize === 0 ? batches + 1 : batches, items: rows},323 {type: SortBlock, calls: batches, items: rows},324 {type: ReturnBlock, calls: batches, items: rows}325 ];326 };327 profHelper.runDefaultChecks(328 {query, genNodeList, prepare, bind}329 );330 },331////////////////////////////////////////////////////////////////////////////////332/// @brief test EnumerateViewBlock3333////////////////////////////////////////////////////////////////////////////////334 testEnumerateViewBlock3: function () {335 const col = db._create(colName);336 const view = db._createView(viewName, "arangosearch", { links: { [colName]: { includeAllFields: true } } });337 const prepare = (rows) => {338 col.truncate();339 col.insert(_.range(1, rows + 1).map((i) => ({value: i})));340 };341 const bind = () => ({'@view': viewName});342 const query = `FOR d IN @@view SEARCH d.value != 0 OPTIONS { waitForSync: true } SORT TFIDF(d) ASC, BM25(d) RETURN d.value`;343 const genNodeList = (rows, batches) => {344 // EnumerateViewBlock returns HASMORE when asked for the exact number345 // of items it has left. This could be improved.346 const optimalBatches = Math.ceil(rows / defaultBatchSize);347 const maxViewBatches = Math.floor(rows / defaultBatchSize) + 1;348 const viewBatches = [optimalBatches, maxViewBatches];349 return [350 {type: SingletonBlock, calls: 1, items: 1},351 {type: EnumerateViewNode, calls: viewBatches, items: rows},352 {type: SortBlock, calls: batches, items: rows},353 {type: CalculationBlock, calls: batches, items: rows},354 {type: ReturnBlock, calls: batches, items: rows}355 ];356 };357 profHelper.runDefaultChecks(358 {query, genNodeList, prepare, bind}359 );360 },361 };362}363////////////////////////////////////////////////////////////////////////////////364/// @brief executes the test suite365////////////////////////////////////////////////////////////////////////////////366jsunity.run(ahuacatlProfilerTestSuite);...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...361 } = context362 // node.id 是一个标识符,用来描述函数的名称,即 node.id.name363 push(`function ${node.id.name}`)364 push(`(`)365 genNodeList(node.params, context)366 push(`)`)367 push(`{`)368 // 缩进369 indent()370 // 为函数体生成代码,递归调用 genNode 函数371 node.body.forEach(n => genNode(n, context))372 // 取消缩进373 deIndent()374 push(`}`)375}376export function genArrayExpression (node, context) {377 const {378 push,379 } = context380 push('[')381 genNodeList(node.elements, context)382 push(']')383}384export function genReturnStatement(node, context) {385 const {386 push,387 } = context388 // 追加 return 关键字和空格389 push(`return `)390 // 调用 genNode 函数递归生成返回代码391 genNode(node.return, context)392}393export function genStringLiteral(node, context) {394 const {395 push,396 } = context397 // 对于字符串字面量,只需要追加与 node.value 对应的字符串即可398 push(`'${node.value}'`)399}400export function genCallExpression(node, context) {401 const {402 push,403 } = context404 // 取得被调用函数名称和参数列表405 const {406 callee,407 arguments: args,408 } = node409 // 生成函数代用代码410 push(`${callee.name}(`)411 // 调用 genNodeList 生成参数代码412 genNodeList(args, context)413 // 补全括号414 push(`)`)415}416export function genNodeList(nodes, context) {417 const {418 push,419 } = context420 for (let i = 0; i < nodes.length; i++) {421 const node = nodes[i]422 genNode(node,context)423 if (i < nodes.length - 1) {424 push(', ')425 }426 }427}428export function compile(template) {429 // 模板 ast430 const ast = parse(template)...

Full Screen

Full Screen

genCode.js

Source:genCode.js Github

copy

Full Screen

...229 const multilines =230 nodes.length > 3 || (process.env.NODE_ENV !== 'production' && nodes.some((n) => isArray(n) || !isText$1(n)));231 context.push(`[`);232 multilines && context.indent();233 genNodeList(nodes, context, multilines);234 multilines && context.deindent();235 context.push(`]`);236}237function genNodeList(nodes, context, multilines = false, comma = true) {238 const { push, newline } = context;239 for (let i = 0; i < nodes.length; i++) {240 const node = nodes[i];241 if (isString(node)) {242 push(node);243 } else if (isArray(node)) {244 genNodeListAsArray(node, context);245 } else {246 genNode(node, context);247 }248 if (i < nodes.length - 1) {249 if (multilines) {250 comma && push(',');251 newline();252 } else {253 comma && push(', ');254 }255 }256 }257}258function genNode(node, context) {259 if (isString(node)) {260 context.push(node);261 return;262 }263 if (isSymbol(node)) {264 context.push(context.helper(node));265 return;266 }267 switch (node.type) {268 case 1 /* ELEMENT */:269 case 9 /* IF */:270 case 11 /* FOR */:271 process.env.NODE_ENV !== 'production' &&272 assert(273 node.codegenNode != null,274 `Codegen node is missing for element/if/for node. ` + `Apply appropriate transforms first.`275 );276 genNode(node.codegenNode, context);277 break;278 case 2 /* TEXT */:279 genText(node, context);280 break;281 case 4 /* SIMPLE_EXPRESSION */:282 genExpression(node, context);283 break;284 case 5 /* INTERPOLATION */:285 genInterpolation(node, context);286 break;287 case 12 /* TEXT_CALL */:288 genNode(node.codegenNode, context);289 break;290 case 8 /* COMPOUND_EXPRESSION */:291 genCompoundExpression(node, context);292 break;293 case 3 /* COMMENT */:294 genComment(node, context);295 break;296 case 13 /* VNODE_CALL */:297 genVNodeCall(node, context);298 break;299 case 14 /* JS_CALL_EXPRESSION */:300 genCallExpression(node, context);301 break;302 case 15 /* JS_OBJECT_EXPRESSION */:303 genObjectExpression(node, context);304 break;305 case 17 /* JS_ARRAY_EXPRESSION */:306 genArrayExpression(node, context);307 break;308 case 18 /* JS_FUNCTION_EXPRESSION */:309 genFunctionExpression(node, context);310 break;311 case 19 /* JS_CONDITIONAL_EXPRESSION */:312 genConditionalExpression(node, context);313 break;314 case 20 /* JS_CACHE_EXPRESSION */:315 genCacheExpression(node, context);316 break;317 // SSR only types318 case 21 /* JS_BLOCK_STATEMENT */:319 break;320 case 22 /* JS_TEMPLATE_LITERAL */:321 break;322 case 23 /* JS_IF_STATEMENT */:323 break;324 case 24 /* JS_ASSIGNMENT_EXPRESSION */:325 break;326 case 25 /* JS_SEQUENCE_EXPRESSION */:327 break;328 case 26 /* JS_RETURN_STATEMENT */:329 break;330 /* istanbul ignore next */331 case 10 /* IF_BRANCH */:332 // noop333 break;334 default:335 if (process.env.NODE_ENV !== 'production') {336 assert(false, `unhandled codegen node type: ${node.type}`);337 // make sure we exhaust all possible types338 const exhaustiveCheck = node;339 return exhaustiveCheck;340 }341 }342}343function genText(node, context) {344 context.push(JSON.stringify(node.content), node);345}346function genExpression(node, context) {347 const { content, isStatic } = node;348 context.push(isStatic ? JSON.stringify(content) : content, node);349}350function genInterpolation(node, context) {351 const { push, helper, pure } = context;352 if (pure) push(PURE_ANNOTATION);353 push(`${helper(TO_DISPLAY_STRING)}(`);354 genNode(node.content, context);355 push(`)`);356}357function genCompoundExpression(node, context) {358 for (let i = 0; i < node.children.length; i++) {359 const child = node.children[i];360 if (isString(child)) {361 context.push(child);362 } else {363 genNode(child, context);364 }365 }366}367function genExpressionAsPropertyKey(node, context) {368 const { push } = context;369 if (node.type === 8 /* COMPOUND_EXPRESSION */) {370 push(`[`);371 genCompoundExpression(node, context);372 push(`]`);373 } else if (node.isStatic) {374 // only quote keys if necessary375 const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);376 push(text, node);377 } else {378 push(`[${node.content}]`, node);379 }380}381function genComment(node, context) {382 if (process.env.NODE_ENV !== 'production') {383 const { push, helper, pure } = context;384 if (pure) {385 push(PURE_ANNOTATION);386 }387 push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);388 }389}390function genVNodeCall(node, context) {391 const { push, helper, pure } = context;392 let { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking } = node;393 if (directives) {394 push(helper(WITH_DIRECTIVES) + `(`);395 }396 // 去除优化397 isBlock = false;398 patchFlag = '-2 /* BAIL */';399 dynamicProps = null;400 //401 if (isBlock) {402 push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);403 }404 if (pure) {405 push(PURE_ANNOTATION);406 }407 push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node);408 genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);409 push(`)`);410 if (isBlock) {411 push(`)`);412 }413 if (directives) {414 push(`, `);415 genNode(directives, context);416 push(`)`);417 }418}419function genNullableArgs(args) {420 let i = args.length;421 while (i--) {422 if (args[i] != null) break;423 }424 return args.slice(0, i + 1).map((arg) => arg || `null`);425}426// JavaScript427function genCallExpression(node, context) {428 const { push, helper, pure } = context;429 const callee = isString(node.callee) ? node.callee : helper(node.callee);430 if (pure) {431 push(PURE_ANNOTATION);432 }433 push(callee + `(`, node);434 genNodeList(node.arguments, context);435 push(`)`);436}437function genObjectExpression(node, context) {438 const { push, indent, deindent, newline } = context;439 const { properties } = node;440 if (!properties.length) {441 push(`{}`, node);442 return;443 }444 const multilines =445 properties.length > 1 ||446 (process.env.NODE_ENV !== 'production' && properties.some((p) => p.value.type !== 4 /* SIMPLE_EXPRESSION */));447 push(multilines ? `{` : `{ `);448 multilines && indent();449 for (let i = 0; i < properties.length; i++) {450 const { key, value } = properties[i];451 // key452 genExpressionAsPropertyKey(key, context);453 push(`: `);454 // value455 genNode(value, context);456 if (i < properties.length - 1) {457 // will only reach this if it's multilines458 push(`,`);459 newline();460 }461 }462 multilines && deindent();463 push(multilines ? `}` : ` }`);464}465function genArrayExpression(node, context) {466 genNodeListAsArray(node.elements, context);467}468function genFunctionExpression(node, context) {469 const { push, indent, deindent, scopeId, mode } = context;470 const { params, returns, body, newline, isSlot } = node;471 if (isSlot) {472 // wrap slot functions with owner context473 push(`_${helperNameMap[WITH_CTX]}(`);474 }475 push(`(`, node);476 if (isArray(params)) {477 genNodeList(params, context);478 } else if (params) {479 genNode(params, context);480 }481 push(`) => `);482 if (newline || body) {483 push(`{`);484 indent();485 }486 if (returns) {487 if (newline) {488 push(`return `);489 }490 if (isArray(returns)) {491 genNodeListAsArray(returns, context);...

Full Screen

Full Screen

vnode.js

Source:vnode.js Github

copy

Full Screen

...59 genCacheExpression(node, context)60 break61 // SSR only types62 case 21 /* JS_BLOCK_STATEMENT */:63 genNodeList(node.body, context, true, false)64 break65 case 22 /* JS_TEMPLATE_LITERAL */:66 genTemplateLiteral(node, context)67 break68 case 23 /* JS_IF_STATEMENT */:69 genIfStatement(node, context)70 break71 case 24 /* JS_ASSIGNMENT_EXPRESSION */:72 genAssignmentExpression(node, context)73 break74 case 25 /* JS_SEQUENCE_EXPRESSION */:75 genSequenceExpression(node, context)76 break77 case 26 /* JS_RETURN_STATEMENT */:78 genReturnStatement(node, context)79 break80 }81}82function genVNodeCall(node, context) {83 const { push, helper, pure } = context84 const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking } = node85 if (directives) {86 push(helper(WITH_DIRECTIVES) + `(`)87 }88 if (isBlock) {89 push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `)90 }91 if (pure) {92 push(PURE_ANNOTATION)93 }94 push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node)95 genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context)96 push(`)`)97 if (isBlock) {98 push(`)`)99 }100 if (directives) {101 push(`, `)102 genNode(directives, context)103 push(`)`)104 }105}106function genNullableArgs(args) {107 let i = args.length108 while (i--) {109 if (args[i] != null)110 break111 }112 return args.slice(0, i + 1).map(arg => arg || `null`)113}114function genNodeList(nodes, context, multilines = false, comma = true) {115 const { push, newline } = context116 for (let i = 0; i < nodes.length; i++) {117 const node = nodes[i]118 if (shared.isString(node)) {119 push(node)120 }121 else if (shared.isArray(node)) {122 genNodeListAsArray(node, context)123 }124 else {125 genNode(node, context)126 }127 if (i < nodes.length - 1) {128 if (multilines) {129 comma && push(',')130 newline()131 }132 else {133 comma && push(', ')134 }135 }136 }137}138function genExpression(node, context) {139 const { content, isStatic } = node140 context.push(isStatic ? JSON.stringify(content) : content, node)141}142function genNodeListAsArray(nodes, context) {143 const multilines = nodes.length > 3 || nodes.some(n => isArray(n) || !isText$1(n))144 context.push(`[`)145 multilines && context.indent()146 genNodeList(nodes, context, multilines);147 multilines && context.deindent()148 context.push(`]`)149}150function genConditionalExpression(node, context) {151 const { test, consequent, alternate, newline: needNewline } = node152 const { push, indent, deindent, newline } = context153 // 生成条件表达式154 if (test.type === 4 /* SIMPLE_EXPRESSION */) {155 const needsParens = !isSimpleIdentifier(test.content)156 needsParens && push(`(`)157 genExpression(test, context)158 needsParens && push(`)`)159 }160 else {...

Full Screen

Full Screen

compiler.js

Source:compiler.js Github

copy

Full Screen

...58function genFunctionDecl(node, context) {59 const { push, indent, deIndent } = context;60 push(`function ${node.id.name}`);61 push(`(`);62 genNodeList(node.params, context);63 push(`)`);64 push(`{`);65 indent();66 node.body.forEach((n) => genNode(n, context));67 deIndent();68 push(`}`);69}70// 生成return71// return72function genReturnStatement(node, context) {73 const { push } = context;74 push(`return `);75 genNode(node.return, context);76}77// 生成字符串字面量78// xxx79function genStringLiteral(node, context) {80 const { push } = context;81 // 对于字符串节点,只需拼接node.value82 push(`'${node.value}'`);83}84// 生成函数调用85// h(xxx,xxx)86function genCallExpression(node, context) {87 const { push } = context;88 const { callee, arguments: args } = node;89 push(`${callee}(`);90 genNodeList(args, context);91 push(")");92}93// [xxx,xxx]94function genArrayExpression(node, context) {95 const { push } = context;96 push("[");97 console.log(node)98 genNodeList(node.elements, context);99 push("]");100}101// 生成参数子节点102// xxx,xxx103function genNodeList(nodes, context) {104 const { push } = context;105 for (let i = 0; i < nodes.length; i++) {106 const node = nodes[i];107 genNode(node, context);108 // 除开最后面的参数,之前的每一个参数拼接一个,109 if (i < nodes.length - 1) {110 push(",");111 }112 }...

Full Screen

Full Screen

generate.js

Source:generate.js Github

copy

Full Screen

...45 const { push, indent, deIndent } = context46 47 push(`function ${node.id.name} `)48 push(`(`)49 genNodeList(node.params, context)50 push(`) `)51 push(`{`)52 indent()53 54 node.body.forEach(n => genNode(n, context))55 56 deIndent()57 push(`}`)58}59function genNodeList(nodes, context) {60 if(!nodes) return61 const { push } = context62 for (let i = 0; i < nodes.length; i++) {63 const node = nodes[i]64 genNode(node, context)65 if (i < nodes.length - 1) {66 push(', ')67 }68 }69}70function genReturnStatement(node, context) {71 const { push } = context72 73 push(`return `)74 genNode(node.return, context)75}76function genCallExpression(node, context) {77 const { push } = context78 const { callee, arguments: args } = node79 push(`${callee.name}(`)80 genNodeList(args, context)81 push(`)`)82}83function genStringLiteral(node, context) {84 const { push } = context85 86 push(`'${node.value}'`)87}88function genArrayExpression(node, context) {89 const { push } = context90 push('[')91 genNodeList(node.elements, context)92 push(']')...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const nodeList = await page._client.send('DOM.getDocument', {6 });7 console.log(nodeList);8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const page = await browser.newPage();14 const nodeList = await page._client.send('DOM.getDocument', {15 });16 console.log(nodeList);17 await browser.close();18})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeList } = require('playwright/lib/client/selectorEngine');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.waitForSelector('text=Get started');7 const nodes = await genNodeList(page, 'text=Get started');8 console.log(nodes);9 await browser.close();10})();11 JSHandle@node {12 }13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const page = await browser.newPage();17 await page.waitForSelector('text=Get started');18 const elementHandle = await page.$('text=Get started');19 const element = await elementHandle.$('text=Get started');20 console.log(element);21 await browser.close();22})();23JSHandle@node {24 _context: JSHandle@context {25 _timeoutSettings: TimeoutSettings { _timeout: 30000 },26 _workers: Map(0) {},27 _workersById: Map(0) {},28 _workersByURL: Map(0) {},29 _workersByExecutionContextId: Map(0) {},30 },

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeList } = require('playwright/lib/client/selectorEngine');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const selector = '.navbar__inner .navbar__title';8 const nodeList = await genNodeList(page, selector);9 console.log(nodeList);10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 const selector = '.navbar__inner .navbar__title';18 const locator = await page.$(selector);19 const text = await locator.evaluate((node) => node.innerText);20 console.log(text);21 await browser.close();22})();23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 const selector = '.navbar__inner .navbar__title';29 const locator = await page.$(selector);30 const text = await locator.evaluate((node) => node.innerText);31 console.log(text);32 await browser.close();33})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const { genNodeList } = require('playwright/lib/server/dom.js');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const context = await browser.newContext();6 const input = await page.$('input');7 const nodeList = await genNodeList(input);8 console.log(nodeList);9 await browser.close();10})();11const { chromium } = require('playwright');12const { genNodeList } = require('playwright/lib/server/dom.js');13(async () => {14 const browser = await chromium.launch({ headless: false });15 const context = await browser.newContext();16 const input = await page.$('input');17 const nodeList = await genNodeList(input);18 console.log(nodeList);19 const inputNodeId = nodeList[0].nodeId;20 console.log(inputNodeId);21 await browser.close();22})();23const { chromium } = require('playwright');24const { genNodeList } = require('playwright/lib/server/dom.js');25(async () => {26 const browser = await chromium.launch({ headless: false });27 const context = await browser.newContext();28 const input = await page.$('input');29 const nodeList = await genNodeList(input);30 console.log(nodeList);31 const inputNodeId = nodeList[0].nodeId;32 console.log(inputNodeId);33 const nodeInfo = await page._delegate._session.send('DOM.describeNode', {34 });35 console.log(nodeInfo);36 await browser.close();37})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeList } = require('@playwright/test/lib/server/frames');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const nodeList = await genNodeList(page, '.navbar__inner .navbar__title');7 console.log(nodeList.length);8 await browser.close();9})();10const { genSelector } = require('@playwright/test/lib/server/frames');11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const page = await browser.newPage();15 const selector = await genSelector(page, '.navbar__inner .navbar__title');16 console.log(selector);17 await browser.close();18})();19const { genTestInfo } = require('@playwright/test/lib/test/testInfo');20const { chromium } = require('playwright');21(async () => {22 const browser = await chromium.launch();23 const page = await browser.newPage();24 const testInfo = await genTestInfo(page, 'test');25 console.log(testInfo);26 await browser.close();27})();28const { getTestState } = require('@playwright/test/lib/test

Full Screen

Using AI Code Generation

copy

Full Screen

1const playwright = require('playwright');2const fs = require('fs');3const path = require('path');4const util = require('util');5const writeFile = util.promisify(fs.writeFile);6(async () => {7 for (const browserType of BROWSER) {8 const browser = await playwright[browserType].launch();9 const context = await browser.newContext();10 const page = await context.newPage();11 const genNodeList = await page._client.send('DOM.getDocument', {depth: -1, pierce: true});12 await writeFile(path.join(__dirname, 'genNodeList.json'), JSON.stringify(genNodeList, null, 2));13 await browser.close();14 }15})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeList } = require('playwright/lib/client/selectorEngine');2const { genNodeList } = require('playwright/lib/client/selectorEngine');3const { genNodeList } = require('playwright/lib/client/selectorEngine');4const { genNodeList } = require('playwright/lib/client/selectorEngine');5const { genNodeList } = require('playwright/lib/client/selectorEngine');6const { genNodeList } = require('playwright/lib/client/selectorEngine');7const { genNodeList } = require('playwright/lib/client/selectorEngine');8const { genNodeList } = require('playwright/lib/client/selectorEngine');9const { genNodeList } = require('playwright/lib/client/selectorEngine');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeList } = require('@playwright/test/lib/autowaiting');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const links = await genNodeList(page, 'a');7 console.log(links);8 await browser.close();9})();

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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