generated from polymech/site-template
base:url - meta
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { meta } from '../../src/base/url.js';
|
||||
|
||||
describe('url.ts', () => {
|
||||
describe('meta', () => {
|
||||
it('should fetch meta data from a valid URL', async () => {
|
||||
const url = 'https://www.alibaba.com/product-detail/SJ25-SJ35-SJ45-SJ65-single-screw_1600600262552.html';
|
||||
const result = await meta(url);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(result.title).toBeDefined();
|
||||
expect(result.description).toBeDefined();
|
||||
expect(result.image).toBeDefined();
|
||||
expect(result.siteName).toBeDefined();
|
||||
}, 30000); // Increased timeout for network requests
|
||||
|
||||
it('should handle invalid URLs', async () => {
|
||||
const url = 'https://invalid-url-that-does-not-exist.com';
|
||||
const result = await meta(url);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.error).toBeDefined();
|
||||
expect(result.title).toBeUndefined();
|
||||
expect(result.description).toBeUndefined();
|
||||
expect(result.image).toBeUndefined();
|
||||
expect(result.siteName).toBeUndefined();
|
||||
}, 30000);
|
||||
|
||||
it('should use cache for subsequent requests', async () => {
|
||||
const url = 'https://www.alibaba.com/product-detail/SJ25-SJ35-SJ45-SJ65-single-screw_1600600262552.html';
|
||||
|
||||
// First request
|
||||
const firstResult = await meta(url);
|
||||
|
||||
// Second request should be faster and return the same data
|
||||
const secondResult = await meta(url);
|
||||
|
||||
expect(secondResult).toEqual(firstResult);
|
||||
}, 30000);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user