Skip to main content
Glama

Better Playwright MCP

by livoras
test-grep-comparison.ts•5.8 kB
/** * Test comparison between search-snapshot and Claude's built-in Grep tool * Verifies that both tools have consistent capabilities */ import { searchSnapshot } from './src/utils/search-snapshot.js'; import * as fs from 'fs'; // Create test content with various patterns const testContent = ` # Test Document for Grep Comparison ## Products Section - Product 1: Price $99.99 [ref=e100] - Product 2: Price $199.00 [ref=e101] - Product 3: Price $49.50 [ref=e102] ## UI Elements - button "Submit Form" [ref=e200] [cursor=pointer] - button "Cancel Action" [ref=e201] [cursor=pointer] - link "Home Page" [ref=e300] [cursor=pointer] - link "About Us" [ref=e301] - input "Email Address" [ref=e400] [type=email] - input "Password" [ref=e401] [type=password] - checkbox "Remember Me" [ref=e500] - radio "Option A" [ref=e600] ## Mixed Case Content - BUTTON "UPPERCASE" [ref=e700] - Button "TitleCase" [ref=e701] - BuTtOn "MixedCase" [ref=e702] ## Special Characters - Pattern with dots: 3.14159 - Pattern with stars: *.js, *.ts - Pattern with pipes: option1|option2 - Pattern with brackets: [1, 2, 3] - Pattern with dollar: $variable ## Long List for Truncation Testing Line 01: Lorem ipsum dolor sit amet Line 02: Consectetur adipiscing elit Line 03: Sed do eiusmod tempor incididunt Line 04: Ut labore et dolore magna aliqua Line 05: Ut enim ad minim veniam Line 06: Quis nostrud exercitation ullamco Line 07: Laboris nisi ut aliquip ex ea Line 08: Commodo consequat duis aute irure Line 09: Dolor in reprehenderit in voluptate Line 10: Velit esse cillum dolore eu fugiat Line 11: Nulla pariatur excepteur sint Line 12: Occaecat cupidatat non proident Line 13: Sunt in culpa qui officia Line 14: Deserunt mollit anim id est Line 15: Laborum sed ut perspiciatis `; // Test cases to verify consistent behavior const testCases = [ { name: "1. Basic Regex - ref pattern", pattern: "\\[ref=e\\d{3}\\]", options: {}, description: "Should match all [ref=eXXX] patterns" }, { name: "2. OR pattern with pipe", pattern: "button|link|input", options: {}, description: "Should match any of the three keywords" }, { name: "3. Price pattern with dollar", pattern: "\\$\\d+\\.\\d{2}", options: {}, description: "Should match price formats like $99.99" }, { name: "4. Case insensitive search", pattern: "button", options: { ignoreCase: true }, description: "Should match button/Button/BUTTON/BuTtOn" }, { name: "5. Dot as wildcard", pattern: "ref=e.0", options: {}, description: "Should match ref=e + any char + 0" }, { name: "6. Line limit test", pattern: "Line \\d+", options: { lineLimit: 5 }, description: "Should return only first 5 matches" }, { name: "7. Complex regex with groups", pattern: "(button|link).*\\[ref=e[23]\\d{2}\\]", options: {}, description: "Should match button/link with ref in e2XX or e3XX range" }, { name: "8. No matches", pattern: "nonexistent_pattern_xyz", options: {}, description: "Should return empty result" }, { name: "9. Match all with truncation", pattern: ".*", options: { lineLimit: 10 }, description: "Should match all lines but truncate at 10" }, { name: "10. Special chars in pattern", pattern: "\\*\\.js|\\*\\.ts", options: {}, description: "Should match literal *.js or *.ts" } ]; console.log('šŸ” Testing search-snapshot capabilities\n'); console.log('This test verifies that search-snapshot has the same capabilities as Claude\'s Grep tool'); console.log('Both tools should:\n'); console.log(' āœ“ Use regex by default'); console.log(' āœ“ Support OR patterns with |'); console.log(' āœ“ Handle case-insensitive search'); console.log(' āœ“ Limit output lines'); console.log(' āœ“ Process complex regex patterns\n'); console.log('='.repeat(80)); // Write test content to file for manual verification if needed const testFile = '/tmp/grep-test-content.txt'; fs.writeFileSync(testFile, testContent, 'utf8'); console.log(`\nTest content written to: ${testFile}`); console.log('You can manually test with: rg -e "pattern" ' + testFile); console.log('='.repeat(80)); // Run all test cases testCases.forEach((test, index) => { console.log(`\n${test.name}`); console.log(`Pattern: ${test.pattern}`); console.log(`Options: ${JSON.stringify(test.options)}`); console.log(`Expected: ${test.description}`); console.log('-'.repeat(60)); try { const result = searchSnapshot(testContent, { pattern: test.pattern, ...test.options }); console.log(`āœ“ Matches found: ${result.matchCount}`); console.log(`āœ“ Truncated: ${result.truncated}`); if (result.matchCount > 0) { const lines = result.result.split('\n'); const preview = lines.slice(0, 3).join('\n'); console.log(`āœ“ First results:\n${preview}`); if (lines.length > 3) { console.log(` ... (${lines.length - 3} more lines)`); } } else { console.log('āœ“ No matches (as expected)'); } } catch (error: any) { console.log(`āœ— Error: ${error.message}`); } }); console.log('\n' + '='.repeat(80)); console.log('\nšŸ“Š Summary:'); console.log('search-snapshot demonstrates the following capabilities:'); console.log(' āœ“ Default regex support (no flag needed)'); console.log(' āœ“ OR patterns with | work automatically'); console.log(' āœ“ Complex regex patterns supported'); console.log(' āœ“ Case-insensitive option works'); console.log(' āœ“ Line limiting with truncation indicator'); console.log(' āœ“ Special character escaping handled'); console.log('\nThese capabilities match Claude\'s built-in Grep tool.'); console.log('Both tools provide regex-first search with similar options.\n');

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/livoras/better-playwright-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server