-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Group log output with the relevant test. #420
Comments
I'm strongly against this one as it's very irritating when obvious & simple things (like Domains looks like a good solution for our issues. We could also group exceptions & rejections, not just console.log()s. It was mentioned before in some issue too. The problem with domains is this: But if a replacement will be provided, that shouldn't be an issue to just migrate to a new API. |
Am I crazy or we could use console.log = function () {
process.send(...);
}; |
👍 I also want them visible by default.
Do we really need this if we manage to route console calls correctly?
Domains are deprecated, but so much depend on it that they're not going to remove it anytime soon (source: Node.js core people). They don't even have an alternative yet. And the alternative is going to be powerful enough to enable building a user-land implementation of domains. More here: #214 (comment). |
You are probably right. I was more thinking this for |
In that case, let's move on with domains on board. |
I'm not really familiar with the |
My thought was that it would be similar to
That only gives you per-process resolution. We need domains to narrow it down per-test |
@jamestalmage I actually thought about running a worker per test. I just realized it's completely insane. |
Mind wonders when you're desperate :D |
It's crossed my mind, and I definitely don't think it's insane, but probably not very performant. |
I considered that a year ago, but decided not to open an issue about it as it would come with a lot of overhead. Might be something worth exploring at some point as totally isolated tests would be so nice. |
That's kinda what the message arguments in assertions are meant for, but I guess it could be useful for generic debug stuff when it fails. Not sure |
Could be cool as a configurable option. Turn it off for faster testing on the local dev machine. On for your CI build so you ensure you are writing truly isolated tests. See https://github.com/jamestalmage/forking-tap |
One downside to this is that it hides the async nature of your code from you. Take the following: var l;
var r;
function addLater(testName, a, b) {
console.log('saving values ' + testName);
l = a;
r = b;
Promise.resolve().then(function() {
console.log('adding values ' + testName);
return l + r;
});
}
test(async t => t.is(await addLater('test 1', 3, 4), 7));
test(async t => t.is(await addLater('test 2', 5, 6), 11)); With this proposal, the above will give you a nice, seemingly synchronous log:
When what will almost certainly be happening is:
|
Yeah, can you open an issue? I don't think we should prioritize it right now, but can have an issue to at least discuss and so we don't forget. |
Paste your above comment into that issue so not to derail this discussion ;) |
My big comment above is directly related to this one. |
I don't really see that as much of a problem. |
Is this something we need to solve, or a pitfall that should be documented? (See #404). Presumably invoking with |
It's just so very surprising to people, I think it's worth trying someday. It definitely could get the low-priority label though |
Actually, I don't think it's surprising, considering that we promote parallelism & concurrency all over the place. However, as a solution to this issue, I see implementing What do you think? |
You frequently use |
I've implemented a simple solution to this problem, similar to Tape's function testWrapper (title, fnc) {
return ava (title, function (avaTest) {
let _logs = [];
// This is a quick and dirty monkey patch to ensure logs print together after
// the test has completed. The downside is logs are not printed in real time.
avaTest.comment = function () {
let msg = " # " + util.format.apply(null, arguments);
_logs.push(msg);
}
let test = avaTest._test;
test._exit = test.exit.bind(test);
test.exit = function () {
return Promise.resolve(test._exit())
.then(res => {
if (_logs.length > 0) {
process.stdout.write(_logs.join("\n")+"\n");
}
return res;
});
}
return fnc(avaTest);
}
} Output: ✔ test_foo › Lorem ipsum dolor sit amet (15.5s)
# Sed ut perspiciatis unde omnis iste natus error
# Nemo enim ipsam voluptatem quia
✔ test_bar › Ut enim ad minim veniam (31.4s)
✔ test_baz › Quis autem vel eum iure reprehenderit (36.7s)
# Neque porro quisquam est
# At vero eos et accusamus et iusto odio dignissimos It needs full integration into the Ava code (e.g., lose the wrapper, add to |
@0x1mason what's your experience using this Supporting |
Nobody on my team has complained about having to use I still use It also just occurred to me that for people already using |
As far as Incidentally the code above is essentially the same pattern I used to implement request local logging in an express js server, the difference being the additional use of domains. |
Sure, but you've already been experimenting with it so that's useful input. @avajs/core any thoughts? I'd be happy to see |
How about |
`log` works for me.
…On Dec 4, 2016 10:33 AM, "Vadim Demedes" ***@***.***> wrote:
How about t.log() instead? Shorter and simpler.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#420 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEX_-1w-3WpCNjJewPEGGRia-137fv7iks5rEt1egaJpZM4HEVoZ>
.
|
Cool. All yours @0x1mason! |
There are times when you wish to include comments in your tests that will be shown in the context of the test result, and not streamed to `stdout` like `console.log` statements are. Fixes #420.
Continuation from here.
2
is a less controversial choice, but won't help for logging from production code.One possibility for such grouping would be to only display the logs when the test failed. I think this is an especially a good idea for
t.log
, as it lets you leave them in your tests without consequence if you think they will help troubleshoot future failures.The text was updated successfully, but these errors were encountered: