-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Universal jest string fromat #3160
Comments
A couple of thoughts:
|
Are we seriously considering JSX to format messages? If so, I think I could give it a try and implement this (after we settle this is actually a good idea). I imagine formatting message like this: const {JestFormat, Default, Error} = require('jest-format');
const jsx = <Default>Some <Error>text</Error> message</Default>; Which then would go through Babel to output something like this: const jsx = JestFormat.createElement(
Default,
null,
'Some ',
JestFormat.createElement(Error, null, 'text'),
' message',
); Which would format to something like this: JestFormat.createElement = function(type, props, children) {
const result = {
$$typeof: Symbol.for('JEST_FORMAT'),
props,
type: Default,
};
return result;
}; This way we could easily write recursive renderers for html, ansi, etc and custom ones for editors support, as they would need to deal with JSON only. Let me know what you think @DmitriiAbramov @kentaromiura |
Yeah I think this could work. We don't need React, we just needn't JSX with the @jsx pragma. Curious what this would look like. |
that actually looks amazing. How will we send serialized objects to other processes though? |
A message will be JSON data after all, so it shouldn't be problematic. |
As per Christoph suggestion, using the jsx pragma it will be possible to create a function like: /** @jsx format */
const format = (type, _, ...parts) => {
return {
type,
parts,
[Symbol.for('custom-format')]: true
}
}
var message = (
<message>
Error: expected value to be (using ===):
<expected>"bar"</expected>
Received:
<received>"foo"</received>
</message>
); Then we could just feed pretty-format the most appropriate plugin to have that message output how we wants; {
test: x => x[Symbol.for('custom-format')],
print: (val,print,opt,color) => (
'<span class="jest-'+ val.type +'">' + val.parts.map(val => {
if (typeof val === 'string') return val;
return print(val, print, opt, color)
}).join('') + '</span>')
} |
@kentaromiura that looks amazing! |
Actually we could adjust whitespace and indentation in props: <message indent={1}>
Error: expected value to be (using ===):
<expected indent={1}>"bar"</expected>
Received:
<received indent={1}>"foo"</received>
</message> Also, it's going to be a ton of work to change all the messages 😐 |
and what about newlines? :)
from
|
I don't think there's any way to detect the new line from code.
/* @jsx h */
h(
"div",
null,
"foo bar"
); Could have a |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
Almost 5 years without movement, I think we can close this (doing something like #7910 makes more sense to me, and if that ever happens, it would unblock doing the work discussed heree) |
The problem:
Jest needs to support different platforms when it prints its output (terminal, nuclide, html, terminal with no color support, snapshots)
There's a few ways we can implement that, but after our discussion with @kentaromiura we focused more on investigating some universal jest format.
Here's my thought on what it may look like:
jest-print-utils
package that will export the following API:JestFormattedString
type is jest a string that follows jest specific print format (a string with XML-like tags describing fonts)Example:
where UUID tags can be found in a common constant definition (to make sure they're unique and don't overlap with hmtl markup or similar)
jestFormattedString
converters that can convertJestFormattedString
type to any other string types (html, ASCII, strip tags completely, or something else)Example:
cc @kentaromiura @thymikee
The text was updated successfully, but these errors were encountered: