Repository navigation
fix: make qase.* work in Jest worker processes - #1041
Merged
Merged
Conversation
The reporter exposed qase.* through global.Qase in the main process, while Jest runs tests in worker processes, so with more than one worker every call threw TypeError and the test was reported as invalid. Only --runInBand worked (#762). Tests now write each test's metadata to a temporary directory the reporter creates (passed to workers through QASE_JEST_METADATA_DIR) and the reporter reads it when the test's result arrives. Files are written through a rename so a result never sees a half-written file, and a bad file never stops the run. The current test is resolved from Jest's own state: - test.concurrent through currentConcurrentTestName, as jest-snapshot does; Jest 30 reports sequential tests there too. - retries are keyed by attempt, so each reported attempt gets its own metadata. - calls from beforeAll/afterAll are dropped instead of landing on the previous test, including after skipped and todo tests. Calls without the reporter configured are no-ops instead of throwing. Examples no longer force --runInBand; docs note that the network profiler still needs a single process. Removes the unused env.ts.
- With injectGlobals: false there is no global expect; fall back to @jest/globals, which Jest's runtime serves to every test file. Every qase.* call was silently dropped in that setup. - Jest passes the runner's shared context to onTestCaseResult, so a per-test result does not say which project ran it, and a file run by several projects at once mixed their metadata. The reporter now tags each project's globals with its id (read by the worker), tracks which projects run each file, and reports overlapping runs from onTestResult, which carries the real project. The tag is never overwritten, since projects without their own globals share Jest's default object.
Contributor
Author
|
Follow-up after a second verification round (commit 0b3a09a):
Full matrix re-run on the final build: generated suites 1–8 workers + in-band on Jest 29/30, stress, retries, no-reporter, environments, projects, and |
The worker support from this PR was only documented in docs/usage.md and the changelog.
apetrosyan1613
approved these changes
Oct 30, 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.
Summary
jest-qase-reporter 2.8.0. Fixes #762: with more than one Jest worker (Jest's default) every
qase.*call threwTypeErrorand the test was reported asinvalid, because the API lived onglobal.Qasein the main process while tests run in workers. Only--runInBandworked.How: tests write each test's metadata to a temp directory the reporter creates (passed to workers via
QASE_JEST_METADATA_DIR); the reporter reads it inonTestCaseResult. Writes go through a rename (no torn reads); a bad file never stops the run; the directory is removed on exit (not on run completion, so watch mode keeps working).The current test is resolved from Jest's own state:
test.concurrentviacurrentConcurrentTestName(as jest-snapshot does); Jest 30 reports sequential tests there too, handled.invocations), so each reported attempt has its own metadata.beforeAll/afterAllcalls are dropped instead of landing on the previous test (circus keepscurrentTestNameafter a test ends, and skipped/todo tests never finish).Also:
qase.*without the reporter configured is a no-op instead of throwing; examples no longer force--runInBand; docs say the network profiler still needs a single process; unusedenv.tsremoved.Test plan
-w=3→ 181 problems across 210 results; new code → 0qase.*call, checked for cross-test leakage: 30/60 files, 1–8 workers and--runInBand, on Jest 29.7 and Jest 30.5beforeEach,beforeAll/afterAll(incl. after skip/todo),test.each,test.concurrent,jest.retryTimes, no reporter configuredexamples/single/jestrun exactly as CI does, without--runInBandand with a fresh cache → matchesexpected/jest-examples.yaml(no baseline change)