-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add logger tests * chore: add linked list queue * chore: add event emitter tests * chore: move mappers * chore: add interceptors storage tests * chore: add store tests --------- Co-authored-by: Dzianis Dashkevich <ddashkevich@brightcove.com>
- Loading branch information
1 parent
1b98969
commit 5850096
Showing
20 changed files
with
610 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
packages/playback/src/lib/types/interceptor-type-to-interceptor-map.declarations.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...s/event-type-to-event-map.declarations.ts → ...s/event-type-to-event-map.declarations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/playback/src/lib/types/mappers/interceptor-type-to-interceptor-map.declarations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { InterceptorType } from '../../consts/interceptor-type'; | ||
|
||
export interface InterceptorTypeToInterceptorMap { | ||
[InterceptorType.NetworkRequest]: (request: Request) => Promise<Request>; | ||
[InterceptorType.HlsPlaylistParse]: (playlist: Uint8Array) => Promise<Uint8Array>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
class LinkedListQueueNode<T> { | ||
public value: T; | ||
public next: LinkedListQueueNode<T> | null = null; | ||
|
||
public constructor(value: T) { | ||
this.value = value; | ||
} | ||
} | ||
|
||
export class LinkedListQueue<T> { | ||
private head_: LinkedListQueueNode<T> | null = null; | ||
private tail_: LinkedListQueueNode<T> | null = null; | ||
private length_: number = 0; | ||
|
||
public enqueue(value: T): void { | ||
const newNode = new LinkedListQueueNode(value); | ||
|
||
if (this.tail_) { | ||
this.tail_.next = newNode; | ||
} | ||
|
||
this.tail_ = newNode; | ||
|
||
if (!this.head_) { | ||
this.head_ = newNode; | ||
} | ||
|
||
this.length_++; | ||
} | ||
|
||
public dequeue(): T | null { | ||
if (!this.head_) { | ||
return null; | ||
} | ||
|
||
const value = this.head_.value; | ||
this.head_ = this.head_.next; | ||
|
||
if (!this.head_) { | ||
this.tail_ = null; | ||
} | ||
|
||
this.length_--; | ||
return value; | ||
} | ||
|
||
public empty(): void { | ||
this.head_ = null; | ||
this.tail_ = null; | ||
this.length_ = 0; | ||
} | ||
|
||
public get peek(): T | null { | ||
return this.head_ ? this.head_.value : null; | ||
} | ||
|
||
// Get size of the queue | ||
public get size(): number { | ||
return this.length_; | ||
} | ||
|
||
public get isEmpty(): boolean { | ||
return this.length_ === 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import { EventEmitter } from '../../src/lib/utils/event-emitter'; | ||
|
||
describe('EventEmitter', () => { | ||
let emitter: EventEmitter<{ testEvent: string; anotherEvent: string }>; | ||
|
||
beforeEach(() => { | ||
emitter = new EventEmitter(); | ||
}); | ||
|
||
it('should register an event listener when added', () => { | ||
const listener = vi.fn(); | ||
|
||
emitter.addEventListener('testEvent', listener); | ||
emitter.emitEvent({ type: 'testEvent' }); | ||
|
||
expect(listener).toHaveBeenNthCalledWith(1, { type: 'testEvent' }); | ||
}); | ||
|
||
it('should unregister an event listener successfully', () => { | ||
const listener = vi.fn(); | ||
|
||
emitter.addEventListener('testEvent', listener); | ||
emitter.removeEventListener('testEvent', listener); | ||
emitter.emitEvent({ type: 'testEvent' }); | ||
|
||
expect(listener).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should trigger all registered listeners when event is emitted', () => { | ||
const listener1 = vi.fn(); | ||
const listener2 = vi.fn(); | ||
|
||
emitter.addEventListener('testEvent', listener1); | ||
emitter.addEventListener('testEvent', listener2); | ||
emitter.emitEvent({ type: 'testEvent' }); | ||
|
||
expect(listener1).toHaveBeenCalledTimes(1); | ||
expect(listener2).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should register a listener that is triggered only once when using "once"', () => { | ||
const listener = vi.fn(); | ||
|
||
emitter.once('testEvent', listener); | ||
emitter.emitEvent({ type: 'testEvent' }); | ||
emitter.emitEvent({ type: 'testEvent' }); | ||
|
||
expect(listener).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should clear all listeners for a specific event when removed', () => { | ||
const listener1 = vi.fn(); | ||
const listener2 = vi.fn(); | ||
const listener3 = vi.fn(); | ||
|
||
emitter.addEventListener('testEvent', listener1); | ||
emitter.addEventListener('testEvent', listener2); | ||
emitter.addEventListener('anotherEvent', listener3); | ||
|
||
emitter.removeAllEventListenersFor('testEvent'); | ||
emitter.emitEvent({ type: 'testEvent' }); | ||
emitter.emitEvent({ type: 'anotherEvent' }); | ||
|
||
expect(listener1).not.toHaveBeenCalled(); | ||
expect(listener2).not.toHaveBeenCalled(); | ||
expect(listener3).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should clear all event listeners when removeAllEventListeners is called', () => { | ||
const listener1 = vi.fn(); | ||
const listener2 = vi.fn(); | ||
|
||
emitter.addEventListener('testEvent', listener1); | ||
emitter.addEventListener('anotherEvent', listener2); | ||
|
||
emitter.removeAllEventListeners(); | ||
emitter.emitEvent({ type: 'testEvent' }); | ||
emitter.emitEvent({ type: 'anotherEvent' }); | ||
|
||
expect(listener1).not.toHaveBeenCalled(); | ||
expect(listener2).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should register the same listener only once for the same event', () => { | ||
const listener = vi.fn(); | ||
|
||
emitter.addEventListener('testEvent', listener); | ||
emitter.addEventListener('testEvent', listener); | ||
emitter.emitEvent({ type: 'testEvent' }); | ||
|
||
expect(listener).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
Oops, something went wrong.