-
Notifications
You must be signed in to change notification settings - Fork 13.4k
chore: qase integration #37538
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
Merged
Merged
chore: qase integration #37538
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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,107 @@ | ||
| /** | ||
| * Jest setup file that automatically wraps describe and it/test functions | ||
| * to register suites and tests with Qase. | ||
| * | ||
| * The Qase Jest reporter reports the directory structure up from the tests directory, | ||
| * making it not consistent with the test suite structure we currently follow in Qase. | ||
| * The solution is to wrap describe and it/test functions to automatically set the suite | ||
| * at the very start of the test to what we really want the reporting structure to be. | ||
| * | ||
| * This file is loaded via setupFilesAfterEnv in jest.config.federation.ts. | ||
| * Qase integration is only enabled when QASE_TESTOPS_JEST_API_TOKEN is set. | ||
| */ | ||
|
|
||
| import { qase } from 'jest-qase-reporter/jest'; | ||
|
|
||
| const ROOT_SUITE = 'Rocket.Chat Federation Automation'; | ||
|
|
||
| /** | ||
| * Stack to track the current suite path hierarchy | ||
| */ | ||
| const suitePathStack: string[] = []; | ||
|
|
||
| /** | ||
| * Store the original Jest describe function before we replace it | ||
| */ | ||
| const originalDescribe = global.describe; | ||
|
|
||
| /** | ||
| * Gets the full suite path including root | ||
| */ | ||
| function getFullSuitePath(): string { | ||
| return [ROOT_SUITE, ...suitePathStack].join('\t'); | ||
| } | ||
|
|
||
| /** | ||
| * Wraps describe to automatically track suite hierarchy and set suite for tests | ||
| */ | ||
| function describeImpl(name: string, fn: () => void): void { | ||
| suitePathStack.push(name); | ||
| const currentPath = getFullSuitePath(); | ||
|
|
||
| originalDescribe(name, () => { | ||
| // Add beforeEach to set suite for all tests in this describe block | ||
| // This must be called before the test runs so the reporter picks it up | ||
| global.beforeEach(() => { | ||
| qase.suite(currentPath); | ||
| }); | ||
|
|
||
| // Store current it and test wrappers (they might be wrapped by parent describe) | ||
| const currentIt = global.it; | ||
| const currentTest = global.test; | ||
|
|
||
| // Wrap it() to automatically set suite at the very start | ||
| global.it = ((testName: any, fn?: any, timeout?: number) => { | ||
| // Handle qase-wrapped test names (qase returns a string) | ||
| if (typeof testName === 'string' && fn) { | ||
| return currentIt( | ||
| testName, | ||
| async () => { | ||
| // Set suite immediately at the start of the test | ||
| qase.suite(currentPath); | ||
| // Call the original test function and return the result | ||
| return fn(); | ||
| }, | ||
| timeout, | ||
| ); | ||
| } | ||
| // Handle cases where testName might be a number or other type | ||
| return currentIt(testName, fn, timeout); | ||
| }) as typeof global.it; | ||
|
|
||
| // Wrap test() to automatically set suite at the very start | ||
| global.test = ((testName: any, fn?: any, timeout?: number) => { | ||
| if (typeof testName === 'string' && fn) { | ||
| return currentTest( | ||
| testName, | ||
| async () => { | ||
| // Set suite immediately at the start of the test | ||
| qase.suite(currentPath); | ||
| // Call the original test function and return the result | ||
| return fn(); | ||
| }, | ||
| timeout, | ||
| ); | ||
| } | ||
| return currentTest(testName, fn, timeout); | ||
| }) as typeof global.test; | ||
|
|
||
| // Execute the describe block | ||
| fn(); | ||
|
|
||
| // Restore previous wrappers | ||
| global.it = currentIt; | ||
| global.test = currentTest; | ||
| }); | ||
|
|
||
| suitePathStack.pop(); | ||
| } | ||
|
|
||
| // Only apply qase wrapping if the environment variable is set | ||
| if (process.env.QASE_TESTOPS_JEST_API_TOKEN) { | ||
| // Replace global describe with our wrapper | ||
| (global as any).describe = Object.assign(describeImpl, { | ||
| skip: (name: string, fn: () => void) => originalDescribe.skip(name, fn), | ||
| only: (name: string, fn: () => void) => originalDescribe.only(name, fn), | ||
| }) as typeof global.describe; | ||
| } | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.