Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add methods to custom and buffered consoles #5514

Merged
merged 4 commits into from
Feb 10, 2018

Conversation

ranyitz
Copy link
Contributor

@ranyitz ranyitz commented Feb 10, 2018

👋 Hey

This PR solves issue #3756.

Summary

The addition of missing methods to custom console and buffered console.

  • assert
  • count
  • countReset
  • dir
  • dirxml
  • group
  • groupCollapsed
  • groupEnd
  • time
  • timeEnd

Test plan

  • custom console - make expectations on the stdout by mocking _logToParentConsole method.
  • buffered console - make expectations on the stdout via the buffer.

concerns

  • There are code duplications between custom console and buffered console.
  • All the simple methods (log, warn, info) aren't tested, should we get full coverage there?
  • should we add integration tests for some of the methods?
  • console.table method is missing.

Let me know what can be improved, thanks!

@codecov-io
Copy link

codecov-io commented Feb 10, 2018

Codecov Report

Merging #5514 into master will increase coverage by <.01%.
The diff coverage is 40.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5514      +/-   ##
==========================================
+ Coverage   61.69%   61.69%   +<.01%     
==========================================
  Files         213      213              
  Lines        7077     7143      +66     
  Branches        4        3       -1     
==========================================
+ Hits         4366     4407      +41     
- Misses       2710     2735      +25     
  Partials        1        1
Impacted Files Coverage Δ
packages/jest-util/src/Console.js 44% <36.58%> (+29%) ⬆️
packages/jest-util/src/buffered_console.js 47.16% <43.9%> (+29.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5a2ea0...946b9cd. Read the comment docs.

_console
.getBuffer()
.map(log => log.message)
.join('\n');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use strip-ansi here to avoid having to use chalk inline. up to you 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, maybe it's the way to go, but that way we don't test the bold effect.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!


beforeEach(() => {
_console = new CustomConsole(process.stdout, process.stderr);
// override the _logToParentConsole method to be able and assert on the stdout.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use jest.spyOn instead, perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed, thanks.

info() {
BufferedConsole.write(this._buffer, 'info', format.apply(null, arguments));
debug(...args: Array<mixed>) {
this._log('debug', format.apply(null, arguments));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason this (and the others) are still format.apply(null, arguments) instead of format(...args)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change it to format(...args) everywhere, but then we'll need to change the flow notation...args: Array<mixed> to ...args: Array<string>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we'll decide to go with changing the signature's type notation, we'll need to also do it in the console type definition. Maybe i'm getting something wrong here, I would love to know your thoughts on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking about it, doing console.log({}) is perfectly valid, so mixed is correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true.
What do you say about (...args: Array<any>) and format(...args)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@cpojer cpojer merged commit f29c03e into jestjs:master Feb 10, 2018
@ranyitz ranyitz deleted the extend-custom-console branch February 10, 2018 14:28
@ranyitz
Copy link
Contributor Author

ranyitz commented Feb 10, 2018

Thanks @SimenB @cpojer 😊

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants