'timeout' events have different structure than e.g. 'test-passed'
consumeStateChange expects events of a specific type to be submitted. These get then passed on to functions that will log the outcome of the test run (endRun and writeTestSummary.
However, an event of type timeout (and maybe also type interrupt) cannot be passed to e.g. writeTestSummary, as their shape is different than e.g. a type test-passed. For comparison, here's a type test-passed event
{
type: 'test-passed',
title: 'another test that is simply passing',
duration: 0,
knownFailing: false,
logs: [],
testFile: '/Users/user/Projects/ava-test-timed-out/test/index_test.js'
}
and here's a type timeout.
{
type: 'timeout',
period: 10000,
pendingTests: Map(2) {
'/Users/user/Projects/ava-test-timed-out/test/index_test.js' => Set(2) { 'a test that times out', 'a second test that times out' },
'/Users/user/Projects/ava-test-timed-out/test/index_test2.js' => Set(1) { 'a third test that times out' }
}
}
Not that also a timeout is logically on another level to a test-passed. A timeout event is sent once and contains all timed-out tests in pendingTests whereas each failed test gets their own test-passed event.
To improve the output of timed-out tests as I've outlined in #2639, I was wondering if it would hence make sense to convert the structure of timeout into a similar one from test-passed. Meaning that for each test that times out, a new event is sent with the properties type, title, duration, knownFailing, logs, testFile.
If so, would you mind telling me which file dictates the structure of a timeout event?
Sounds good.
https://github.com/avajs/ava/blob/32c5425353cc58422f0a196bb0c06a4095a33825/lib/api.js#L84
Also:
https://github.com/avajs/ava/blob/32c5425353cc58422f0a196bb0c06a4095a33825/lib/api.js#L107
I think I'm really close. But for both L84 and L107, I can't find a way to get the test's title. It seems I can only access it after the worker has stopped on during selected-test. Both occurrences seem really tricky to access it. Anywhere I could get the title from otherwise?
- up-to-date branch
Sorry what title do you need to acces in what circumstance?
The proposed event "test-timeout" that is created in emitStateChange is supposed to contain the test's title in the same way that an event of type "test-passed" contains a title property. Along the event's lifecycle, I want to add the test's title somehow.
Is this for individual test timeouts? Through t.timeout? Though those may be emitted as test failures. The other timeouts are due to inactivity and thus not attributable to specific tests.
Apologies if I didn't make this clear enough. Trying to remember it all myself π
The other timeouts are due to inactivity and thus not attributable to specific tests.
Actually, I was contemplating if they're attributable or not too. But from my understanding, the current timeout event is created from a pendingWorkers list. What my previous questions were all concerned with mapping a title to a worker. IMO, I'd just need the title somehow when forking the worker. Any ideas?
The worker runs test files, which contain tests, which have titles.
#2501 mentions this issue:
We print pending tests when AVA times out. We should print just those tests (and hooks) that have started. Originally reported in #2421.
Perhaps solving that makes it easier to achieve your goal here.
As I'm also discussing in https://github.com/avajs/ava/pull/2647 the reporter code is quite messy at this point and I'm having a hard time remembering what it's supposed to do for what reason. Let's keep that in mind as we expend all this energy trying to tweak it⦠perhaps a more radical approach is necessary.