-
Notifications
You must be signed in to change notification settings - Fork 45
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
Support for ansi colour coding in the test window #237
Comments
Slightly off topic, but wallaby.js supports showing nice diffs for assertion libraries that throw errors with For example, for chai, expect.js, and other assertion libs that follow the convention, wallaby can do this: I'm wondering if unexpected.js would be open to the idea of following the convention and adding these properties to the assertion errors they throw. |
While this works for things that can be compared in text and line by line, this doesn't work for many of the things that An excellent example is the unexpected-dom library, which allows assertions over the DOM. Here I'm asserting that a particular CSS class is included in the node: (Also note the syntax highlighting of the HTML, which you get for free because the diffing algorithm understands the DOM, and can highlight it as it goes 😄)
It also allows assertions like var actualObject = {
some: 'prop'
important: 42,
alsoImportant: [
{ id: 1, name: 'Herr von Neumann'},
{ id: 22, name: 'Herr A. Einstein', profession: 'genius' }
]
};
// check the object contains at least what we need
expect(actualObject, 'to satisfy', { important: 42, alsoImportant: [ { id: 1}, { id: 22} ]); It's not possible to produce a line-by-line diff for this externally, because it can't be known what the rules for matching are, without reimplementing it. I'm pretty sure that's why |
Fair enough Dave, thanks for the explanation. Will have a look what can be done. |
Unexpected also supports generating HTML error messages (including diffs) for the browser, and this representation can be enriched with media that cannot be shown in a terminal, such as http://unexpected.js.org/unexpected-resemble/ I wanted to try playing with/cheering for getting those HTML errors into Atom once wallaby adds support for it :) |
@papandreou Nice! I just thought how to display the diffs in Atom. Would be totally awesome if unexpected was also supporting returning the diff in a form a string plus a token array (describing what parts of the string are what). Something like language grammar parsers do, so that the content and the presentation would be separated and one could create any kind of presentation for the content. |
@ArtemGovorov Internally Unexpected uses /~https://github.com/sunesimonsen/magicpen to build its output, and that includes something like the token representation that you're asking for. It's exposed via the var expect = require('unexpected');
try {
expect('abc', 'to equal', 'abe');
} catch (err) {
err.getErrorMessage('html'); // returns magicpen instance with the tokens
err.getErrorMessage('html').toString(); // returns HTML serialization
err.getErrorMessage('ansi').toString(); // returns ansi serialization
err.getErrorMessage('text').toString(); // returns text serialization
} ... Or does wallaby actually need to understand the contents of the error message/diff? If so, please write a few words about why, then we'll see what we can do. |
@ArtemGovorov I guess we can make a serializer for magicpen that would produce should an output. But for this use case I think it would be preferable to show the error.htmlMessage as rendered html if it is available - that would probably be pretty easy to support from wallabyjs. |
From what I can see, Wallaby does need to understand the contents style semantics, to be able to format the output with a custom formatter. For example, for the IntelliJ/Visual Studio platform I'll be reading the tokens array and rendering them into Failing Tests console (which is a micro instance of the IDE editor class), using current theme colours. Same for Atom, as opposed to the built-in html serialisation (which hardcodes styles/colors), we'll need to use CSS classes (that will support Atom theme changes nicely). |
@ArtemGovorov What are the capabilities of that terminal? Maybe you could write an IntelliJ/Visual Studio serializer for magicpen? I think that would be easier to maintain than relying on the internal representation of the tokens. "Serializer" is actually a bit of a misnomer, as the Then you could do something like this: err.getErrorMessage('intelliJ').toString(theIntelliJConsole); |
@papandreou For IntelliJ it's basically a printer, like: public interface Printer {
void print(String text, ConsoleViewContentType contentType);
} (where ConsoleViewContentType encapsulates styles). So it has to be used as a sequence of the printer instance calls, passing parts of the message and styles (like colours) for the parts. Those styles are theme-able, so that if exposed, the IDE user can configure them and theme authors may consider them as well. Ideally, it'd be good to map styles to the IDE editor styles for the majority of token types (tags, attributes, JS strings, errors and other tokens) so that the output looks and feels like in the IDE editor and easily customisable by the end user. |
@ArtemGovorov I fully agree with @papandreou adding a serializer to magicpen is the right way to go about it. It would be possible to generate a string with additional token information that could be styled the way you like it. It would also be possible to produce html with class names that can be styled from CSS. |
@ArtemGovorov as you can see here: /~https://github.com/unexpectedjs/unexpected/blob/master/lib/styles.js unexpected uses logical names for most things as theme them differently if it is html or ansi output. But you could produce output with the logical names instead or map them to names that IntelliJ understands. |
@sunesimonsen Cool, thanks. Could you please point me to the right direction in terms of how to write the magicpen serializer and install it to unexpected? I'll probably just pass the logical names coming from unexpected and its plugins to an IDE/editor, so that the logic of producing the output with actual styles resides in the target IDE. This way IntelliJ plugin will use its printer, Atom package will produce HTML with proper CSS classes, etc. |
@ArtemGovorov I'm afraid that there is no extensive documentation on the subject, but try to take a look at this code: /~https://github.com/sunesimonsen/magicpen/blob/master/lib/ColoredConsoleSerializer.js and this is where they get installed: /~https://github.com/sunesimonsen/magicpen/blob/master/lib/MagicPen.js#L61-L69 you can just add one more to the hash. I guess it is must be something like:
I it cool if you would give it a go, otherwise I can see if I can get some time to help you out. |
@sunesimonsen Thanks! I'll have a look. For now as a quick solution for the IntelliJ platform, I'll just add an ansi decoder to display whatever colors are coming from unexpected. But will definitely need to implement the serializer for the theme-friendly solution for all supported IDEs. |
@ArtemGovorov sounds awesome - thanks a lot! |
That is awesome, thanks! |
That is amazingly awesome. Thank you so much, everyone! |
This looks great now. The only thing is the inline message (inline with the code), is still with the ansi escape sequences. Not sure how easy that is to fix. The important thing works great. |
@bruderstein Are you still forcing unexpected to output ansi? If so, don't force it and it should work fine (like you can see on my screenshots). If it doesn't work, please share a sample where I could reproduce the issue. |
Sorry, yes, I was, due to dom emulation. I'll solve that a different way. Thank you. And sorry for the noise. |
Is there colored output support in atom plugin? |
@hellboy81 Not in Atom yet. |
Some assertion libraries (for example unexpected) can use ansi terminal colour coding in the test results to highlight a diff between expected and actual.
When running the tests in webstorm terminal via the mocha command line, we can see these beautiful diffs, in the wallaby "failing tests" window however, we can't get the colours (when forced to output ansi, they appear as just �
[31m�[1m...
etc.It would be awesome to support these colour codes - it's actually a reason i still occasionally run the tests via the command line to see the output.
Or from the webstorm console:
And that is shown in wallaby as:
The text was updated successfully, but these errors were encountered: