Skip to content

Commit

Permalink
add test cases for NodeFilter and TreeWalker (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonPinZ authored Aug 2, 2023
1 parent 7d11794 commit e5fbbac
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/platform/node-filter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Partytown Test Page" />
<title>NodeFilter</title>
<script>
partytown = {
logCalls: true,
logGetters: true,
logSetters: true,
logStackTraces: false,
logScriptExecution: true,
};
</script>
<script src="/~partytown/debug/partytown.js"></script>
</head>
<body>
<h1>NodeFilter</h1>
<div id="nodeFilterProps"></div>
<script type="text/partytown">
(function () {
const nodeFilterEntries = Object.entries(NodeFilter);
document.getElementById('nodeFilterProps').textContent =
nodeFilterEntries.map(([k, v]) => `${k}: ${v}`).join(', ');
})();
</script>

<hr />
<p><a href="/tests/">All Tests</a></p>
</body>
</html>
9 changes: 9 additions & 0 deletions tests/platform/node-filter/node-filter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from '@playwright/test';

test('NodeFilter', async ({ page }) => {
await page.goto('/tests/platform/node-filter/');
await page.waitForSelector('#nodeFilterProps');
const resultDiv = page.locator('#nodeFilterProps');
await expect(resultDiv).toContainText('FILTER_ACCEPT');
});

36 changes: 36 additions & 0 deletions tests/platform/tree-walker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Partytown Test Page" />
<title>TreeWalker</title>
<script>
partytown = {
logCalls: true,
logGetters: true,
logSetters: true,
logStackTraces: false,
logScriptExecution: true,
};
</script>
<script src="/~partytown/debug/partytown.js"></script>
</head>
<body>
<h1>TreeWalker</h1>
<div id="walkerResult"></div>
<script type="text/partytown">
(function () {
const tw = document.createTreeWalker(document.body, 1);
result = [];
do {
result.push(tw.currentNode.nodeName);
} while (tw.nextNode());
document.getElementById('walkerResult').textContent = result.join(' ');
})();
</script>

<hr />
<p><a href="/tests/">All Tests</a></p>
</body>
</html>
9 changes: 9 additions & 0 deletions tests/platform/tree-walker/tree-walker.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test, expect } from '@playwright/test';

test('TreeWalker', async ({ page }) => {
await page.goto('/tests/platform/tree-walker/');
await page.waitForSelector('#walkerResult');
const resultDiv = page.locator('#walkerResult');
await expect(resultDiv).toHaveText('BODY H1 DIV SCRIPT');
});

1 comment on commit e5fbbac

@vercel
Copy link

@vercel vercel bot commented on e5fbbac Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.