Files
RSSHub/lib/utils/rand-user-agent.test.ts
T
2024-03-27 15:37:51 +08:00

38 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import got from '@/utils/got';
import { config } from '@/config';
import randUserAgent from '@/utils/rand-user-agent';
const mobileUa = randUserAgent({ browser: 'mobile safari', os: 'ios', device: 'mobile' });
describe('rand-user-agent', () => {
it('chrome should not include headlesschrome', () => {
const uaArr = Array(100)
.fill(null)
.map(() => randUserAgent({ browser: 'chrome', os: 'windows' }));
const match = uaArr.find((e) => !!(e.includes('Chrome-Lighthouse') || e.includes('HeadlessChrome')));
expect(match).toBeFalsy();
});
it('chrome should not include electron', () => {
const uaArr = Array(100)
.fill(null)
.map(() => randUserAgent({ browser: 'chrome', os: 'windows' }));
const match = uaArr.find((e) => !!e.includes('Electron'));
expect(match).toBeFalsy();
});
it('should has default random ua', async () => {
const { data } = await got('http://rsshub.test/ua');
expect(data.ua).toBe(config.ua);
});
it('should match ua configurated', async () => {
const { data } = await got('http://rsshub.test/ua', {
headers: {
'user-agent': mobileUa,
},
});
expect(data.ua).toBe(mobileUa);
});
});