Repository navigation
Show how long a Nightwatch assertion waited - #636
vishnuv688 wants to merge 4 commits into
Conversation
Under the BDD interface Nightwatch reports no per-assertion command window, so a native assertion's row kept the moment it was queued as both its start and its end, and a failing textContains that polled for 5 s showed as 1 ms with its test's span closing before the failure. The row now ends when the assertion's promise settled, or after the wait its failure message names, and keeps its queued start, which with its issue sequence keeps the rows in order. Closes #627
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
[Medium impact] The PR appears safe to merge, with no new findings or outstanding previous findings. SummaryAssertion rows now use the observed settlement time when Nightwatch supplies no command window. Failed assertions without an observed settlement use the wait named in their message, accounting for earlier assertions.
Reviews (4) · Last reviewed commit: "Note that a queued native assert's live ..." · Reviewed by Greptile |
| startTime: call.timestamp, | ||
| endTime: call.timestamp + Number(elapsed[1]) |
There was a problem hiding this comment.
elapsedTiming adds the assertion's wait to its enqueue time, not its execution start. For synchronous assertions without an observed settlement, earlier queued work can therefore hide the wait again. If an earlier assertion takes 5 seconds and this assertion then waits 5 seconds, both calculated ends land around enqueue + 5 seconds. The exporter raises the second start to the first end, leaving the second row about 1 ms long.
Account for earlier queued work when placing this fallback window, and add a test with consecutive queued assertions.
There was a problem hiding this comment.
Fixed in 9cdc7a0: captureNativeAssertions now tracks where the assertion queue has got to, and the message fallback starts each wait at the later of the assertion's enqueue time and the previous assertion's end, since Nightwatch runs queued assertions one after another. Test: "places consecutive queued failures one after another, each with its own wait" (two assertions queued together waiting 5000 and 4000 ms land at 0-5000 and 5000-9000).
Nightwatch runs queued assertions one after another, but the fallback that times an assertion from its failure message started the wait when the assertion was queued. Two assertions queued together, each waiting 5 s, got the same window and the exporter pressed the second back to 1 ms. The fallback now starts each wait once the assertion before it has ended.
| const startTime = Math.max(call.timestamp, after) | ||
| return { startTime, endTime: startTime + Number(elapsed[1]) } |
There was a problem hiding this comment.
Queued actions appear out of order
Moving the fallback's startTime forward can put an assertion after commands queued later. Queue two failing verify.textContains calls followed by a click, without observed settlements or command windows: the second assertion starts at the first assertion's end, but the click keeps its enqueue start.
Both trace outputs sort by startTime before sequence, so the click appears before the second assertion. This can also shrink the assertion's displayed wait again. Keep the enqueue time as the ordering key when placing the fallback window.
There was a problem hiding this comment.
Fixed in cfda385: the fallback keeps the row's startTime at enqueue, the ordering key beside sequence, and only its end follows the queue (the later of enqueue and the previous assertion's end, plus the wait). The exporter raises a row's start to the previous row's end (trace-action-events.ts), so two assertions queued together at 200 ms waiting 5000 and 4000 ms show as 200 to 5200 and 5200 to 9200, and a click queued after them at 201 ms sorts and shows after both.
Moving the fallback's start to the previous assertion's end let a command queued after it sort before it, since rows are ordered by start before issue sequence. The start stays at enqueue, the ordering key, and only the end follows the assertion queue; the exporter raises the start to the previous row's end, so each assertion still shows its own wait.
| startTime: call.timestamp, | ||
| endTime: waitedFrom + Number(elapsed[1]) |
There was a problem hiding this comment.
Keeping startTime at enqueue fixes trace ordering, but makes the live action list count earlier waits again. With two queued failures waiting 5000 ms and 4000 ms, the second row now carries a 9000 ms span. The live view's entryDuration subtracts startTime directly, so it displays 9 seconds instead of 4 seconds. Only the trace exporter raises the start to the previous end.
Keep the enqueue ordering key without making the live duration include earlier assertions.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Right, and it is a trade-off rather than a bug this PR can remove: one startTime is both the row's ordering key (it must be the enqueue time, or a command queued after back-to-back asserts sorts ahead of them, your previous comment) and the start of its live duration. The trace exporter raises a start to the previous row's end, so traces show each wait on its own; the live list subtracts the start directly. The observed-settlement path, which existed before this PR for cucumber and is the common case here, has the same shape (enqueue start, settle end). Only back-to-back un-awaited asserts are affected. Kept as is and recorded in 9c240d6 in packages/nightwatch-devtools/CLAUDE.md known debt; the fix is a display start separate from the ordering key across shared, the app and the exporter, which belongs in its own change.
The row keeps its enqueue start as the ordering key, so the live action list, which subtracts the start directly, counts the wait of the assert queued before it; the trace exporter does not. A separate display start would fix it across shared, the app and the exporter.
What & why
Under Nightwatch's BDD interface, a native assertion's row recorded the moment it was queued as both its start and its end, so a trace showed it lasting about 1 ms however long it waited. In the committed fixture
nightwatch-bdd-2026-11-10-ee505b9c.zip, a failingassert.textContainsthat polled for 5 s ran from 2205 to 2206 ms, and its test's span closed before the failure happened.Closes #627
Type of change
Packages touched
shared(types and contracts)core(framework-agnostic capture/reporting)elements(published element/snapshot API:@wdio/elements)service(WebdriverIO adapter)nightwatch-devtools(Nightwatch adapter)selenium-devtools(Selenium adapter)selenium-devtools-py(Selenium Python adapter)backend(server)app(UI)script(page-injected runtime)trace(Trace mode)Capability matrix
packages/conformance/src/features.tsupdated, and tables regenerated withpnpm docs:capabilities, if this adds or changes user-facing behaviourNot applicable: assertion rows are listed already; this fixes their duration.
Notes for reviewers
pnpm demo:nightwatch(trace mode, the-internet.herokuapp.com, Chrome 158): the failingassert.textContains("#flash", ...)now lasts 5240 ms against the 5236 ms its error message names, and the next test's first action starts 55 ms after it ends. Before, the same row lasted 1 ms.pnpm test(347 files, 4727 tests),pnpm typecheckand lint (0 errors) pass.Screenshots / recordings
Not applicable: no UI change.
🤖 Generated with Claude Code