-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1818 from matthieuRioual/AddLoggerToVueJS
Add Logger to Vue common application
- Loading branch information
Showing
9 changed files
with
102 additions
and
0 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
10 changes: 10 additions & 0 deletions
10
src/main/resources/generator/client/vue/test/spec/common/domain/Logger.fixture.ts.mustache
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,10 @@ | ||
import sinon, { SinonStub } from 'sinon'; | ||
import { Logger } from '@/common/domain/Logger'; | ||
|
||
export interface LoggerFixture extends Logger { | ||
error: SinonStub; | ||
} | ||
|
||
export const stubLogger = (): LoggerFixture => ({ | ||
error: sinon.stub(), | ||
}); |
20 changes: 20 additions & 0 deletions
20
.../resources/generator/client/vue/test/spec/common/secondary/ConsoleLogger.spec.ts.mustache
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,20 @@ | ||
import sinon from 'sinon'; | ||
|
||
import ConsoleLogger from '@/common/secondary/ConsoleLogger'; | ||
|
||
describe('ConsoleLogger', () => { | ||
it('should log an error', () => { | ||
const logger = { | ||
error: sinon.stub(), | ||
}; | ||
const consoleLogger = new ConsoleLogger(logger as any); | ||
const error = new Error('Error message'); | ||
|
||
consoleLogger.error('An error occurs', error); | ||
|
||
const [message, errorPassed] = logger.error.getCall(0).args; | ||
expect(message).toBe('An error occurs\n'); | ||
expect(errorPassed).toBeInstanceOf(Error); | ||
expect(errorPassed.message).toBe('Error message'); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
src/main/resources/generator/client/vue/webapp/app/common/domain/Logger.ts.mustache
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,5 @@ | ||
import { Message } from '@/common/domain/Message'; | ||
|
||
export interface Logger { | ||
error(message: Message, error: Error): void; | ||
} |
1 change: 1 addition & 0 deletions
1
src/main/resources/generator/client/vue/webapp/app/common/domain/Message.ts.mustache
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 @@ | ||
export type Message = string; |
10 changes: 10 additions & 0 deletions
10
...main/resources/generator/client/vue/webapp/app/common/secondary/ConsoleLogger.ts.mustache
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,10 @@ | ||
import { Logger } from '@/common/domain/Logger'; | ||
import { Message } from '@/common/domain/Message'; | ||
|
||
export default class ConsoleLogger implements Logger { | ||
constructor(private logger: Console) {} | ||
|
||
error(message: Message, error: Error) { | ||
this.logger.error(`${message}\n`, error); | ||
} | ||
} |
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