-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
68 lines (59 loc) · 2.26 KB
/
test.js
File metadata and controls
68 lines (59 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import AHScraper from './src/scraper/ahScraper.js';
async function testScraper() {
const scraper = new AHScraper();
console.log('🧪 Testing Albert Heijn Scraper\n');
try {
// Test 1: Search products
console.log('📦 Test 1: Searching for "melk"...');
const searchResults = await scraper.searchProducts('melk', 5);
console.log(`✅ Found ${searchResults.length} products`);
if (searchResults.length > 0) {
console.log('First product:', {
name: searchResults[0].name,
brand: searchResults[0].brand,
price: searchResults[0].price,
id: searchResults[0].id
});
}
console.log('');
// Test 2: Get product details (if we have a product ID)
if (searchResults.length > 0) {
const productId = searchResults[0].id;
console.log(`📝 Test 2: Getting details for product ${productId}...`);
const productDetails = await scraper.getProductDetails(productId);
console.log('✅ Product details retrieved');
console.log('Details:', {
name: productDetails.name,
brand: productDetails.brand,
price: productDetails.price,
hasIngredients: !!productDetails.ingredients,
hasAllergens: !!productDetails.allergens,
hasNutrition: !!productDetails.nutrition
});
console.log('');
}
// Test 3: Get categories
console.log('📂 Test 3: Getting categories...');
const categories = await scraper.getCategories();
console.log(`✅ Found ${categories.length} categories`);
if (categories.length > 0) {
console.log('First 3 categories:', categories.slice(0, 3).map(c => c.name));
}
console.log('');
// Test 4: Cache test (should be instant)
console.log('⚡ Test 4: Testing cache (searching "melk" again)...');
const startTime = Date.now();
const cachedResults = await scraper.searchProducts('melk', 5);
const duration = Date.now() - startTime;
console.log(`✅ Cache hit! Retrieved in ${duration}ms`);
console.log('');
console.log('✨ All tests passed!');
} catch (error) {
console.error('❌ Test failed:', error.message);
console.error(error.stack);
} finally {
await scraper.close();
console.log('\n🔒 Browser closed');
}
}
testScraper();