epg-grabber
Version:
Node.js CLI tool for grabbing EPG from different sites
43 lines (33 loc) • 1.16 kB
text/typescript
import { escapeString, getUTCDate, parseProxy, sleep } from '../../src/core/utils'
import { it, expect, describe, test, vi } from 'vitest'
import dayjs from 'dayjs'
describe('sleep()', () => {
it('can be skiped during test', async () => {
vi.useFakeTimers()
const promise = sleep(3000)
vi.advanceTimersByTime(3000)
await promise
})
})
describe('escapeString()', () => {
it('can escape string', () => {
const string = 'Música тест dun. &<>"\'\r\n'
expect(escapeString(string)).toBe('Música тест dun. &<>"'')
})
it('can escape url', () => {
const string = 'http://example.com/logos/1TV.png?param1=val¶m2=val'
expect(escapeString(string)).toBe('http://example.com/logos/1TV.png?param1=val&param2=val')
})
})
test('parseProxy()', () => {
const string = 'socks://127.0.0.1:1234'
expect(parseProxy(string)).toMatchObject({
protocol: 'socks'
})
})
describe('getUTCDate()', () => {
it('return original value if it is already UTC date', () => {
const date = dayjs.utc('2022-10-20')
expect(getUTCDate(date).toJSON()).toBe('2022-10-20T00:00:00.000Z')
})
})