Skip to content

Commit

Permalink
chore: clean up test file names
Browse files Browse the repository at this point in the history
  • Loading branch information
cgilly2fast committed Sep 3, 2024
1 parent 76e8eeb commit 7f44c7a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 93 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ module.exports = {
moduleNameMapper: {
'^hls.js$': '<rootDir>/test/mocks/hls.mock.ts',
},
testMatch: ['<rootDir>/test/**/*.test.tsx'],
testMatch: ['<rootDir>/test/**/*.spec.tsx'],
}
File renamed without changes.
122 changes: 30 additions & 92 deletions test/mocks/hls.mock.ts
Original file line number Diff line number Diff line change
@@ -1,96 +1,34 @@
import { EventEmitter } from 'eventemitter3';
import { HlsConfig, ManifestParsedData, HlsEventEmitter } from 'hls.js';

const Events = {
MEDIA_ATTACHED: 'hlsMediaAttached',
MANIFEST_PARSED: 'hlsManifestParsed',
ERROR: 'hlsError',
};

const ErrorTypes = {
NETWORK_ERROR: 'networkError',
MEDIA_ERROR: 'mediaError',
KEY_SYSTEM_ERROR: 'keySystemError',
MUX_ERROR: 'muxError',
OTHER_ERROR: 'otherError',
};

const ErrorDetails = {
KEY_SYSTEM_NO_KEYS: 'keySystemNoKeys',
KEY_SYSTEM_NO_ACCESS: 'keySystemNoAccess',
KEY_SYSTEM_NO_SESSION: 'keySystemNoSession',
KEY_SYSTEM_NO_CONFIGURED_LICENSE: 'keySystemNoConfiguredLicense',
KEY_SYSTEM_LICENSE_REQUEST_FAILED: 'keySystemLicenseRequestFailed',
KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED:
'keySystemServerCertificateRequestFailed',
KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED:
'keySystemServerCertificateUpdateFailed',
KEY_SYSTEM_SESSION_UPDATE_FAILED: 'keySystemSessionUpdateFailed',
KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED: 'keySystemStatusOutputRestricted',
KEY_SYSTEM_STATUS_INTERNAL_ERROR: 'keySystemStatusInternalError',
MANIFEST_LOAD_ERROR: 'manifestLoadError',
MANIFEST_LOAD_TIMEOUT: 'manifestLoadTimeOut',
MANIFEST_PARSING_ERROR: 'manifestParsingError',
MANIFEST_INCOMPATIBLE_CODECS_ERROR: 'manifestIncompatibleCodecsError',
LEVEL_EMPTY_ERROR: 'levelEmptyError',
LEVEL_LOAD_ERROR: 'levelLoadError',
LEVEL_LOAD_TIMEOUT: 'levelLoadTimeOut',
LEVEL_PARSING_ERROR: 'levelParsingError',
LEVEL_SWITCH_ERROR: 'levelSwitchError',
AUDIO_TRACK_LOAD_ERROR: 'audioTrackLoadError',
AUDIO_TRACK_LOAD_TIMEOUT: 'audioTrackLoadTimeOut',
SUBTITLE_LOAD_ERROR: 'subtitleTrackLoadError',
SUBTITLE_TRACK_LOAD_TIMEOUT: 'subtitleTrackLoadTimeOut',
FRAG_LOAD_ERROR: 'fragLoadError',
FRAG_LOAD_TIMEOUT: 'fragLoadTimeOut',
FRAG_DECRYPT_ERROR: 'fragDecryptError',
FRAG_PARSING_ERROR: 'fragParsingError',
FRAG_GAP: 'fragGap',
REMUX_ALLOC_ERROR: 'remuxAllocError',
KEY_LOAD_ERROR: 'keyLoadError',
KEY_LOAD_TIMEOUT: 'keyLoadTimeOut',
BUFFER_ADD_CODEC_ERROR: 'bufferAddCodecError',
BUFFER_INCOMPATIBLE_CODECS_ERROR: 'bufferIncompatibleCodecsError',
BUFFER_APPEND_ERROR: 'bufferAppendError',
BUFFER_APPENDING_ERROR: 'bufferAppendingError',
BUFFER_STALLED_ERROR: 'bufferStalledError',
BUFFER_FULL_ERROR: 'bufferFullError',
BUFFER_SEEK_OVER_HOLE: 'bufferSeekOverHole',
BUFFER_NUDGE_ON_STALL: 'bufferNudgeOnStall',
INTERNAL_EXCEPTION: 'internalException',
INTERNAL_ABORTED: 'aborted',
UNKNOWN: 'unknown',
};
import { EventEmitter } from 'eventemitter3'
import { HlsConfig, ManifestParsedData, HlsEventEmitter } from 'hls.js'
import { ErrorDetails, ErrorTypes, Events } from './hlsVars.mock'

class MockHls extends EventEmitter implements HlsEventEmitter {
static isSupported = jest.fn().mockReturnValue(true);
static Events = Events;
static ErrorTypes = ErrorTypes;
static ErrorDetails = ErrorDetails;

attachMedia: jest.Mock;
loadSource: jest.Mock;
startLoad: jest.Mock;
recoverMediaError: jest.Mock;
destroy: jest.Mock;

constructor(config?: HlsConfig) {
super();

this.attachMedia = jest
.fn()
.mockImplementation((media: HTMLMediaElement) => {
this.emit(Events.MEDIA_ATTACHED, { media });
});

this.loadSource = jest.fn().mockImplementation((src: string) => {
this.emit(Events.MANIFEST_PARSED, {} as ManifestParsedData);
});

this.startLoad = jest.fn();
this.recoverMediaError = jest.fn();
this.destroy = jest.fn();
}
static isSupported = jest.fn().mockReturnValue(true)
static Events = Events
static ErrorTypes = ErrorTypes
static ErrorDetails = ErrorDetails

attachMedia: jest.Mock
loadSource: jest.Mock
startLoad: jest.Mock
recoverMediaError: jest.Mock
destroy: jest.Mock

constructor(config?: HlsConfig) {
super()

this.attachMedia = jest.fn().mockImplementation((media: HTMLMediaElement) => {
this.emit(Events.MEDIA_ATTACHED, { media })
})

this.loadSource = jest.fn().mockImplementation((src: string) => {
this.emit(Events.MANIFEST_PARSED, {} as ManifestParsedData)
})

this.startLoad = jest.fn()
this.recoverMediaError = jest.fn()
this.destroy = jest.fn()
}
}

export default MockHls;
export default MockHls
58 changes: 58 additions & 0 deletions test/mocks/hlsVars.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export const Events = {
MEDIA_ATTACHED: 'hlsMediaAttached',
MANIFEST_PARSED: 'hlsManifestParsed',
ERROR: 'hlsError',
}

export const ErrorTypes = {
NETWORK_ERROR: 'networkError',
MEDIA_ERROR: 'mediaError',
KEY_SYSTEM_ERROR: 'keySystemError',
MUX_ERROR: 'muxError',
OTHER_ERROR: 'otherError',
}

export const ErrorDetails = {
KEY_SYSTEM_NO_KEYS: 'keySystemNoKeys',
KEY_SYSTEM_NO_ACCESS: 'keySystemNoAccess',
KEY_SYSTEM_NO_SESSION: 'keySystemNoSession',
KEY_SYSTEM_NO_CONFIGURED_LICENSE: 'keySystemNoConfiguredLicense',
KEY_SYSTEM_LICENSE_REQUEST_FAILED: 'keySystemLicenseRequestFailed',
KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED: 'keySystemServerCertificateRequestFailed',
KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED: 'keySystemServerCertificateUpdateFailed',
KEY_SYSTEM_SESSION_UPDATE_FAILED: 'keySystemSessionUpdateFailed',
KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED: 'keySystemStatusOutputRestricted',
KEY_SYSTEM_STATUS_INTERNAL_ERROR: 'keySystemStatusInternalError',
MANIFEST_LOAD_ERROR: 'manifestLoadError',
MANIFEST_LOAD_TIMEOUT: 'manifestLoadTimeOut',
MANIFEST_PARSING_ERROR: 'manifestParsingError',
MANIFEST_INCOMPATIBLE_CODECS_ERROR: 'manifestIncompatibleCodecsError',
LEVEL_EMPTY_ERROR: 'levelEmptyError',
LEVEL_LOAD_ERROR: 'levelLoadError',
LEVEL_LOAD_TIMEOUT: 'levelLoadTimeOut',
LEVEL_PARSING_ERROR: 'levelParsingError',
LEVEL_SWITCH_ERROR: 'levelSwitchError',
AUDIO_TRACK_LOAD_ERROR: 'audioTrackLoadError',
AUDIO_TRACK_LOAD_TIMEOUT: 'audioTrackLoadTimeOut',
SUBTITLE_LOAD_ERROR: 'subtitleTrackLoadError',
SUBTITLE_TRACK_LOAD_TIMEOUT: 'subtitleTrackLoadTimeOut',
FRAG_LOAD_ERROR: 'fragLoadError',
FRAG_LOAD_TIMEOUT: 'fragLoadTimeOut',
FRAG_DECRYPT_ERROR: 'fragDecryptError',
FRAG_PARSING_ERROR: 'fragParsingError',
FRAG_GAP: 'fragGap',
REMUX_ALLOC_ERROR: 'remuxAllocError',
KEY_LOAD_ERROR: 'keyLoadError',
KEY_LOAD_TIMEOUT: 'keyLoadTimeOut',
BUFFER_ADD_CODEC_ERROR: 'bufferAddCodecError',
BUFFER_INCOMPATIBLE_CODECS_ERROR: 'bufferIncompatibleCodecsError',
BUFFER_APPEND_ERROR: 'bufferAppendError',
BUFFER_APPENDING_ERROR: 'bufferAppendingError',
BUFFER_STALLED_ERROR: 'bufferStalledError',
BUFFER_FULL_ERROR: 'bufferFullError',
BUFFER_SEEK_OVER_HOLE: 'bufferSeekOverHole',
BUFFER_NUDGE_ON_STALL: 'bufferNudgeOnStall',
INTERNAL_EXCEPTION: 'internalException',
INTERNAL_ABORTED: 'aborted',
UNKNOWN: 'unknown',
}

0 comments on commit 7f44c7a

Please sign in to comment.