Repository navigation
fix(cli): record a timed-out mocha test's failure when mocha reports it (SDK-7843) [v8] - #273
AakashHotchandani wants to merge 6 commits into
Conversation
…it (SDK-7843) v8 port of the main-line fix. When a mocha test hits its timeout, mocha fails it while the body and wdio's afterTest are still pending. With `bail`, or on the worker's last test, wdio runs after() first, so on the CLI flow AutomateModule.onAfterExecute marks the session `passed`: its results only come from afterTest. The classic flow reads after(result) and was correct. The service now registers a finisher per mocha test in beforeTest (cli/earlyTestFinish.ts). The reporter's onTestFail reports the failure through it when mocha fails the test. after() waits for those finishes before EXECUTE/POST, and the late afterTest stands down for a test that was already reported. v8 sends TEST/POST inline (no deferred finish), so its Test Reporting results were already right; this fixes the session status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
|
🔴 SDK PR Review gate is red. Pending:
It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge. |
…ogging an ERROR (SDK-7843) Console output from wdio's `before` hook reaches trackEvent(LOG, POST) before mocha's first hook, when no test or hook instance exists, so resolveInstance printed "resolveInstance: unable to resolve/create instance ... LOG POST" on every worker. Drop it at debug level, as the classic path does. Same change as #265. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🔴 SDK PR Review gate is red. Pending:
It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge. |
- Finish a test mocha already failed from after() when no reporter claimed it, using mocha's own runnable, so the fix holds with Test Reporting, Accessibility and Percy all off (the reporter is only registered when Test Hub events are on). - Key the finish hand-off per retry attempt, so a retried attempt's late afterTest closes that attempt and not the next one. - Drop the try/catch around awaitCliTestFinishesOnFailure(); every finish catches its own error. - Tests: no reporter, retries. Same changes as #272. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🔴 SDK PR Review gate is red. Pending:
It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge. |
With no reporter, a timed-out test whose body finishes late gets an afterTest saying only whether the body threw. If mocha already failed that attempt, claimCliTestFinish now reports mocha's failure and afterTest stands down, instead of reporting it passed. Same change as #272. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🔴 SDK PR Review gate is red. Pending:
It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge. |
What is this about?
v8 port of #272. On the CLI flow, a mocha test that hits mocha's timeout has its session marked
passedon the Automate / App Automate dashboard.Why: wdio runs
afterTestinside the test's runnable. When the test times out, mocha fails it (and emitsfailto reporters) while the body and itsafterTestare still pending. Withbail, or on the worker's last test, wdio runsafter()first.after()emitsEXECUTE/POST, andAutomateModule.onAfterExecutemarks the session from results that onlyafterTestsupplies. There is none yet, so the session is markedpassed. The classic flow readsafter(result), mocha's own failure count, and was correct.Same fix as #272:
cli/earlyTestFinish.ts(identical file):beforeTest(CLI, mocha) registers a finisher per test.onTestFailreports the failure through it, with mocha's own result, the moment mocha fails the test.after()awaits those finishes beforeEXECUTE/POST.afterTeststands down only for a test the reporter already reported.The CLI finish (LOG_REPORT/POST → TEST/POST) moved unchanged into
finishCliTest(), including the existingsuiteTitepayload key.Difference from main: v8 has no deferred
TEST/POSTand no bail cascade, so its Test Reporting results were already right. On v8 this fixes the session status only.Also in this PR — the
resolveInstanceERROR (same change as #265): console output from wdio'sbeforehook (the customer's[SelfHealer] Installed …) reachestrackEvent(LOG, POST)before mocha's first hook, when no test or hook instance exists.resolveInstancethen printedresolveInstance: unable to resolve/create instance for TestFrameworkState.LOG HookState.POSTon every worker.WdioMochaTestFramework.trackEventnow drops a LOG with no tracked instance at debug level, as the classic flow does. New test:tests/cli/wdioMochaTestFramework.preTestLog.test.ts(3 cases). Verified on real sessions under #265: stock 8.53.1 buildsmosjpekx4…prints the ERROR, patched builddjju5rlyfb…is clean.Review follow-up (ab144e5):
after()finishes any test mocha already failed that no reporter claimed, beforeEXECUTE/POST.try/catchinafter().Verification
Real WDIO 8 + mocha sessions on Automate (chrome/Win11),
mochaOpts: { timeout: 10000, bail: true }. The timed-out test waits 40 s for a missing element.gceel2cz0bnksiupe9w90rzx7ttnf06w4dgaqj8n3eeef5f73f174165fb02f17f6616041f43656360passed ❌ (CLIENT_STOPPED_SESSION)niszt4uhggs0bb2nnia3ngxookl2oemckau8wrmc0c835059b01822990f4e38cb092af6a9a934d438failed, reason = mocha timeoutTiming on both runs: reporter
onTestFail(05:53:48.831) →after(result=1)(.840). On stock, the session status is set before the failed result exists.Tests: the same 11 new cases as #272.
tests/cli/earlyTestFinish.test.tsandtests/reporter.onTestFail.test.tsare identical to fix(cli): record a timed-out mocha test's failure when mocha reports it (SDK-7843) #272.tests/service.timedOutTestFinish.test.tsis adapted: it has no flush step and asserts TEST/POST <EXECUTE/POST. Mutation-checked: dropping theawaitinafter()fails it.Full suite: 1131 passed with this PR (51/51 files) vs 1109 on
v8, 0 failing tests on both. The only failing file istests/crash-reporter.test.ts(needs a builtbuild/), and it fails identically onv8.tsc -p tsconfig.prod.json --noEmitis clean. The v8 branch has no eslint config.Related Jira task/s
SDK-7843
Release (mandatory for every PR — required for the
ready-for-reviewlabel)Version bump: (required — tick exactly one)
Release notes type: (optional)
Release notes (customer-facing): (optional but encouraged)
resolveInstance: unable to resolve/create instance ... LOG POSTerror printed when a wdiobeforehook writes to the console.Release notes (internal): (required — engineer-facing; what actually changed / why)
cli/earlyTestFinish.ts:beforeTest(CLI, mocha) registers a finisher per test; reporteronTestFailreports a failure through it when mocha fails the test;after()awaits those finishes beforeEXECUTE/POST;afterTeststands down only for a test already reported. Root cause: for a mocha timeout underbail(or on a worker's last test) wdio runsafter()beforeafterTest, soAutomateModule.onAfterExecutemarked the session from an empty result map (passed). Also (as fix(cli): drop a log written before the first mocha hook instead of logging an ERROR (SDK-7843) [v8] #265):WdioMochaTestFramework.trackEventdrops a LOG event with no tracked instance at debug level instead of logging the resolveInstance ERROR.Checklist
PR Validations
Run Tests: Comment RUN_TESTS to trigger sanity tests.
🤖 Generated with Claude Code