Best JavaScript code snippet using playwright-internal
runtime-core.cjs.prod.js
Source:runtime-core.cjs.prod.js
...1199 processCommentNode(n1, n2, container, anchor);1200 }1201 function processSuspense(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) {1202 if (n1 == null) {1203 mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);1204 }1205 else {1206 patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, optimized);1207 }1208 }1209 function mountSuspense(n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) {1210 const hiddenContainer = hostCreateElement('div');1211 const suspense = (n2.suspense = createSuspenseBoundary(n2, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, optimized));1212 const { content, fallback } = normalizeSuspenseChildren(n2);1213 suspense.subTree = content;1214 suspense.fallbackTree = fallback;1215 // start mounting the content subtree in an off-dom container1216 patch(null, content, hiddenContainer, null, parentComponent, suspense, isSVG, optimized);1217 // now check if we have encountered any async deps1218 if (suspense.deps > 0) {1219 // mount the fallback tree1220 patch(null, fallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context1221 isSVG, optimized);1222 n2.el = fallback.el;1223 }1224 else {1225 // Suspense has no async deps. Just resolve.1226 resolveSuspense(suspense);1227 }1228 }1229 function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, optimized) {1230 const suspense = (n2.suspense = n1.suspense);1231 suspense.vnode = n2;1232 const { content, fallback } = normalizeSuspenseChildren(n2);1233 const oldSubTree = suspense.subTree;1234 const oldFallbackTree = suspense.fallbackTree;1235 if (!suspense.isResolved) {1236 patch(oldSubTree, content, suspense.hiddenContainer, null, parentComponent, suspense, isSVG, optimized);1237 if (suspense.deps > 0) {1238 // still pending. patch the fallback tree.1239 patch(oldFallbackTree, fallback, container, anchor, parentComponent, null, // fallback tree will not have suspense context1240 isSVG, optimized);1241 n2.el = fallback.el;1242 }1243 // If deps somehow becomes 0 after the patch it means the patch caused an1244 // async dep component to unmount and removed its dep. It will cause the1245 // suspense to resolve and we don't need to do anything here.1246 }1247 else {1248 // just normal patch inner content as a fragment1249 patch(oldSubTree, content, container, anchor, parentComponent, suspense, isSVG, optimized);1250 n2.el = content.el;1251 }1252 suspense.subTree = content;1253 suspense.fallbackTree = fallback;1254 }1255 function resolveSuspense(suspense) {1256 const { vnode, subTree, fallbackTree, effects, parentComponent, container } = suspense;1257 // this is initial anchor on mount1258 let { anchor } = suspense;1259 // unmount fallback tree1260 if (fallbackTree.el) {1261 // if the fallback tree was mounted, it may have been moved1262 // as part of a parent suspense. get the latest anchor for insertion1263 anchor = getNextHostNode(fallbackTree);1264 unmount(fallbackTree, parentComponent, suspense, true);1265 }1266 // move content from off-dom container to actual container1267 move(subTree, container, anchor);1268 const el = (vnode.el = subTree.el);1269 // suspense as the root node of a component...1270 if (parentComponent && parentComponent.subTree === vnode) {1271 parentComponent.vnode.el = el;1272 updateHOCHostEl(parentComponent, el);1273 }1274 // check if there is a pending parent suspense1275 let parent = suspense.parent;1276 let hasUnresolvedAncestor = false;1277 while (parent) {1278 if (!parent.isResolved) {1279 // found a pending parent suspense, merge buffered post jobs1280 // into that parent1281 parent.effects.push(...effects);1282 hasUnresolvedAncestor = true;1283 break;1284 }1285 parent = parent.parent;1286 }1287 // no pending parent suspense, flush all jobs1288 if (!hasUnresolvedAncestor) {1289 queuePostFlushCb(effects);1290 }1291 suspense.isResolved = true;1292 // invoke @resolve event1293 const onResolve = vnode.props && vnode.props.onResolve;1294 if (isFunction(onResolve)) {1295 onResolve();1296 }1297 }1298 function restartSuspense(suspense) {1299 suspense.isResolved = false;1300 const { vnode, subTree, fallbackTree, parentComponent, container, hiddenContainer, isSVG, optimized } = suspense;1301 // move content tree back to the off-dom container1302 const anchor = getNextHostNode(subTree);1303 move(subTree, hiddenContainer, null);1304 // remount the fallback tree1305 patch(null, fallbackTree, container, anchor, parentComponent, null, // fallback tree will not have suspense context1306 isSVG, optimized);1307 const el = (vnode.el = fallbackTree.el);1308 // suspense as the root node of a component...1309 if (parentComponent && parentComponent.subTree === vnode) {1310 parentComponent.vnode.el = el;1311 updateHOCHostEl(parentComponent, el);1312 }1313 // invoke @suspense event1314 const onSuspense = vnode.props && vnode.props.onSuspense;1315 if (isFunction(onSuspense)) {1316 onSuspense();1317 }1318 }1319 function processComponent(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) {1320 if (n1 == null) {1321 mountComponent(n2, container, anchor, parentComponent, parentSuspense, isSVG);1322 }1323 else {1324 const instance = (n2.component = n1.component);1325 if (shouldUpdateComponent(n1, n2, optimized)) {1326 if (1327 instance.asyncDep &&1328 !instance.asyncResolved) {1329 updateComponentPreRender(instance, n2);1330 return;1331 }1332 else {1333 // normal update1334 instance.next = n2;1335 // instance.update is the reactive effect runner.1336 instance.update();1337 }1338 }1339 else {1340 // no update needed. just copy over properties1341 n2.component = n1.component;1342 n2.el = n1.el;1343 }1344 }1345 if (n2.ref !== null && parentComponent !== null) {1346 setRef(n2.ref, n1 && n1.ref, parentComponent, n2.component.renderProxy);1347 }1348 }1349 function mountComponent(initialVNode, container, anchor, parentComponent, parentSuspense, isSVG) {1350 const instance = (initialVNode.component = createComponentInstance(initialVNode, parentComponent));1351 // resolve props and slots for setup context1352 const propsOptions = initialVNode.type.props;1353 resolveProps(instance, initialVNode.props, propsOptions);1354 resolveSlots(instance, initialVNode.children);1355 // setup stateful logic1356 if (initialVNode.shapeFlag & 4 /* STATEFUL_COMPONENT */) {1357 setupStatefulComponent(instance, parentSuspense);1358 }1359 // setup() is async. This component relies on async logic to be resolved1360 // before proceeding1361 if ( instance.asyncDep) {1362 if (!parentSuspense) {1363 // TODO handle this properly1364 throw new Error('Async component without a suspense boundary!');1365 }1366 // parent suspense already resolved, need to re-suspense1367 // use queueJob so it's handled synchronously after patching the current1368 // suspense tree1369 if (parentSuspense.isResolved) {1370 queueJob(() => {1371 restartSuspense(parentSuspense);1372 });1373 }1374 parentSuspense.deps++;1375 instance.asyncDep1376 .catch(err => {1377 handleError(err, instance, 0 /* SETUP_FUNCTION */);1378 })1379 .then(asyncSetupResult => {1380 // component may be unmounted before resolve1381 if (!instance.isUnmounted && !parentSuspense.isUnmounted) {1382 retryAsyncComponent(instance, asyncSetupResult, parentSuspense, isSVG);1383 }1384 });1385 // give it a placeholder1386 const placeholder = (instance.subTree = createVNode(Comment));1387 processCommentNode(null, placeholder, container, anchor);1388 initialVNode.el = placeholder.el;1389 return;1390 }1391 setupRenderEffect(instance, parentSuspense, initialVNode, container, anchor, isSVG);1392 }1393 function retryAsyncComponent(instance, asyncSetupResult, parentSuspense, isSVG) {1394 parentSuspense.deps--;1395 // retry from this component1396 instance.asyncResolved = true;1397 const { vnode } = instance;1398 handleSetupResult(instance, asyncSetupResult, parentSuspense);1399 setupRenderEffect(instance, parentSuspense, vnode, 1400 // component may have been moved before resolve1401 hostParentNode(instance.subTree.el), getNextHostNode(instance.subTree), isSVG);1402 updateHOCHostEl(instance, vnode.el);1403 if (parentSuspense.deps === 0) {1404 resolveSuspense(parentSuspense);1405 }1406 }1407 function setupRenderEffect(instance, parentSuspense, initialVNode, container, anchor, isSVG) {1408 // create reactive effect for rendering1409 let mounted = false;1410 instance.update = reactivity.effect(function componentEffect() {1411 if (!mounted) {1412 const subTree = (instance.subTree = renderComponentRoot(instance));1413 // beforeMount hook1414 if (instance.bm !== null) {1415 invokeHooks(instance.bm);1416 }1417 patch(null, subTree, container, anchor, instance, parentSuspense, isSVG);1418 initialVNode.el = subTree.el;1419 // mounted hook1420 if (instance.m !== null) {1421 queuePostRenderEffect(instance.m, parentSuspense);1422 }1423 mounted = true;1424 }1425 else {1426 // updateComponent1427 // This is triggered by mutation of component's own state (next: null)1428 // OR parent calling processComponent (next: HostVNode)1429 const { next } = instance;1430 if (next !== null) {1431 updateComponentPreRender(instance, next);1432 }1433 const prevTree = instance.subTree;1434 const nextTree = (instance.subTree = renderComponentRoot(instance));1435 // beforeUpdate hook1436 if (instance.bu !== null) {1437 invokeHooks(instance.bu);1438 }1439 // reset refs1440 // only needed if previous patch had refs1441 if (instance.refs !== EMPTY_OBJ) {1442 instance.refs = {};1443 }1444 patch(prevTree, nextTree, 1445 // parent may have changed if it's in a portal1446 hostParentNode(prevTree.el), 1447 // anchor may have changed if it's in a fragment1448 getNextHostNode(prevTree), instance, parentSuspense, isSVG);1449 instance.vnode.el = nextTree.el;1450 if (next === null) {1451 // self-triggered update. In case of HOC, update parent component1452 // vnode el. HOC is indicated by parent instance's subTree pointing1453 // to child component's vnode1454 updateHOCHostEl(instance, nextTree.el);1455 }1456 // updated hook1457 if (instance.u !== null) {1458 queuePostRenderEffect(instance.u, parentSuspense);1459 }1460 }1461 }, prodEffectOptions);1462 }1463 function updateComponentPreRender(instance, nextVNode) {1464 nextVNode.component = instance;1465 instance.vnode = nextVNode;1466 instance.next = null;1467 resolveProps(instance, nextVNode.props, nextVNode.type.props);1468 resolveSlots(instance, nextVNode.children);1469 }1470 function updateHOCHostEl({ vnode, parent }, el) {1471 while (parent && parent.subTree === vnode) {1472 (vnode = parent.vnode).el = el;1473 parent = parent.parent;1474 }1475 }1476 function patchChildren(n1, n2, container, anchor, parentComponent, parentSuspense, isSVG, optimized = false) {1477 const c1 = n1 && n1.children;1478 const prevShapeFlag = n1 ? n1.shapeFlag : 0;1479 const c2 = n2.children;1480 const { patchFlag, shapeFlag } = n2;1481 if (patchFlag === -1 /* BAIL */) {1482 optimized = false;1483 }1484 // fast path1485 if (patchFlag > 0) {1486 if (patchFlag & 64 /* KEYED_FRAGMENT */) {1487 // this could be either fully-keyed or mixed (some keyed some not)1488 // presence of patchFlag means children are guaranteed to be arrays1489 patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);1490 return;1491 }1492 else if (patchFlag & 128 /* UNKEYED_FRAGMENT */) {1493 // unkeyed1494 patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);1495 return;1496 }1497 }1498 // children has 3 possibilities: text, array or no children.1499 if (shapeFlag & 8 /* TEXT_CHILDREN */) {1500 // text children fast path1501 if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {1502 unmountChildren(c1, parentComponent, parentSuspense);1503 }1504 if (c2 !== c1) {1505 hostSetElementText(container, c2);1506 }1507 }1508 else {1509 if (prevShapeFlag & 16 /* ARRAY_CHILDREN */) {1510 // prev children was array1511 if (shapeFlag & 16 /* ARRAY_CHILDREN */) {1512 // two arrays, cannot assume anything, do full diff1513 patchKeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized);1514 }1515 else {1516 // no new children, just unmount old1517 unmountChildren(c1, parentComponent, parentSuspense, true);1518 }1519 }1520 else {1521 // prev children was text OR null1522 // new children is array OR null1523 if (prevShapeFlag & 8 /* TEXT_CHILDREN */) {1524 hostSetElementText(container, '');1525 }1526 // mount new if array1527 if (shapeFlag & 16 /* ARRAY_CHILDREN */) {1528 mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG);1529 }1530 }1531 }1532 }1533 function patchUnkeyedChildren(c1, c2, container, anchor, parentComponent, parentSuspense, isSVG, optimized) {1534 c1 = c1 || EMPTY_ARR;1535 c2 = c2 || EMPTY_ARR;1536 const oldLength = c1.length;1537 const newLength = c2.length;1538 const commonLength = Math.min(oldLength, newLength);1539 let i;1540 for (i = 0; i < commonLength; i++) {1541 const nextChild = (c2[i] = normalizeVNode(c2[i]));1542 patch(c1[i], nextChild, container, null, parentComponent, parentSuspense, isSVG, optimized);1543 }1544 if (oldLength > newLength) {1545 // remove old1546 unmountChildren(c1, parentComponent, parentSuspense, true, commonLength);1547 }1548 else {1549 // mount new1550 mountChildren(c2, container, anchor, parentComponent, parentSuspense, isSVG, commonLength);1551 }1552 }1553 // can be all-keyed or mixed1554 function patchKeyedChildren(c1, c2, container, parentAnchor, parentComponent, parentSuspense, isSVG, optimized) {1555 let i = 0;1556 const l2 = c2.length;1557 let e1 = c1.length - 1; // prev ending index1558 let e2 = l2 - 1; // next ending index1559 // 1. sync from start1560 // (a b) c1561 // (a b) d e1562 while (i <= e1 && i <= e2) {1563 const n1 = c1[i];1564 const n2 = (c2[i] = normalizeVNode(c2[i]));1565 if (isSameType$1(n1, n2)) {1566 patch(n1, n2, container, parentAnchor, parentComponent, parentSuspense, isSVG, optimized);1567 }1568 else {1569 break;1570 }1571 i++;1572 }1573 // 2. sync from end1574 // a (b c)1575 // d e (b c)1576 while (i <= e1 && i <= e2) {1577 const n1 = c1[e1];1578 const n2 = (c2[e2] = normalizeVNode(c2[e2]));1579 if (isSameType$1(n1, n2)) {1580 patch(n1, n2, container, parentAnchor, parentComponent, parentSuspense, isSVG, optimized);1581 }1582 else {1583 break;1584 }1585 e1--;1586 e2--;1587 }1588 // 3. common sequence + mount1589 // (a b)1590 // (a b) c1591 // i = 2, e1 = 1, e2 = 21592 // (a b)1593 // c (a b)1594 // i = 0, e1 = -1, e2 = 01595 if (i > e1) {1596 if (i <= e2) {1597 const nextPos = e2 + 1;1598 const anchor = nextPos < l2 ? c2[nextPos].el : parentAnchor;1599 while (i <= e2) {1600 patch(null, (c2[i] = normalizeVNode(c2[i])), container, anchor, parentComponent, parentSuspense, isSVG);1601 i++;1602 }1603 }1604 }1605 // 4. common sequence + unmount1606 // (a b) c1607 // (a b)1608 // i = 2, e1 = 2, e2 = 11609 // a (b c)1610 // (b c)1611 // i = 0, e1 = 0, e2 = -11612 else if (i > e2) {1613 while (i <= e1) {1614 unmount(c1[i], parentComponent, parentSuspense, true);1615 i++;1616 }1617 }1618 // 5. unknown sequence1619 // [i ... e1 + 1]: a b [c d e] f g1620 // [i ... e2 + 1]: a b [e d c h] f g1621 // i = 2, e1 = 4, e2 = 51622 else {1623 const s1 = i; // prev starting index1624 const s2 = i; // next starting index1625 // 5.1 build key:index map for newChildren1626 const keyToNewIndexMap = new Map();1627 for (i = s2; i <= e2; i++) {1628 const nextChild = (c2[i] = normalizeVNode(c2[i]));1629 if (nextChild.key != null) {1630 keyToNewIndexMap.set(nextChild.key, i);1631 }1632 }1633 // 5.2 loop through old children left to be patched and try to patch1634 // matching nodes & remove nodes that are no longer present1635 let j;1636 let patched = 0;1637 const toBePatched = e2 - s2 + 1;1638 let moved = false;1639 // used to track whether any node has moved1640 let maxNewIndexSoFar = 0;1641 // works as Map<newIndex, oldIndex>1642 // Note that oldIndex is offset by +11643 // and oldIndex = 0 is a special value indicating the new node has1644 // no corresponding old node.1645 // used for determining longest stable subsequence1646 const newIndexToOldIndexMap = [];1647 for (i = 0; i < toBePatched; i++)1648 newIndexToOldIndexMap.push(0);1649 for (i = s1; i <= e1; i++) {1650 const prevChild = c1[i];1651 if (patched >= toBePatched) {1652 // all new children have been patched so this can only be a removal1653 unmount(prevChild, parentComponent, parentSuspense, true);1654 continue;1655 }1656 let newIndex;1657 if (prevChild.key != null) {1658 newIndex = keyToNewIndexMap.get(prevChild.key);1659 }1660 else {1661 // key-less node, try to locate a key-less node of the same type1662 for (j = s2; j <= e2; j++) {1663 if (newIndexToOldIndexMap[j - s2] === 0 &&1664 isSameType$1(prevChild, c2[j])) {1665 newIndex = j;1666 break;1667 }1668 }1669 }1670 if (newIndex === undefined) {1671 unmount(prevChild, parentComponent, parentSuspense, true);1672 }1673 else {1674 newIndexToOldIndexMap[newIndex - s2] = i + 1;1675 if (newIndex >= maxNewIndexSoFar) {1676 maxNewIndexSoFar = newIndex;1677 }1678 else {1679 moved = true;1680 }1681 patch(prevChild, c2[newIndex], container, null, parentComponent, parentSuspense, isSVG, optimized);1682 patched++;1683 }1684 }1685 // 5.3 move and mount1686 // generate longest stable subsequence only when nodes have moved1687 const increasingNewIndexSequence = moved1688 ? getSequence(newIndexToOldIndexMap)1689 : EMPTY_ARR;1690 j = increasingNewIndexSequence.length - 1;1691 // looping backwards so that we can use last patched node as anchor1692 for (i = toBePatched - 1; i >= 0; i--) {1693 const nextIndex = s2 + i;1694 const nextChild = c2[nextIndex];1695 const anchor = nextIndex + 1 < l21696 ? c2[nextIndex + 1].el1697 : parentAnchor;1698 if (newIndexToOldIndexMap[i] === 0) {1699 // mount new1700 patch(null, nextChild, container, anchor, parentComponent, parentSuspense, isSVG);1701 }1702 else if (moved) {1703 // move if:1704 // There is no stable subsequence (e.g. a reverse)1705 // OR current node is not among the stable sequence1706 if (j < 0 || i !== increasingNewIndexSequence[j]) {1707 move(nextChild, container, anchor);1708 }1709 else {1710 j--;1711 }1712 }1713 }1714 }1715 }1716 function move(vnode, container, anchor) {1717 if (vnode.component !== null) {1718 move(vnode.component.subTree, container, anchor);1719 return;1720 }1721 if ( vnode.type === Suspense) {1722 const suspense = vnode.suspense;1723 move(suspense.isResolved ? suspense.subTree : suspense.fallbackTree, container, anchor);1724 suspense.container = container;1725 return;1726 }1727 if (vnode.type === Fragment) {1728 hostInsert(vnode.el, container, anchor);1729 const children = vnode.children;1730 for (let i = 0; i < children.length; i++) {1731 move(children[i], container, anchor);1732 }1733 hostInsert(vnode.anchor, container, anchor);1734 }1735 else {1736 hostInsert(vnode.el, container, anchor);1737 }1738 }1739 function unmount(vnode, parentComponent, parentSuspense, doRemove) {1740 const { props, ref, type, component, suspense, children, dynamicChildren, shapeFlag, anchor } = vnode;1741 // unset ref1742 if (ref !== null && parentComponent !== null) {1743 setRef(ref, null, parentComponent, null);1744 }1745 if (component != null) {1746 unmountComponent(component, parentSuspense, doRemove);1747 return;1748 }1749 if ( suspense != null) {1750 unmountSuspense(suspense, parentComponent, parentSuspense, doRemove);1751 return;1752 }1753 if (props != null && props.vnodeBeforeUnmount != null) {1754 invokeDirectiveHook(props.vnodeBeforeUnmount, parentComponent, vnode);1755 }1756 const shouldRemoveChildren = type === Fragment && doRemove;1757 if (dynamicChildren != null) {1758 unmountChildren(dynamicChildren, parentComponent, parentSuspense, shouldRemoveChildren);1759 }1760 else if (shapeFlag & 16 /* ARRAY_CHILDREN */) {1761 unmountChildren(children, parentComponent, parentSuspense, shouldRemoveChildren);1762 }1763 if (doRemove) {1764 hostRemove(vnode.el);1765 if (anchor != null)1766 hostRemove(anchor);1767 }1768 if (props != null && props.vnodeUnmounted != null) {1769 queuePostRenderEffect(() => {1770 invokeDirectiveHook(props.vnodeUnmounted, parentComponent, vnode);1771 }, parentSuspense);1772 }1773 }1774 function unmountComponent(instance, parentSuspense, doRemove) {1775 const { bum, effects, update, subTree, um } = instance;1776 // beforeUnmount hook1777 if (bum !== null) {1778 invokeHooks(bum);1779 }1780 if (effects !== null) {1781 for (let i = 0; i < effects.length; i++) {1782 reactivity.stop(effects[i]);1783 }1784 }1785 // update may be null if a component is unmounted before its async1786 // setup has resolved.1787 if (update !== null) {1788 reactivity.stop(update);1789 unmount(subTree, instance, parentSuspense, doRemove);1790 }1791 // unmounted hook1792 if (um !== null) {1793 queuePostRenderEffect(um, parentSuspense);1794 }1795 queuePostFlushCb(() => {1796 instance.isUnmounted = true;1797 });1798 // A component with async dep inside a pending suspense is unmounted before1799 // its async dep resolves. This should remove the dep from the suspense, and1800 // cause the suspense to resolve immediately if that was the last dep.1801 if (1802 parentSuspense !== null &&1803 !parentSuspense.isResolved &&1804 !parentSuspense.isUnmounted &&1805 instance.asyncDep !== null &&1806 !instance.asyncResolved) {1807 parentSuspense.deps--;1808 if (parentSuspense.deps === 0) {1809 resolveSuspense(parentSuspense);1810 }1811 }1812 }1813 function unmountSuspense(suspense, parentComponent, parentSuspense, doRemove) {1814 suspense.isUnmounted = true;1815 unmount(suspense.subTree, parentComponent, parentSuspense, doRemove);1816 if (!suspense.isResolved) {1817 unmount(suspense.fallbackTree, parentComponent, parentSuspense, doRemove);1818 }1819 }1820 function unmountChildren(children, parentComponent, parentSuspense, doRemove, start = 0) {1821 for (let i = start; i < children.length; i++) {1822 unmount(children[i], parentComponent, parentSuspense, doRemove);1823 }1824 }1825 function getNextHostNode({ component, suspense, anchor, el }) {1826 if (component !== null) {1827 return getNextHostNode(component.subTree);
...
ExternalInformation.spec.js
Source:ExternalInformation.spec.js
...74 // we will get warnings that props were not set, but thats fine as we are not testing props75 // Also, if we were to test props, the second parameter of mountSuspense needs to be figured out.76 // There is little documentation on how to test components that use async setup.77 // This is because it is still a new experimental feature.78 wrapper = await mountSuspense(ExternalInformation);79 });80 afterEach(() => {81 jest.resetModules();82 jest.clearAllMocks();83 });84 it("renders NCBIService data to the screen in correct format", async () => {85 expect(NCBIService.getGeneInformation).toHaveBeenCalledTimes(1);86 expect(wrapper.findAll("h5")[0].text()).toMatch(87 NCBIServiceResponse.description + ", " + NCBIServiceResponse.name88 );89 expect(wrapper.findAll("h5")[1].text()).toMatch(90 NCBIServiceResponse.name + " Description"91 );92 expect(wrapper.findAll("p")[0].text()).toMatch(NCBIServiceResponse.summary);...
NewsFeed.spec.js
Source:NewsFeed.spec.js
...42 // we will get warnings that props were not set, but thats fine as we are not testing props43 // Also, if we were to test props, the second parameter of mountSuspense needs to be figured out.44 // There is little documentation on how to test components that use async setup.45 // This is because it is still a new experimental feature.46 wrapper = await mountSuspense(NewsFeed);47 });48 afterEach(() => {49 jest.resetModules();50 jest.clearAllMocks();51 });52 it("renders NewsFeed data to the screen in correct format", async () => {53 expect(NewsFeedService.getNewsFeed).toHaveBeenCalledTimes(1);54 expect(wrapper.findAll("h5")[0].text()).toMatch(55 NewsFeedResponse.data.items[0].title56 );57 expect(wrapper.findAll("blockquote")[0].text()).toMatch(58 NewsFeedResponse.data.items[0].description59 );60 expect(wrapper.findAll("p")[0].text()).toMatch(...
PaymentMethods.test.js
Source:PaymentMethods.test.js
...37 }38 beforeEach(async () => {39 createMeta('session', 'd216cc99-e54f-3425-92d7-62aca86b84fc')40 createMeta('token', 'd216cc99-e54f-3425-92d7-62aca86b84fc')41 wrapper = await mountSuspense(PaymentMethods)42 flushPromises()43 })44 it('can fetch payment methods', () => {45 expect(axios.get).toHaveBeenCalledTimes(1)46 })47 it('can show the payment methods', () => {48 see('Visa credit')49 see('Visa debit')50 })51 it('broadcasts when a payment method is selected', async () => {52 const paymentMethodsComponent = wrapper.findComponent(PaymentMethods)53 paymentMethodsComponent.find('.cursor-pointer').trigger('click')54 expect(paymentMethodsComponent.emitted('select-payment-method')).toBeTruthy()55 expect(paymentMethodsComponent.emitted('select-payment-method')).toHaveLength(1)...
UserInformation.spec.js
Source:UserInformation.spec.js
...14 // we will get warnings that props were not set, but thats fine as we are not testing props15 // Also, if we were to test props, the second parameter of mountSuspense needs to be figured out.16 // There is little documentation on how to test components that use async setup.17 // This is because it is still a new experimental feature.18 wrapper = await mountSuspense(UserInformation);19 });20 afterEach(() => {21 jest.resetModules();22 jest.clearAllMocks();23 });24 it("renders UserInformation data to the screen in correct format", async () => {25 expect(getUserDetails).toHaveBeenCalledTimes(1);26 expect(wrapper.text()).toMatch(27 "Hello " +28 userDetailsResponse.name +29 " from " +30 userDetailsResponse.institution +31 ", these are your user details and available graph data."32 );...
mount-suspense.js
Source:mount-suspense.js
1import {2 defineComponent, h, resolveComponent,3} from 'vue';4import flushPromises from 'flush-promises';5const mountSuspense = async ({6 component, loadingComponent, errorComponent, transitionComponent,7}) => {8 const HSuspense = resolveComponent('h-suspense');9 const slots = {};10 const mainComponent = transitionComponent11 ? (props) => h(transitionComponent, null, () => h(component, props))12 : (props) => h(component, props);13 if (mainComponent) slots.default = mainComponent;14 if (loadingComponent) slots.loading = (props) => h(loadingComponent, props);15 if (errorComponent) slots.error = (props) => h(errorComponent, props);16 const wrapper = defineComponent({17 setup(props, { attrs }) {18 const toBind = { ...attrs, ...props };19 return () => h(HSuspense, toBind, slots);20 },21 });22 await flushPromises();23 return wrapper;24};...
create-component-with-loader.js
Source:create-component-with-loader.js
...12 loadingComponent,13 errorComponent,14 transitionComponent,15 };16 return defineAsyncComponent(() => mountSuspense(params));17};...
MountSuspenseHelper.js
Source:MountSuspenseHelper.js
1import { defineComponent, h, Suspense } from "vue";2import { mount } from "@vue/test-utils";3import flushPromises from "flush-promises";4const mountSuspense = async (component, options) => {5 const wrapper = mount(6 defineComponent({7 render() {8 return h(Suspense, null, {9 default: h(component),10 fallback: h("div", "fallback")11 });12 }13 }),14 options15 );16 await flushPromises();17 return wrapper;18};...
Using AI Code Generation
1const { chromium } = require('playwright');2const { mountSuspense } = require('playwright/internal');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const elementHandle = await page.$('input[name="q"]');7 await mountSuspense(elementHandle);8 await elementHandle.type('Playwright');9 await page.screenshot({ path: 'screenshot.png' });10 await browser.close();11})();
Using AI Code Generation
1const { mountSuspense } = require('playwright/lib/internal/suspense');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 await mountSuspense(page, {8 });9 await page.waitForSelector('text=Playwright is a Node library to automate');10 await page.screenshot({ path: `example.png` });11 await browser.close();12})();13await mountSuspense(page, {14 waitFor: () => document.readyState === 'complete',15});16const cleanup = await mountSuspense(page, {17});18cleanup();19await page.waitForSelector('text=Playwright is a Node library to automate', {20 suspense: {21 },22});23await page.waitForSelector('text=Playwright is a Node library to automate',
Using AI Code Generation
1const { mountSuspense } = require('@playwright/test/lib/server/supplements/suspense');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const handle = await page.$('text=Get Started');7 await mountSuspense(page, handle);8 await page.screenshot({ path: 'example.png' });9 await browser.close();10})();
Using AI Code Generation
1const { mountSuspense } = require('playwright/lib/server/supplements/recorderSupplement.js');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 await page.waitForSelector('input[name="q"]');8 await page.fill('input[name="q"]', 'Hello World');9 await page.keyboard.press('Enter');10 await page.waitForSelector('text=Hello World');11 await mountSuspense(page);12 await page.click('text=Hello World');13 await page.waitForSelector('text=Hello World - Wikipedia');14 await page.click('text=Hello World - Wikipedia');15 await page.waitForSelector('text=Hello World');16 await page.click('text=Hello World');17 await page.waitForSelector(':nth-match(:text("Hello World"), 2)');18 await page.click(':nth-match(:text("Hello World"), 2)');19 await page.waitForSelector(':nth-match(:text("Hello World"), 2)');20 await page.click(':nth-match(:text("Hello World"), 2)');21 await page.waitForSelector('text=Hello World');22 await page.click('text=Hello World');23 await page.waitForSelector(':nth-match(:text("Hello World"), 2)');24 await page.click(':nth-match(:text("Hello World"), 2)');25 await page.waitForSelector(':nth-match(:text("Hello World"), 2)');26 await page.click(':nth-match(:text("Hello World"), 2)');27 await page.waitForSelector('text=Hello World');28 await page.click('text=Hello World');29 await page.waitForSelector(':nth-match(:text("Hello World"), 2)');30 await page.click(':nth-match(:text("Hello World"), 2)');31 await page.waitForSelector(':nth-match(:text("Hello World"), 2)');32 await page.click(':nth-match(:text("Hello World"), 2)');33 await page.waitForSelector('text=Hello World');34 await page.click('text=Hello World');35 await page.waitForSelector(':nth-match(:text("Hello World"), 2)');36 await page.click(':nth-match(:text("Hello World"), 2)');37 await page.waitForSelector(':nth-match(:text("Hello World"), 2)');38 await page.click(':
Using AI Code Generation
1const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');3const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');4const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');5const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');6const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');7const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');8const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');9const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');10const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');11const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');12const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');13const { mountSuspense } = require('playwright/lib/server/supplements/recorder/recorderSupplement');14const { mountSuspense } = require('playwright/lib/server/supplements
Using AI Code Generation
1const { mountSuspense } = require('playwright');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 await page.waitForSelector('#hplogo');5 await mountSuspense(page);6 await page.click('input[name="q"]');7});8const { devices } = require('playwright');9module.exports = {10 use: {11 viewport: { width: 1920, height: 1080 },12 },13};14{15 "scripts": {16 },17 "dependencies": {18 }19}
Using AI Code Generation
1const { mountSuspense } = require("@playwright/test/lib/server/supplements/suspense");2const { test } = require("@playwright/test");3test("test", async ({ page }) => {4 const elementHandle = await page.$("input");5 await mountSuspense(elementHandle, async () => {6 await elementHandle.click();7 });8});9import { PlaywrightTestConfig } from '@playwright/test';10const config: PlaywrightTestConfig = {11 use: {12 },13 {14 use: {15 }16 }17};18export default config;
Using AI Code Generation
1const { mountSuspense } = require('playwright-core/lib/server/supplements/utils/suspenseUtils');2const { chromium } = require('playwright-core');3const path = require('path');4const fs = require('fs');5(async() => {6 const browser = await chromium.launch();7 const context = await browser.newContext();8 const page = await context.newPage();9 const html = fs.readFileSync(path.resolve(__dirname, 'index.html'), 'utf8');10 await page.setContent(html);11 await page.waitForLoadState('networkidle');12 await mountSuspense(page);13 await page.waitForSelector('text=Hello World');14 await browser.close();15})();
Using AI Code Generation
1import { mountSuspense } from 'playwright/lib/server/supplements/recorder/recorderApp';2import { Page } from 'playwright';3import { RecorderApp } from 'playwright/lib/server/supplements/recorder/recorderApp';4export async function mountRecorder(page: Page, recorderApp: RecorderApp) {5 await mountSuspense(page, recorderApp);6}7import { Page } from 'playwright';8import { RecorderApp } from 'playwright/lib/server/supplements/recorder/recorderApp';9export async function mountSuspense(page: Page, recorderApp: RecorderApp) {10 await page.exposeBinding('mountRecorder', (source, ...args) => {11 recorderApp.mount();12 });13}14import { Page } from 'playwright';15import { RecorderApp } from 'playwright/lib/server/supplements/recorder/recorderApp';16export async function mountRecorder(page: Page, recorderApp: RecorderApp) {17 await page.exposeBinding('mountRecorder', (source, ...args) => {18 recorderApp.mount();19 });20}21import { Page } from 'playwright';22import { RecorderApp } from 'playwright/lib/server/supplements/recorder/recorderApp';23export async function mountRecorder(page: Page, recorderApp: RecorderApp) {24 await page.exposeBinding('mountRecorder', (source, ...args) => {25 recorderApp.mount();26 });27}
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.
Get 100 minutes of automation test minutes FREE!!