-
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.
- Loading branch information
Showing
7 changed files
with
79 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { logger } from '../utils'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export function logError(error: unknown, eventType: string, listener: Function) { | ||
const errorDetails = (error instanceof Error && error.stack) || String(error); | ||
export function logError(error: unknown, eventType: unknown, listener: unknown) { | ||
logger.warn( | ||
`Caught an error while emitting "${eventType}" event:\n${errorDetails}\nThe listener function was:\n${listener}`, | ||
error, | ||
`Caught an error while emitting %j event in a listener function:\n%s`, | ||
eventType, | ||
listener, | ||
); | ||
} |
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,33 @@ | ||
import { arraysEqual } from './arraysEqual'; | ||
|
||
const EMPTY_OBJECT = {}; | ||
const EMPTY_ARRAY: unknown[] = []; | ||
const FUNCTION = () => {}; | ||
const STRING = 'string'; | ||
const NUMBER = 123; | ||
const BOOLEAN = true; | ||
const ARRAY = [EMPTY_OBJECT, EMPTY_ARRAY, FUNCTION, STRING, NUMBER, BOOLEAN]; | ||
|
||
describe('arraysEqual', () => { | ||
it('should return true for empty arrays', () => { | ||
expect(arraysEqual([], [])).toBe(true); | ||
}); | ||
|
||
it('should return true for the same array', () => { | ||
expect(arraysEqual(ARRAY, ARRAY)).toBe(true); | ||
}); | ||
|
||
it('should return true for arrays with the same elements', () => { | ||
expect(arraysEqual([...ARRAY], [...ARRAY])).toBe(true); | ||
}); | ||
|
||
it('should return false for arrays with different lengths', () => { | ||
const arr1 = Array.from({ length: 1 }); | ||
const arr2 = Array.from({ length: 2 }); | ||
expect(arraysEqual(arr1, arr2)).toBe(false); | ||
}); | ||
|
||
it('should return false for arrays with different elements', () => { | ||
expect(arraysEqual([{}], [{}])).toBe(false); | ||
}); | ||
}); |
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,12 @@ | ||
/* eslint-disable unicorn/no-for-loop */ | ||
export function arraysEqual<T>(a: readonly T[], b: readonly T[]): boolean { | ||
if (a === b) return true; | ||
|
||
if (a.length !== b.length) return false; | ||
|
||
const length = a.length; | ||
for (let index = 0; index < length; index++) { | ||
if (a[index] !== b[index]) return false; | ||
} | ||
return true; | ||
} |
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