mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-19 06:35:53 +08:00
Update canonical-url.test.ts
This commit is contained in:
parent
f2e0bfbfe3
commit
d48ddb8820
@ -1,4 +1,44 @@
|
|||||||
import { normalizeUrl } from './canonical-url';
|
import { normalizeUrl, normalizeUrlOnlyHostname } from './canonical-url';
|
||||||
|
|
||||||
|
describe('normalizeUrlOnlyHostname', () => {
|
||||||
|
it('should remove protocol and www from URL', () => {
|
||||||
|
const url = 'https://www.example.com';
|
||||||
|
const expected = 'example.com';
|
||||||
|
expect(normalizeUrlOnlyHostname(url)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove only protocol if www is not present', () => {
|
||||||
|
const url = 'https://example.com';
|
||||||
|
const expected = 'example.com';
|
||||||
|
expect(normalizeUrlOnlyHostname(url)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle URLs without protocol', () => {
|
||||||
|
const url = 'www.example.com';
|
||||||
|
const expected = 'example.com';
|
||||||
|
expect(normalizeUrlOnlyHostname(url)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle URLs without protocol and www', () => {
|
||||||
|
const url = 'example.com';
|
||||||
|
const expected = 'example.com';
|
||||||
|
expect(normalizeUrlOnlyHostname(url)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle URLs with paths', () => {
|
||||||
|
const url = 'https://www.example.com/path/to/resource';
|
||||||
|
const expected = 'example.com';
|
||||||
|
expect(normalizeUrlOnlyHostname(url)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle invalid URLs gracefully', () => {
|
||||||
|
const url = 'not a valid url';
|
||||||
|
const expected = 'not a valid url';
|
||||||
|
expect(normalizeUrlOnlyHostname(url)).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe('normalizeUrl', () => {
|
describe('normalizeUrl', () => {
|
||||||
it('should remove protocol and www from URL', () => {
|
it('should remove protocol and www from URL', () => {
|
||||||
@ -27,10 +67,22 @@ describe('normalizeUrl', () => {
|
|||||||
|
|
||||||
it('should handle URLs with paths', () => {
|
it('should handle URLs with paths', () => {
|
||||||
const url = 'https://www.example.com/path/to/resource';
|
const url = 'https://www.example.com/path/to/resource';
|
||||||
|
const expected = 'example.com/path/to/resource';
|
||||||
|
expect(normalizeUrl(url)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle URLs with trailing slash', () => {
|
||||||
|
const url = 'https://www.example.com/';
|
||||||
const expected = 'example.com';
|
const expected = 'example.com';
|
||||||
expect(normalizeUrl(url)).toBe(expected);
|
expect(normalizeUrl(url)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle URLs with trailing slash and path', () => {
|
||||||
|
const url = 'https://www.example.com/path/';
|
||||||
|
const expected = 'example.com/path';
|
||||||
|
expect(normalizeUrl(url)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle invalid URLs gracefully', () => {
|
it('should handle invalid URLs gracefully', () => {
|
||||||
const url = 'not a valid url';
|
const url = 'not a valid url';
|
||||||
const expected = 'not a valid url';
|
const expected = 'not a valid url';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user