Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Update removeUnwantedElements.test.ts

Nicolas042f81ddf21c
diff --git a/apps/api/src/scraper/WebScraper/utils/__tests__/removeUnwantedElements.test.ts b/apps/api/src/scraper/WebScraper/utils/__tests__/removeUnwantedElements.test.ts
index d17ca23cb..18438df22 100644
--- a/apps/api/src/scraper/WebScraper/utils/__tests__/removeUnwantedElements.test.ts
+++ b/apps/api/src/scraper/WebScraper/utils/__tests__/removeUnwantedElements.test.ts
@@ -144,4 +144,32 @@ describe('removeUnwantedElements', () => {
expect(result).not.toContain('<aside>');
expect(result).not.toContain('<footer>');
});
+ it('should include specified tags with class', () => {
+ const html = `<div><main class="main-content">Main Content</main><aside class="remove">Remove</aside><footer class="footer-content">Footer Content</footer></div>`;
+ const options: PageOptions = { onlyIncludeTags: ['.main-content', '.footer-content'] };
+ const result = removeUnwantedElements(html, options);
+ expect(result).toContain('<main class="main-content">Main Content</main>');
+ expect(result).toContain('<footer class="footer-content">Footer Content</footer>');
+ expect(result).not.toContain('<aside class="remove">');
+ });
+
+ it('should include specified tags with id', () => {
+ const html = `<div><main id="main-content">Main Content</main><aside id="remove">Remove</aside><footer id="footer-content">Footer Content</footer></div>`;
+ const options: PageOptions = { onlyIncludeTags: ['#main-content', '#footer-content'] };
+ const result = removeUnwantedElements(html, options);
+ expect(result).toContain('<main id="main-content">Main Content</main>');
+ expect(result).toContain('<footer id="footer-content">Footer Content</footer>');
+ expect(result).not.toContain('<aside id="remove">');
+ });
+
+ it('should include specified tags with mixed class and id', () => {
+ const html = `<div><main class="main-content">Main Content</main><aside id="remove">Remove</aside><footer id="footer-content">Footer Content</footer></div>`;
+ const options: PageOptions = { onlyIncludeTags: ['.main-content', '#footer-content'] };
+ const result = removeUnwantedElements(html, options);
+ expect(result).toContain('<main class="main-content">Main Content</main>');
+ expect(result).toContain('<footer id="footer-content">Footer Content</footer>');
+ expect(result).not.toContain('<aside id="remove">');
+ });
+
+
});