[browser-logs] print promises
See original GitHub issuePromises logged to the console show up as {}
.
We can improve that, at the least we can print Promise { }
. If possible it would be great to mirror the behavior of the browser/node terminal to also log the Promise status and/or result. I’m not sure if it’s possible to get this status synchronously from the promise object.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
console logging prints a promise when function returns an ...
In the first way: const get = async (endpoint: string): Promise<object> => { const response: Response = await fetch(`${process.env.
Read more >Promise.resolve() - JavaScript - MDN Web Docs
The Promise.resolve() method "resolves" a given value to a Promise. If the value is a promise, that promise is returned; if the value...
Read more >Console logs inside Promise functions not working ... - GitHub
I'm on Ubuntu 14.04LTS. Using Google Chrome (38.0.2125.111 (64-bit)) & Firefox (33.0). I'm using the pouchdb.min.js (From commit e78a30f on ...
Read more >Javascript: How to access the return value of a Promise object
It's happening because the Javascript code always executes synchronously, so the console.log() function starts immediately after the fetch() ...
Read more >How to Make your Console Output Fun and Interactive in ...
We'll add it by explicitly printing the \n character. const log = (s) => { for ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@43081j thanks for the explanation, it’s spot on.
I think for the first version we can start with a compromise - just return
"Promise { }"
. I don’t know of any way to synchronously check if a promise is already resolved… maybe someone knows a trick but we can also add this later. The most important part is communicating that it actually is a promise so that people can know how to proceed with debugging.@ashikvarma11 if you want to pick this up here’s my suggested solution:
The browser-logs code really seems to exist so it can copy a logged value (via
console.log
) from the browser session to the test runner:So if you want to print promises nicely, you need to change the serialiser to return something like:
Just like
undefined
is handled here.Unfortunately im not aware of a way to check if a promise has resolved or rejected without actually asynchronously catching/then-ing it (which we can’t do here because a JSON reviver is synchronous).
Then in the deserialiser you need to add a case to set a fake promise (or something representing one). Just like the one for functions here:
it’s not great to be generating loads of unresolved promises i suppose. You could also return a
Promise.resolve()
but that may be misleading if what was originally serialised was a rejected promise.Maybe @LarsDenBakker would be happy with some compromise where we don’t make a real promise but just log a string representing one instead, i’m not sure.