// tests/integration.test.ts
// Integration tests for SEO Audit MCP Server
import { describe, it, expect, afterAll } from 'vitest';
// Note: These tests require building first (npm run build)
// Run with: npm test
describe('SEO Audit Tools', () => {
// Using a simple, reliable test URL
const testUrl = 'https://example.com';
afterAll(async () => {
// Clean up browser
const { closeBrowser } = await import('../src/utils/browser.js');
await closeBrowser();
});
describe('Page Analysis', () => {
it('should analyze a basic page', async () => {
const { analyzePage } = await import('../src/tools/crawl-page.js');
const result = await analyzePage({ url: testUrl });
expect(result.url).toBe(testUrl);
expect(result.httpStatus).toBe(200);
expect(result.title).toBeTruthy();
expect(result.rendering).toBeDefined();
expect(result.links).toBeDefined();
}, 30000);
it('should detect structured data', async () => {
const { analyzePage } = await import('../src/tools/crawl-page.js');
const result = await analyzePage({ url: testUrl });
expect(result.structuredData).toBeDefined();
expect(Array.isArray(result.structuredData.jsonLd)).toBe(true);
}, 30000);
});
describe('Sitemap Analysis', () => {
it('should analyze robots.txt', async () => {
const { analyzeRobots } = await import('../src/tools/sitemap.js');
const result = await analyzeRobots(testUrl);
expect(result.url).toContain('robots.txt');
expect(typeof result.found).toBe('boolean');
}, 10000);
it('should handle missing sitemap gracefully', async () => {
const { analyzeSiteAccess } = await import('../src/tools/sitemap.js');
const result = await analyzeSiteAccess({ baseUrl: testUrl });
expect(result.baseUrl).toBe(testUrl);
expect(result.summary).toBeDefined();
expect(Array.isArray(result.summary.issues)).toBe(true);
}, 30000);
});
describe('URL Checking', () => {
it('should check URL status codes', async () => {
const { checkUrls } = await import('../src/utils/http.js');
const result = await checkUrls([testUrl, 'https://example.com/nonexistent']);
expect(result.length).toBe(2);
expect(result[0].statusCode).toBe(200);
expect(result[1].statusCode).toBe(404);
}, 20000);
});
});
describe('Browser Utilities', () => {
afterAll(async () => {
const { closeBrowser } = await import('../src/utils/browser.js');
await closeBrowser();
});
it('should extract meta tags', async () => {
const { createPage, navigateToUrl, extractMetaTags } = await import('../src/utils/browser.js');
const { context, page } = await createPage();
await navigateToUrl(page, 'https://example.com');
const meta = await extractMetaTags(page);
expect(meta.title).toBeTruthy();
await context.close();
}, 30000);
it('should detect framework', async () => {
const { createPage, navigateToUrl, detectFramework } = await import('../src/utils/browser.js');
const { context, page } = await createPage();
await navigateToUrl(page, 'https://example.com');
const framework = await detectFramework(page);
expect(['react', 'vue', 'angular', 'next', 'nuxt', 'unknown']).toContain(framework);
await context.close();
}, 30000);
});