diff --git a/.changeset/fair-walls-smile.md b/.changeset/fair-walls-smile.md new file mode 100644 index 00000000000..546d3360980 --- /dev/null +++ b/.changeset/fair-walls-smile.md @@ -0,0 +1,4 @@ +--- +--- + +chore: adjust logger tests diff --git a/packages/logger/test/index.test.ts b/packages/logger/test/index.test.ts index b9eb3dcbdcd..655af61e57d 100644 --- a/packages/logger/test/index.test.ts +++ b/packages/logger/test/index.test.ts @@ -13,19 +13,26 @@ describe('Logger Tests', () => { beforeEach(() => { debug.enable('test'); - debugSpy = vi.spyOn(debug, 'log'); + debugSpy = vi.spyOn(debug, 'log').mockImplementation(() => ({})); }); afterEach(() => { debugSpy.mockRestore(); }); + // Removes ANSI color codes from strings + function clean(s: string) { + // eslint-disable-next-line no-control-regex + const reg = /\u001b[^m]*?m/g; + return s.replace(reg, ''); + } + it('should log info messages correctly', () => { const log = logger('test'); const message = 'This is a message'; log(message); const callArgs = debugSpy.mock.calls[0][0]; - expect(callArgs).toContain(`test ${message}`); + expect(clean(callArgs)).toContain(`test ${message}`); }); it('should format a b256 string correctly', () => { @@ -39,7 +46,7 @@ describe('Logger Tests', () => { log(formattedMessage, mockAddress); const callArgs = debugSpy.mock.calls[0][0]; - expect(callArgs).toContain('0x123456789abcdef'); + expect(clean(callArgs)).toContain('0x123456789abcdef'); }); it('should prefix log messages correctly using prefixLogger', () => { @@ -53,7 +60,7 @@ describe('Logger Tests', () => { log(message); const callArgs = debugSpy.mock.calls[0][0]; - expect(callArgs).toContain(`${prefix}:${component} ${message}`); + expect(clean(callArgs)).toContain(`${prefix}:${component} ${message}`); }); it('should create a default logger and log messages correctly', () => { @@ -65,7 +72,7 @@ describe('Logger Tests', () => { log(message); const callArgs = debugSpy.mock.calls[0][0]; - expect(callArgs).toContain(`test-component ${message}`); + expect(clean(callArgs)).toContain(`test-component ${message}`); }); it('should format BN values with commas correctly using formatter a', () => {