Skip to content

Commit 6dce90a

Browse files
committed
debug: add console logging to diagnose search failures in CI
1 parent 39ff22a commit 6dce90a

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

tests/e2e/search.spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ const { test, expect } = require('@playwright/test');
22

33
test.describe('Search functionality', () => {
44
test('should find a specific recipe by exact name', async ({ page }) => {
5+
// Capture console logs for debugging
6+
const consoleLogs = [];
7+
page.on('console', msg => {
8+
consoleLogs.push(`${msg.type()}: ${msg.text()}`);
9+
});
10+
11+
// Capture page errors
12+
page.on('pageerror', error => {
13+
console.error('Page error:', error.message);
14+
});
15+
516
await page.goto('/');
617

718
// Find and fill the search input
@@ -18,7 +29,14 @@ test.describe('Search functionality', () => {
1829
await expect(page).toHaveURL(/q=Apple\+Crisp/);
1930

2031
// Wait for search results to load (wait for the "Loading..." text to disappear)
21-
await page.waitForSelector('#search-results:not(:has-text("Loading..."))', { timeout: 30000 });
32+
try {
33+
await page.waitForSelector('#search-results:not(:has-text("Loading..."))', { timeout: 30000 });
34+
} catch (error) {
35+
// Log console output on timeout
36+
console.log('Console logs from page:');
37+
consoleLogs.forEach(log => console.log(log));
38+
throw error;
39+
}
2240

2341
// Check that the search stats show results
2442
const searchStats = page.locator('#search-stats');

themes/cook/assets/js/main.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,33 @@ let fuse = null;
44

55
// Fetch and cache recipe data
66
async function loadRecipeData() {
7-
if (recipeData) return recipeData;
7+
if (recipeData) {
8+
console.log('[loadRecipeData] Using cached recipe data');
9+
return recipeData;
10+
}
811

12+
console.log('[loadRecipeData] Fetching /index.json...');
913
try {
1014
const response = await fetch('/index.json');
15+
console.log('[loadRecipeData] Fetch response status:', response.status);
16+
17+
if (!response.ok) {
18+
throw new Error(`HTTP error! status: ${response.status}`);
19+
}
20+
1121
recipeData = await response.json();
22+
console.log('[loadRecipeData] Recipe data loaded:', Object.keys(recipeData).length, 'recipes');
23+
24+
// Check if Fuse.js is available
25+
if (typeof Fuse === 'undefined') {
26+
console.error('[loadRecipeData] Fuse.js is not loaded!');
27+
throw new Error('Fuse.js library not available');
28+
}
29+
console.log('[loadRecipeData] Fuse.js is available');
1230

1331
// Initialize Fuse.js for search
1432
const recipesArray = Object.values(recipeData);
33+
console.log('[loadRecipeData] Initializing Fuse with', recipesArray.length, 'recipes');
1534
fuse = new Fuse(recipesArray, {
1635
keys: [
1736
{ name: 'title', weight: 3 },
@@ -23,10 +42,11 @@ async function loadRecipeData() {
2342
includeScore: true,
2443
ignoreLocation: true
2544
});
45+
console.log('[loadRecipeData] Fuse initialized successfully');
2646

2747
return recipeData;
2848
} catch (error) {
29-
console.error('Failed to load recipe data:', error);
49+
console.error('[loadRecipeData] Failed to load recipe data:', error);
3050
return null;
3151
}
3252
}
@@ -91,29 +111,42 @@ window.pickRandomRecipe = async function() {
91111

92112
// Perform search and display results
93113
async function performSearch() {
114+
console.log('[performSearch] Starting search');
94115
const urlParams = new URLSearchParams(window.location.search);
95116
const query = urlParams.get('q');
96117
const searchQueryInput = document.getElementById('search-query');
97118
const resultsContainer = document.getElementById('search-results');
98119
const statsContainer = document.getElementById('search-stats');
99120

100-
if (!query || !resultsContainer) return;
121+
console.log('[performSearch] Query:', query);
122+
console.log('[performSearch] Results container exists:', !!resultsContainer);
123+
124+
if (!query || !resultsContainer) {
125+
console.log('[performSearch] Missing query or results container, exiting');
126+
return;
127+
}
101128

102129
// Set the search input value
103130
if (searchQueryInput) {
104131
searchQueryInput.value = query;
105132
}
106133

107134
// Load recipe data and ensure Fuse is initialized
135+
console.log('[performSearch] Loading recipe data...');
108136
await loadRecipeData();
109137

138+
console.log('[performSearch] Fuse initialized:', !!fuse);
139+
110140
if (!fuse) {
141+
console.error('[performSearch] Fuse not initialized, showing error message');
111142
resultsContainer.innerHTML = '<p class="text-muted-foreground italic col-span-2">Failed to load search index</p>';
112143
return;
113144
}
114145

115146
// Perform search
147+
console.log('[performSearch] Performing search for:', query);
116148
const results = fuse.search(query);
149+
console.log('[performSearch] Search results count:', results.length);
117150

118151
// Display stats
119152
if (statsContainer) {

0 commit comments

Comments
 (0)