New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
console.Console global reference is undefined in the node environment #10282
Comments
Thanks for the issue, accepting PRs to add |
@jeysal I'll pick it up BufferedConsole: Pretty straightforward, the following is valid export default class BufferedConsole extends Console {
constructor() { }
static Console: NodeJS.ConsoleConstructor = BufferedConsole; CustomConsole: Not straight forward because of the base class. I thought of the following two ways export default class CustomConsole extends Console {
constructor(
stdout: NodeJS.WriteStream,
stderr: NodeJS.WriteStream,
formatBuffer: Formatter) {
}
CustomConsole: CustomConsoleContructor = CustomConsole;
// ...
} export default class CustomConsole extends Console {
constructor(
stdout: NodeJS.WriteStream,
stderr: NodeJS.WriteStream,
formatBuffer: Formatter) {
}
Console: NodeJS.ConsoleContructor = Console;
//...
} Maybe this may be an approach, if the class does not extend Console. export default class CustomConsole {
private _console: Console;
constructor(
stdout: NodeJS.WriteStream,
stderr: NodeJS.WriteStream,
formatBuffer: Formatter = (_type: LogType, message: string): string =>
message,
) {
this._console = new Console(stdout, stderr);
}
Console: CustomConsoleContructor = CustomConsole;
private _log(type: LogType, message: string) {
clearLine(this._stdout);
this._console.log(
this._formatBuffer(type, ' '.repeat(this._groupDepth) + message),
);
}
private _logError(type: LogType, message: string) {
clearLine(this._stderr);
this._console.error(
this._formatBuffer(type, ' '.repeat(this._groupDepth) + message),
);
} Any thoughts? I'll get started on a PR when we finished discussion |
Not sure I understand how it's more difficult for |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
馃悰 Bug Report
Regarding official documentation, in the nodeJS environment it is possible to create
Console
object with globalconsole
reference:With jest, configured as a node instance, it doesn't work:
jest.config.js:
console.test.js:
output:
To Reproduce
Steps to reproduce the behavior: just check the simple demo repo linked below
Expected behavior
Global
console.Console
reference should be defined in the nodeJS environment.Link to repl or repo (highly encouraged)
https://github.com/twawszczak/jest-console-issue
envinfo
The text was updated successfully, but these errors were encountered: