Environment
- @wdio/browserstack-service: 9.36.1 (also reproduced on 9.35.1)
- webdriverio: 9.31.3, Mocha, CLI/gRPC flow, App Automate Android
Bug
A console.log/console.error outside the tracked test/hook window
(e.g. global setup, teardown, between specs) triggers:
ERROR @wdio/browserstack-service/cli: resolveInstance: unable to resolve/create instance for testFrameworkState=TestFrameworkState.LOG hookState=HookState.POST
ERROR @wdio/browserstack-service/cli: trackEvent: instance not found for testFrameworkState=TestFrameworkState.LOG hookState=HookState.POST
Run still passes. Log event is silently dropped.
Minimal reproduction
wdio.conf.ts:
export const config: WebdriverIO.Config = {
services: ['browserstack'],
before: function () {
// Config-level `before` — runs once, before any Mocha `before all`.
// No TestFrameworkState instance exists yet at this point.
console.log('global setup');
// ^ triggers the two ERROR lines above
},
specs: ['./test/specs/**/*.ts'],
// ...rest of your wdio config
};
test/specs/example.test.ts:
describe('Suite', () => {
it('passes', () => {
expect(true).toBe(true);
});
});
Run with wdio run wdio.conf.ts against BrowserStack. The before()
hook's console.log fires before the CLI tracker has created any
instance, reproducing the error on every run.
Root cause
packages/browserstack-service/src/cli/frameworks/wdioMochaTestFramework.ts
→ resolveInstance(). Only creates/reuses an instance for NONE,
INIT_TEST, or a PRE hook. LOG+POST matches none of these, so
instance stays null and both resolveInstance() and trackEvent()
log at error. Introduced in 7d6f822 (Jul 2026).
Trigger: logPatcher.ts patches console.log/console.error
process-wide, routed via insights-handler.ts appendTestItemLog() —
not scoped to an active test.
Suggested fix
Downgrade to logger.debug for TestFrameworkState.LOG in both
resolveInstance() and trackEvent():
// resolveInstance()
instance = TestFramework.getTrackedInstance()
if (!instance) {
if (testFrameworkState === TestFrameworkState.LOG) {
logger.debug(`resolveInstance: no active instance for LOG event (hookState=${hookState})`)
} else {
logger.error(`resolveInstance: unable to resolve/create instance for testFrameworkState=${testFrameworkState} hookState=${hookState}`)
}
return null
}
// trackEvent()
const instance = this.resolveInstance(testFrameworkState, hookState, args)
if (instance === null) {
if (testFrameworkState !== TestFrameworkState.LOG) {
logger.error(`trackEvent: instance not found for testFrameworkState=${testFrameworkState} hookState=${hookState}`)
}
return
}
Missing instance is expected here, not a tracking failure — behavior
(returns null, drops the log event) is unchanged, only the log
severity changes.
Verification
Applied the above patch locally against the installed 9.36.1 package and
ran the same spec on real BrowserStack App Automate (Android) sessions:
Expected
debug-level (or no log) when no instance exists for a LOG event,
not error.
Environment
Bug
A
console.log/console.erroroutside the tracked test/hook window(e.g. global setup, teardown, between specs) triggers:
Run still passes. Log event is silently dropped.
Minimal reproduction
wdio.conf.ts:test/specs/example.test.ts:Run with
wdio run wdio.conf.tsagainst BrowserStack. Thebefore()hook's
console.logfires before the CLI tracker has created anyinstance, reproducing the error on every run.
Root cause
packages/browserstack-service/src/cli/frameworks/wdioMochaTestFramework.ts→
resolveInstance(). Only creates/reuses an instance forNONE,INIT_TEST, or aPREhook.LOG+POSTmatches none of these, soinstancestaysnulland bothresolveInstance()andtrackEvent()log at
error. Introduced in 7d6f822 (Jul 2026).Trigger:
logPatcher.tspatchesconsole.log/console.errorprocess-wide, routed via
insights-handler.ts appendTestItemLog()—not scoped to an active test.
Suggested fix
Downgrade to
logger.debugforTestFrameworkState.LOGin bothresolveInstance()andtrackEvent():Missing instance is expected here, not a tracking failure — behavior
(returns
null, drops the log event) is unchanged, only the logseverity changes.
Verification
Applied the above patch locally against the installed 9.36.1 package and
ran the same spec on real BrowserStack App Automate (Android) sessions:
Expected
debug-level (or no log) when no instance exists for aLOGevent,not
error.