Giter Club home page Giter Club logo

Comments (8)

palmerj3 avatar palmerj3 commented on July 17, 2024 1

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.

palmerj3 avatar palmerj3 commented on July 17, 2024

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.

phalgunv avatar phalgunv commented on July 17, 2024

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.

palmerj3 avatar palmerj3 commented on July 17, 2024

Sorry there is not

from jest-junit.

phalgunv avatar phalgunv commented on July 17, 2024

"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.

palmerj3 avatar palmerj3 commented on July 17, 2024

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.

phalgunv avatar phalgunv commented on July 17, 2024

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.

phalgunv avatar phalgunv commented on July 17, 2024

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.

jest-html-reporter:
image

jest-html-reporters:
image

from jest-junit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.