-
-
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.
chore(deps): bump chalk from 4.1.2 to 5.3.0
Bumps [chalk](https://github.com/chalk/chalk) from 4.1.2 to 5.3.0. - [Release notes](https://github.com/chalk/chalk/releases) - [Commits](chalk/chalk@v4.1.2...v5.3.0) --- updated-dependencies: - dependency-name: chalk dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com>
- Loading branch information
1 parent
8b1653d
commit 368a640
Showing
8 changed files
with
171 additions
and
76 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
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,71 @@ | ||
import { ConsoleService } from './ConsoleService'; | ||
import chalk from 'chalk'; | ||
|
||
describe('ConsoleService', () => { | ||
let consoleService: ConsoleService; | ||
|
||
beforeEach(() => { | ||
consoleService = new ConsoleService(); | ||
}); | ||
|
||
describe('info', () => { | ||
it('should write an info message to stdout', () => { | ||
const message = 'This is an info message'; | ||
const expectedOutput = `\n${chalk.yellow('→ ')}${message}\n`; | ||
const writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(); | ||
|
||
consoleService.info(message); | ||
|
||
expect(writeSpy).toHaveBeenCalledWith(expectedOutput); | ||
writeSpy.mockRestore(); | ||
}); | ||
}); | ||
|
||
describe('success', () => { | ||
it('should write a success message to stdout', () => { | ||
const message = 'This is a success message'; | ||
const expectedOutput = `${chalk.green('✓ ')}${message}\n`; | ||
const writeSpy = jest.spyOn(process.stdout, 'write').mockImplementation(); | ||
|
||
consoleService.success(message); | ||
|
||
expect(writeSpy).toHaveBeenCalledWith(expectedOutput); | ||
writeSpy.mockRestore(); | ||
}); | ||
}); | ||
|
||
describe('error', () => { | ||
it('should write a string error message to stderr', () => { | ||
const errorMessage = 'This is a string error message'; | ||
const expectedOutput = `\n${chalk.red(`⚠ ${errorMessage}`)}\n`; | ||
const writeSpy = jest.spyOn(process.stderr, 'write').mockImplementation(); | ||
|
||
consoleService.error(errorMessage); | ||
|
||
expect(writeSpy).toHaveBeenCalledWith(expectedOutput); | ||
writeSpy.mockRestore(); | ||
}); | ||
|
||
it('should write an Error object to stderr', () => { | ||
const error = new Error('This is an error message'); | ||
const expectedOutput = `\n${chalk.red(`⚠ [${error.name}] ${error.message}`)}\n${error.stack}\n`; | ||
const writeSpy = jest.spyOn(process.stderr, 'write').mockImplementation(); | ||
|
||
consoleService.error(error); | ||
|
||
expect(writeSpy).toHaveBeenCalledWith(expectedOutput); | ||
writeSpy.mockRestore(); | ||
}); | ||
|
||
it('should write a JSON error message to stderr', () => { | ||
const error = { message: 'This is a JSON error message' }; | ||
const expectedOutput = `\n${chalk.red(`⚠ `)}${JSON.stringify(error)}\n`; | ||
const writeSpy = jest.spyOn(process.stderr, 'write').mockImplementation(); | ||
|
||
consoleService.error(error); | ||
|
||
expect(writeSpy).toHaveBeenCalledWith(expectedOutput); | ||
writeSpy.mockRestore(); | ||
}); | ||
}); | ||
}); |
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,26 +1,28 @@ | ||
import { green, red, yellow } from "chalk"; | ||
import chalk from "chalk"; | ||
import { injectable } from "inversify"; | ||
|
||
@injectable() | ||
export class ConsoleService { | ||
info(message: string): void { | ||
process.stdout.write(`\n${yellow("→ ")}${message}\n`); | ||
process.stdout.write(`\n${chalk.yellow("→ ")}${message}\n`); | ||
} | ||
|
||
success(message: string): void { | ||
process.stdout.write(`${green("✓ ") + message}\n`); | ||
process.stdout.write(`${chalk.green("✓ ") + message}\n`); | ||
} | ||
|
||
error(error: unknown): void { | ||
if (typeof error === "string") { | ||
process.stderr.write(`\n${red(`⚠ ${error}`)}\n`); | ||
process.stderr.write(`\n${chalk.red(`⚠ ${error}`)}\n`); | ||
return; | ||
} | ||
if (error instanceof Error) { | ||
process.stderr.write(`\n${red(`⚠ [${error.name}] ${error.message}`)}\n${error.stack}\n`); | ||
process.stderr.write( | ||
`\n${chalk.red(`⚠ [${error.name}] ${error.message}`)}\n${error.stack}\n` | ||
); | ||
return; | ||
} | ||
|
||
process.stderr.write(`\n${red(`⚠ `)}${JSON.stringify(error)}\n`); | ||
process.stderr.write(`\n${chalk.red(`⚠ `)}${JSON.stringify(error)}\n`); | ||
} | ||
} |
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