-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-query): add cli error handling (#1388)
# Overview related: #1383 (comment) - add error handler in commander.js - add logger utils (for consistency) ref: https://github.com/tj/commander.js?tab=readme-ov-file#override-exit-and-output-handling ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests. --------- Co-authored-by: Jonghyeon Ko <[email protected]>
- Loading branch information
Showing
10 changed files
with
70 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@suspensive/react-query": patch | ||
--- | ||
|
||
feat(react-query): add cli error handling |
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
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,26 @@ | ||
import { logger } from './logger' | ||
|
||
describe('logger', () => { | ||
const LOG_PREFIX = '[@suspensive/react-query]' | ||
const consoleLogSpy = vi.spyOn(console, 'log').mockClear() | ||
const consoleErrorSpy = vi.spyOn(console, 'error').mockClear() | ||
|
||
beforeEach(() => { | ||
vi.resetModules() | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('should log a message with console.log', () => { | ||
const testMessage = 'test message' | ||
logger.log(testMessage) | ||
|
||
expect(consoleLogSpy).toHaveBeenCalledWith(LOG_PREFIX, testMessage) | ||
}) | ||
|
||
it('should log a error with console.warn', () => { | ||
const testMessage = 'error message' | ||
logger.error(testMessage) | ||
|
||
expect(consoleErrorSpy).toHaveBeenCalledWith(LOG_PREFIX, testMessage) | ||
}) | ||
}) |
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,6 @@ | ||
const LOG_PREFIX = '[@suspensive/react-query]' | ||
|
||
export const logger = { | ||
log: (message: string) => console.log(LOG_PREFIX, message), | ||
error: (message: string) => console.error(LOG_PREFIX, message), | ||
} |
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,11 +1,12 @@ | ||
import { copy } from './copy' | ||
import { logger } from './logger' | ||
|
||
export function switchVersion(version: number) { | ||
const result = copy(version) | ||
|
||
if (result) { | ||
console.log('[@suspensive/react-query]', `switched to version v${version}`) | ||
logger.log(`switched to version v${version}`) | ||
} else { | ||
console.warn('[@suspensive/react-query]', 'not found version files.') | ||
logger.error('not found version files.') | ||
} | ||
} |