added cli-covarage tool and fixed more tests
This commit is contained in:
parent
b63e58784c
commit
b845a8eade
57 changed files with 11917 additions and 295 deletions
60
libs/utils/test/user-agent.test.ts
Normal file
60
libs/utils/test/user-agent.test.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { describe, expect, it } from 'bun:test';
|
||||
import { getRandomUserAgent } from '../src/user-agent';
|
||||
|
||||
describe('User Agent', () => {
|
||||
describe('getRandomUserAgent', () => {
|
||||
it('should return a user agent string', () => {
|
||||
const userAgent = getRandomUserAgent();
|
||||
expect(typeof userAgent).toBe('string');
|
||||
expect(userAgent.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should return a valid user agent containing Mozilla', () => {
|
||||
const userAgent = getRandomUserAgent();
|
||||
expect(userAgent).toContain('Mozilla');
|
||||
});
|
||||
|
||||
it('should return different user agents on multiple calls', () => {
|
||||
const userAgents = new Set();
|
||||
// Get 20 user agents
|
||||
for (let i = 0; i < 20; i++) {
|
||||
userAgents.add(getRandomUserAgent());
|
||||
}
|
||||
// Should have at least 2 different user agents
|
||||
expect(userAgents.size).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
it('should return user agents with browser identifiers', () => {
|
||||
const userAgent = getRandomUserAgent();
|
||||
const hasBrowser =
|
||||
userAgent.includes('Chrome') ||
|
||||
userAgent.includes('Firefox') ||
|
||||
userAgent.includes('Safari') ||
|
||||
userAgent.includes('Edg');
|
||||
expect(hasBrowser).toBe(true);
|
||||
});
|
||||
|
||||
it('should return user agents with OS identifiers', () => {
|
||||
const userAgent = getRandomUserAgent();
|
||||
const hasOS =
|
||||
userAgent.includes('Windows') ||
|
||||
userAgent.includes('Macintosh') ||
|
||||
userAgent.includes('Mac OS X');
|
||||
expect(hasOS).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle multiple concurrent calls', () => {
|
||||
const promises = Array(10)
|
||||
.fill(null)
|
||||
.map(() => Promise.resolve(getRandomUserAgent()));
|
||||
|
||||
return Promise.all(promises).then(userAgents => {
|
||||
expect(userAgents).toHaveLength(10);
|
||||
userAgents.forEach(ua => {
|
||||
expect(typeof ua).toBe('string');
|
||||
expect(ua.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue