Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Test cases for NodeFilter and TreeWalker #252

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});