forked from pavlobu/deskreen
-
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.
added custom electron-log logger, husky post-commit
- Loading branch information
Showing
14 changed files
with
326 additions
and
23 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
File renamed without changes.
File renamed without changes.
5 changes: 1 addition & 4 deletions
5
test/reducers/counter.spec.ts → app/features/counter/counter.spec.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
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import Logger from './logger'; | ||
|
||
describe('LoggerWithFilePrefix that uses electron-log', () => { | ||
const filePath = 'some/file/path'; | ||
let log = new Logger(filePath); | ||
const mockLoggerInfoProperty = jest.fn(); | ||
const mockLoggerErrorProperty = jest.fn(); | ||
const mockLoggerWarnProperty = jest.fn(); | ||
const mockLoggerVerboseProperty = jest.fn(); | ||
const mockLoggerDebugProperty = jest.fn(); | ||
const mockLoggerSillyProperty = jest.fn(); | ||
|
||
beforeEach(() => { | ||
mockLoggerInfoProperty.mockClear(); | ||
mockLoggerErrorProperty.mockClear(); | ||
mockLoggerWarnProperty.mockClear(); | ||
mockLoggerVerboseProperty.mockClear(); | ||
mockLoggerDebugProperty.mockClear(); | ||
mockLoggerDebugProperty.mockClear(); | ||
|
||
log = new Logger(filePath); | ||
Object.defineProperty(log, 'electronLog', { | ||
value: { | ||
info: mockLoggerInfoProperty, | ||
error: mockLoggerErrorProperty, | ||
warn: mockLoggerWarnProperty, | ||
verbose: mockLoggerVerboseProperty, | ||
debug: mockLoggerDebugProperty, | ||
silly: mockLoggerSillyProperty, | ||
}, | ||
}); | ||
}); | ||
it('should use internal electronLog.info() with filePath as first argument, when .info() is called', () => { | ||
log.info('some info() log here'); | ||
|
||
expect(mockLoggerInfoProperty).toHaveBeenCalledWith( | ||
filePath, | ||
expect.anything(), | ||
expect.anything() | ||
); | ||
}); | ||
|
||
it('should use internal electronLog.error() with filePath as first argument, when .error() is called', () => { | ||
log.error('some error() log here'); | ||
|
||
expect(mockLoggerErrorProperty).toHaveBeenCalledWith( | ||
filePath, | ||
expect.anything(), | ||
expect.anything() | ||
); | ||
}); | ||
|
||
it('should use internal electronLog.warn() with filePath as first argument, when .warn() is called', () => { | ||
log.warn('some warn() log here'); | ||
|
||
expect(mockLoggerWarnProperty).toHaveBeenCalledWith( | ||
filePath, | ||
expect.anything(), | ||
expect.anything() | ||
); | ||
}); | ||
|
||
it('should use internal electronLog.verbose() with filePath as first argument, when .verbose() is called', () => { | ||
log.verbose('some verbose() log here'); | ||
|
||
expect(mockLoggerVerboseProperty).toHaveBeenCalledWith( | ||
filePath, | ||
expect.anything(), | ||
expect.anything() | ||
); | ||
}); | ||
|
||
it('should use internal electronLog.debug() with filePath as first argument, when .debug() is called', () => { | ||
log.debug('some debug() log here'); | ||
|
||
expect(mockLoggerDebugProperty).toHaveBeenCalledWith( | ||
filePath, | ||
expect.anything(), | ||
expect.anything() | ||
); | ||
}); | ||
|
||
it('should use internal electronLog.silly() with filePath as first argument, when .silly() is called', () => { | ||
log.silly('some silly() log here'); | ||
|
||
expect(mockLoggerSillyProperty).toHaveBeenCalledWith( | ||
filePath, | ||
expect.anything(), | ||
expect.anything() | ||
); | ||
}); | ||
}); |
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,45 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const log = require('electron-log'); | ||
|
||
log.transports.file.level = 'warn'; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
log.transports.console.level = 'silly'; | ||
} else { | ||
log.transports.console.level = 'silly'; // TODO: make false when doing release | ||
} | ||
|
||
export default class LoggerWithFilePrefix { | ||
filenamePath: string; | ||
|
||
electronLog: typeof log; | ||
|
||
constructor(_filenamePath: string) { | ||
this.filenamePath = _filenamePath; | ||
this.electronLog = log; | ||
} | ||
|
||
error(...args: any[]) { | ||
this.electronLog.error(this.filenamePath, ':', ...args); | ||
} | ||
|
||
warn(...args: any[]) { | ||
this.electronLog.warn(this.filenamePath, ':', ...args); | ||
} | ||
|
||
info(...args: any[]) { | ||
this.electronLog.info(this.filenamePath, ':', ...args); | ||
} | ||
|
||
verbose(...args: any[]) { | ||
this.electronLog.verbose(this.filenamePath, ':', ...args); | ||
} | ||
|
||
debug(...args: any[]) { | ||
this.electronLog.debug(this.filenamePath, ':', ...args); | ||
} | ||
|
||
silly(...args: any[]) { | ||
this.electronLog.silly(this.filenamePath, ':', ...args); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import http from 'http'; | ||
import SignalingServer from '../../../../app/server/index'; | ||
|
||
describe('signaling server', () => { | ||
let server: typeof SignalingServer; | ||
beforeEach(() => { | ||
server = SignalingServer; | ||
}); | ||
|
||
afterEach(() => { | ||
server.stop(); | ||
}); | ||
|
||
it('start() should return http.Server', async () => { | ||
const res = await server.start(); | ||
expect(res instanceof http.Server).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.