fix(observability,session-status): don't mark suppressNotFoundErrors commands as test failures#53
Merged
shubhamkd merged 2 commits intoMay 15, 2026
Conversation
…t failures Nightwatch records every isVisible / isPresent timeout with status:'fail' internally, including calls where the caller explicitly opted into "not found is fine" via suppressNotFoundErrors:true. sendTestRunEvent and the setSessionStatus path in globals.js both scanned commands[] for any status:'fail' and flipped the test/session to "failed" without checking the opt-out or the testcase envelope's pass/fail rollup, so tests Nightwatch and Automate considered passed were reported as failed in Test Observability. - Add helper.isSuppressedFailure(cmd) — handles args[0] as object or JSON string. - sendTestRunEvent: filter suppressed-failure commands and trust the envelope rollup (status:'pass' && failed:0 && errors:0) over a stray command-level fail status. - globals.js setSessionStatus: same fix, keeps Automate session status consistent with TRA. - Add 4 regression tests for sendTestRunEvent (previously uncovered). Linked: BrowserStack SDK-5914
…r coverage - src/utils/helper.js: satisfy padding-line-between-statements; log a debug message when args[0] is an unparseable JSON string; clarify in the doc-comment why only args[0] is inspected. - nightwatch/globals.js: clarify the eventData===null fallback behavior matches the pre-fix code (status defaults to 'passed'). - test/src/test-observability/sendTestRunEvent.js: tighten tests 3 & 4 to lock failure_reason content and backtrace shape — exactly the wire fields the original bug malformed. - test/src/utils/helper.js: add 10 unit tests for isSuppressedFailure covering null/undefined/primitive args[0], malformed JSON strings, object/string opt-out shapes, and falsy variants. Both call sites (sendTestRunEvent and setSessionStatus) are covered by reference.
xxshubhamxx
approved these changes
May 12, 2026
pranay-v29
approved these changes
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix:
TestRunFinishedand session status incorrectly marked failed for commands withsuppressNotFoundErrors: trueLinked ticket: BrowserStack SDK-5914 / Freshdesk 1617613 (SmartVault)
Target package release:
@nightwatch/browserstack@3.10.2Summary
sendTestRunEvent('TestRunFinished', ...)flipstest_run.resultto"failed"whenever any command in the test envelope carriesstatus:"fail", even when the command was a NightwatchisVisible/isPresentinvocation withsuppressNotFoundErrors:trueon an absent element. Nightwatch itself reports the testcase asstatus:"pass"withfailed:0, the local runner exits clean, and BrowserStack Automate marks the session passed. Only Test Observability disagrees, producing a confusing pass/fail split for the same run.Same defect shape lives in
nightwatch/globals.jswhere the plugin sets the BrowserStack session status viabrowserstack_executor: setSessionStatus— folded into this PR so both surfaces stay consistent.Root cause
Two sites read the per-command status array without consulting (a) the command's own
args[0].suppressNotFoundErrorsopt-out or (b) the testcase envelope's rollup (status,failed,errors):src/testObservability.js—TestRunFinishedbranch insendTestRunEvent:nightwatch/globals.js—setSessionStatuspath:A Nightwatch
isVisible({suppressNotFoundErrors:true})on an absent element internally recordsstatus:'fail'even though the caller opted out of failure semantics, so both sites flip to "failed" against the test's actual outcome.Fix
helper.isSuppressedFailure(cmd)insrc/utils/helper.js— returns true when astatus:'fail'command'sargs[0]carriessuppressNotFoundErrors:true. Handles both shapes Nightwatch emits: object literal and JSON-encoded string.src/testObservability.js—sendTestRunEventfilters suppressed-failure commands out of thecommands.find(...)call. Additionally, the testcase-envelope rollup (status:'pass' && failed:0 && errors:0) is consulted before flippingtestData.result— if Nightwatch already says the test passed, the plugin trusts that rather than re-deriving from the raw command log.nightwatch/globals.js—setSessionStatuspath uses the same helper and the same envelope-rollup guard, keeping the Automate session status aligned with TRA.The behavior is additive: a non-suppressed
status:'fail'command alongside an envelope rollup that says failed continues to mark the test failed exactly as before. Verified by the regression tests below.Wire evidence
Captured against the customer's actual repro (a 2-test Nightwatch suite, one control + one conditional
isVisible({suppressNotFoundErrors:true})) running with@nightwatch/browserstack@3.10.0. Same spec, same environment, only the plugin source differs.Before:
failure_reason: nulland the emptybacktraceare the smoking gun — there is no real failure to render; the plugin synthesized one from the suppressedisVisiblecommand'sstatus:'fail'.After:
No
failure,failure_reason, orfailure_typefields. Control test unaffected (regression-negative).Test plan
New unit-test file
test/src/test-observability/sendTestRunEvent.js(4 cases —sendTestRunEventhad zero existing coverage, which is the structural reason this bug shipped):suppressNotFoundErrors:trueandargs[0]is an object literal.suppressNotFoundErrors:trueandargs[0]is a JSON-encoded string (the shape the customer's Nightwatch report uses).assert.*failure is present — envelope rollup saysfailed:1, the patch must propagate the failure.failedCommandmust skip the suppressed entry and pick the real one;failure_typeset correctly.Full mocha suite: 55 passing (was 51).
Manual reproduction
The customer-attached reproduction repository runs against a real BrowserStack build:
With the customer's environment (
BROWSERSTACK_USER/BROWSERSTACK_KEY, default Chrome on Windows 11), both tests landresult:"passed"on the wire and on the TRA dashboard after upgrading to a build that includes this patch.Compat note
src/utils/helper.jslike the other utilities in the file.silent:true,optional:true), as long as the testcase rollup correctly reportsstatus:'pass', the plugin will stop overriding it.