diff --git a/e2e/share-target.spec.js b/e2e/share-target.spec.js index 57282f7..90a4556 100644 --- a/e2e/share-target.spec.js +++ b/e2e/share-target.spec.js @@ -1,21 +1,47 @@ const { test, expect } = require('@playwright/test'); +// Add a helper function to check if the server is up +async function isServerUp(page) { + try { + const response = await page.goto('http://localhost:5173'); + return response.status() === 200; + } catch (error) { + console.error('Server check failed:', error); + return false; + } +} + test('share-target redirects with URL parameter', async ({ page }) => { + // Check if the server is up + const serverUp = await isServerUp(page); + console.log('Is server up?', serverUp); + const sharedUrl = 'https://example.com/shared-page'; await page.goto(`share-target.html?url=${encodeURIComponent(sharedUrl)}`); - // Wait for navigation to complete - await page.waitForURL(`index.html?url=${encodeURIComponent(sharedUrl)}`); + // Wait for navigation to complete with a shorter timeout + await page.waitForNavigation({ timeout: 5000 }).catch(e => console.log('Navigation timeout:', e)); + + // Log the current URL for debugging + console.log('Current URL:', page.url()); // Check if we've been redirected to the correct URL - expect(page.url()).toContain(`index.html?url=${encodeURIComponent(sharedUrl)}`); + expect(page.url()).toContain(`index.html`); + expect(page.url()).toContain(`url=${encodeURIComponent(sharedUrl)}`); }); test('share-target redirects to index.html when no URL is shared', async ({ page }) => { + // Check if the server is up + const serverUp = await isServerUp(page); + console.log('Is server up?', serverUp); + await page.goto(`share-target.html`); - // Wait for navigation to complete - await page.waitForURL(`index.html`); + // Wait for navigation to complete with a shorter timeout + await page.waitForNavigation({ timeout: 5000 }).catch(e => console.log('Navigation timeout:', e)); + + // Log the current URL for debugging + console.log('Current URL:', page.url()); // Check if we've been redirected to the index.html page expect(page.url()).toContain(`index.html`); diff --git a/playwright.config.js b/playwright.config.js index dc75187..83a35e6 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -3,7 +3,7 @@ const { defineConfig } = require('@playwright/test'); module.exports = defineConfig({ testDir: './e2e', use: { - baseURL: 'http://localhost:3000/listen-UI/', + baseURL: 'http://localhost:5173/listen-UI/', }, webServer: { command: 'npm run dev', diff --git a/public/share-target.js b/public/share-target.js index b35ceda..8ed5ef7 100644 --- a/public/share-target.js +++ b/public/share-target.js @@ -1,5 +1,5 @@ // This function will be called when the PWA receives a share -export function handleShareTarget() { +function handleShareTarget() { const urlParams = new URLSearchParams(window.location.search); const sharedUrl = urlParams.get('url') || urlParams.get('text'); @@ -12,7 +12,7 @@ export function handleShareTarget() { } } -// Call the function when the page loads -if (typeof window !== 'undefined') { +// // Call the function when the page loads +// if (typeof window !== 'undefined') { handleShareTarget(); -} \ No newline at end of file +// } \ No newline at end of file