Comments (8)
Jest does not give the ability for reporters to easily iterate through describe blocks recursively so even if you wanted a reporter to treat describe blocks as test suites it would be an error-prone, edge case heavy, pain.
I am very willing to accept pull requests if you wanted to give it a shot.
from jest-junit.
Thanks for submitting an issue!
I think the confusion here is that Jest actually considers each test file a suite, not each describe block. So this is how jest-junit represents things.
You can absolutely have multiple describe blocks per file and even nest them as you have done here. jest-junit can use those describe block names in various places based on your configuration.
Here is how your test looks to jest-junit. You can see jest iterates through the tests not the describe blocks.
"numFailedTestSuites": 0,
"numFailedTests": 0,
"numPassedTestSuites": 1,
"numPassedTests": 2,
"numPendingTestSuites": 0,
"numPendingTests": 0,
"numRuntimeErrorTestSuites": 0,
"numTodoTests": 0,
"numTotalTestSuites": 1,
"numTotalTests": 2,
"openHandles": [],
"snapshot": {
"added": 0,
"didUpdate": false,
"failure": false,
"filesAdded": 0,
"filesRemoved": 0,
"filesRemovedList": [],
"filesUnmatched": 0,
"filesUpdated": 0,
"matched": 0,
"total": 0,
"unchecked": 0,
"uncheckedKeysByFile": [],
"unmatched": 0,
"updated": 0
},
"startTime": 1678243830484,
"success": false,
"testResults": [
{
"leaks": false,
"numFailingTests": 0,
"numPassingTests": 2,
"numPendingTests": 0,
"numTodoTests": 0,
"openHandles": [],
"perfStats": {
"end": 1678243831136,
"runtime": 506,
"slow": false,
"start": 1678243830630
},
"skipped": false,
"snapshot": {
"added": 0,
"fileDeleted": false,
"matched": 0,
"unchecked": 0,
"uncheckedKeys": [],
"unmatched": 0,
"updated": 0
},
"testFilePath": "/Users/jsonp/Desktop/test/__tests__/sum.test.js",
"testResults": [
{
"ancestorTitles": [
"addition",
"positive numbers"
],
"duration": 2,
"failureDetails": [],
"failureMessages": [],
"fullName": "addition positive numbers should add up",
"invocations": 1,
"location": null,
"numPassingAsserts": 1,
"retryReasons": [],
"status": "passed",
"title": "should add up"
},
{
"ancestorTitles": [
"subtraction",
"positive numbers"
],
"duration": 0,
"failureDetails": [],
"failureMessages": [],
"fullName": "subtraction positive numbers should subtract",
"invocations": 1,
"location": null,
"numPassingAsserts": 1,
"retryReasons": [],
"status": "passed",
"title": "should subtract"
}
],
"failureMessage": null
}
],
"wasInterrupted": false
}```
from jest-junit.
Thanks @palmerj3
From what I understand each test file must contain only one top-level describe()
block. Is there any workaround so that I can avoid updating the test file?
from jest-junit.
Sorry there is not
from jest-junit.
"Jest actually considers each test file a suite"
Can you point me to the jest code or documentation where I can check this?
from jest-junit.
Jest passes reporters who listen for the onTestResult event AggregatedResultWithoutCoverageAggregatedResultWithoutCoverage .
This type contains the testResults property of type TestResultTestResult.
Each index in TestResult has a testFilePath and aggregate reporting results such as numFailingTests, numPassingTests, etc which map exactly to Junit TestSuite level reporting.
Hence, Jest treats test files as suites.
I've worked on the reporter system enough to go into more detail if needed but this should suffice.
from jest-junit.
Thanks @palmerj3! If it is Jest that is causing the pain, I guess it would be better if an issue is raised to Jest project to make it easier for reporters to be able treat describe block as test suites. However, I do not know enough to be able to suggest changes in Jest. Would you help raising an issue with Jest, if you agree?
from jest-junit.
I see jest-html-reporter and jest-html-reporters(in particular) are able to display the describe()
blocks under the file name as I would expect it to be. But I do not know how they're able to do it. I've updated the repo linked above with these packages for comparison.
from jest-junit.
Related Issues (20)
- Getting "extra" testcases, one "correct", another with just a Test Execution Failure HOT 3
- [Question] include console log as a system.out to the junit report. HOT 1
- Handle boolean values in addition to strings within config HOT 2
- Feature Request: Add `line` attribute to `<testcase>` element HOT 5
- Feature Request: outputNameTemplate HOT 4
- Feature request: Support for test case properties HOT 4
- Can't run jest-junit as a reporter HOT 2
- Feature Request: Mark 'todo' tests as 'skipped' HOT 3
- Feature Request: Allow adding custom properties to `<testcase>` HOT 2
- ERR_REQUIRE_ESM HOT 2
- I have a Create React App and am trying to get unit test running in an Azure pipeline. HOT 1
- I didnt find jest-junit latest version updated with latest strip ansi 7.0.1
- Feature request: attribute retry HOT 1
- Add <rootDir> expansion to `filePathPrefix`
- Feature Request: Injection values in outputName HOT 3
- Failed to write coverage reports: HOT 4
- Report is not generated when using --forceExit
- Code Coverage not included in JUnit Report HOT 2
- Line coverage in jest-junit report HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-junit.