53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import { beforeAll, describe, expect, it } from 'vitest';
|
||
import { scraperNetflix } from '../src/index.js';
|
||
import { parseNetflixHtml } from '../src/parser.js';
|
||
|
||
const TEST_URL = 'https://www.netflix.com/title/80189685';
|
||
const UA =
|
||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36';
|
||
|
||
let liveHtml = '';
|
||
|
||
beforeAll(async () => {
|
||
const res = await fetch(TEST_URL, {
|
||
headers: {
|
||
'User-Agent': UA,
|
||
Accept: 'text/html,application/xhtml+xml'
|
||
}
|
||
});
|
||
|
||
if (!res.ok) {
|
||
throw new Error(`Live fetch başarısız: ${res.status}`);
|
||
}
|
||
|
||
liveHtml = await res.text();
|
||
}, 20000);
|
||
|
||
describe('parseNetflixHtml (canlı sayfa)', () => {
|
||
it(
|
||
'static HTML’den en az isim ve yıl bilgisini okur',
|
||
() => {
|
||
const meta = parseNetflixHtml(liveHtml);
|
||
expect(meta.name).toBeTruthy();
|
||
expect(String(meta.name).toLowerCase()).toContain('witcher');
|
||
expect(meta.year).toMatch(/\d{4}/);
|
||
},
|
||
20000
|
||
);
|
||
});
|
||
|
||
describe('scraperNetflix (canlı istek)', () => {
|
||
it(
|
||
'normalize edilmiş url, id ve meta bilgilerini döner',
|
||
async () => {
|
||
const meta = await scraperNetflix(TEST_URL, { headless: false, userAgent: UA });
|
||
expect(meta.url).toBe('https://www.netflix.com/title/80189685');
|
||
expect(meta.id).toBe('80189685');
|
||
expect(meta.name).toBeTruthy();
|
||
expect(String(meta.name).toLowerCase()).toContain('witcher');
|
||
expect(meta.year).toMatch(/\d{4}/);
|
||
},
|
||
20000
|
||
);
|
||
});
|