-
Notifications
You must be signed in to change notification settings - Fork 10
fix(cli): drop a log written before the first mocha hook instead of logging an ERROR (SDK-7843) [v8] #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AakashHotchandani
wants to merge
3
commits into
v8
Choose a base branch
from
fix/SDK-7843-quiet-pre-test-log-v8
base: v8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(cli): drop a log written before the first mocha hook instead of logging an ERROR (SDK-7843) [v8] #265
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
484d4e1
fix(cli): drop a log written before the first mocha hook instead of l…
AakashHotchandani c74564c
chore(changeset): auto-generate from PR template (patch)
github-actions[bot] 18f5f61
docs(cli): name only the wdio `before` hook in the pre-test log guard…
AakashHotchandani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@wdio/browserstack-service": patch | ||
| --- | ||
|
|
||
| - Removed misleading `resolveInstance: unable to resolve/create instance ... TestFrameworkState.LOG` / `trackEvent: instance not found` error messages. They were printed when a wdio `before` hook writes to the console. Test execution and reporting were never affected. |
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
56 changes: 56 additions & 0 deletions
56
packages/browserstack-service/tests/cli/wdioMochaTestFramework.preTestLog.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' | ||
| import * as bstackLogger from '../../src/bstackLogger.js' | ||
|
|
||
| import WdioMochaTestFramework from '../../src/cli/frameworks/wdioMochaTestFramework.js' | ||
| import TestFramework from '../../src/cli/frameworks/testFramework.js' | ||
| import { TestFrameworkState } from '../../src/cli/states/testFrameworkState.js' | ||
| import { HookState } from '../../src/cli/states/hookState.js' | ||
| import { BStackLogger as cliLogger } from '../../src/cli/cliLogger.js' | ||
|
|
||
| vi.spyOn(bstackLogger.BStackLogger, 'logToFile').mockImplementation(() => {}) | ||
|
|
||
| describe('SDK-7843 — a log written before the first mocha hook is dropped quietly', () => { | ||
| let framework: WdioMochaTestFramework | ||
| let errorSpy: ReturnType<typeof vi.spyOn> | ||
|
|
||
| beforeEach(() => { | ||
| framework = new WdioMochaTestFramework(['WebdriverIO', 'mocha'], {}, 'bin-session-id') | ||
| errorSpy = vi.spyOn(cliLogger, 'error').mockImplementation(() => {}) | ||
| vi.spyOn(cliLogger, 'info').mockImplementation(() => {}) | ||
| vi.spyOn(cliLogger, 'debug').mockImplementation(() => {}) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks() | ||
| }) | ||
|
|
||
| it('does not log an ERROR for console output from wdio\'s `before` hook', async () => { | ||
| // wdio's `before` runs before mocha's `before all`, so no instance is tracked yet. | ||
| vi.spyOn(TestFramework, 'getTrackedInstance').mockReturnValue(null as any) | ||
| const resolveSpy = vi.spyOn(framework, 'resolveInstance') | ||
|
|
||
| await framework.trackEvent(TestFrameworkState.LOG, HookState.POST, { | ||
| logEntry: { kind: 'TEST_LOG', message: '[SelfHealer] Installed', level: 'info', timestamp: new Date().toISOString() } | ||
| }) | ||
|
|
||
| expect(errorSpy).not.toHaveBeenCalled() | ||
| expect(resolveSpy).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('still resolves the instance for a log once a test or hook is tracked', async () => { | ||
| vi.spyOn(TestFramework, 'getTrackedInstance').mockReturnValue({} as any) | ||
| const resolveSpy = vi.spyOn(framework, 'resolveInstance').mockReturnValue(null) | ||
|
|
||
| await framework.trackEvent(TestFrameworkState.LOG, HookState.POST, { logEntry: {} }) | ||
|
|
||
| expect(resolveSpy).toHaveBeenCalledOnce() | ||
| }) | ||
|
|
||
| it('still reports a missing instance for non-log events', async () => { | ||
| vi.spyOn(TestFramework, 'getTrackedInstance').mockReturnValue(null as any) | ||
|
|
||
| await framework.trackEvent(TestFrameworkState.TEST, HookState.POST, {}) | ||
|
|
||
| expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('resolveInstance: unable to resolve/create instance')) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Suggestion — [TESTING] New test sits outside v8's
tests/cli/frameworks/home for mocha framework testsProblem
On
v8, the existingWdioMochaTestFrameworktests live intests/cli/frameworks/wdioMochaTestFramework.test.ts, which uses../../../srcimports. This file is placed attests/cli/(themainlayout, wherewdioMochaTestFramework.*.test.tssiblings live at that level). It works either way. Moving it totests/cli/frameworks/on v8, or folding the 3 cases into the existing file, keeps the v8 tree consistent. Keeping it identical to #264 for cherry-pick symmetry is also a reasonable choice.Suggested Fix
Move the file to
packages/browserstack-service/tests/cli/frameworks/wdioMochaTestFramework.preTestLog.test.tsand change the imports from../../src/...to../../../src/.... Alternatively, append thedescribeblock to the existingtests/cli/frameworks/wdioMochaTestFramework.test.ts.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changing this one. I'm keeping the file identical to #264 (same path, same
../../srcimports) so the test stays a straight cherry-pick betweenmainandv8. Splitting the layout would make the next port of this file diverge. It runs fine where it is: 12/12 together with the existingtests/cli/frameworks/wdioMochaTestFramework.test.ts. As the suggestion itself notes, symmetry with #264 is a reasonable choice here.