question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

results.success is always false in custom reporter onRunComplete

See original GitHub issue

Logging results from onRunComplete in MyCustomReporter shows success is false even though all tests pass.

MyCustomReporter in tests/my-custom-reporter.js:

class MyCustomReporter {
  constructor(globalConfig, options) {
    this._globalConfig = globalConfig
    this._options = options
  }

  onRunComplete(contexts, results) {
    console.log({ results })
  }
}

module.exports = MyCustomReporter

jest config in package.json

  "jest": {
    "testEnvironment": "node",
    "reporters": [
      "./tests/my-custom-reporter.js"
    ]
  }

jest output (note success: false even though numFailedTests: 0)

$ node ./node_modules/.bin/jest path/to/tests.spec.js
 PASS  path/to/tests.spec.js
  outer
    ✓ works outer (1ms)
    inner
      ✓ works inner (1ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        0.352s, estimated 1s
Ran all test suites matching /path\/to\/tests.spec.js/i.
{ results:
   { numFailedTestSuites: 0,
     numFailedTests: 0,
     numPassedTestSuites: 1,
     numPassedTests: 2,
     numPendingTestSuites: 0,
     numPendingTests: 0,
     numRuntimeErrorTestSuites: 0,
     numTotalTestSuites: 1,
     numTotalTests: 2,
     openHandles: [],
     snapshot:
      { added: 0,
        didUpdate: false,
        failure: false,
        filesAdded: 0,
        filesRemoved: 0,
        filesUnmatched: 0,
        filesUpdated: 0,
        matched: 0,
        total: 0,
        unchecked: 0,
        uncheckedKeysByFile: [],
        unmatched: 0,
        updated: 0 },
     startTime: 1535648815628,
     success: false,
     testResults: [ [Object] ],
     wasInterrupted: false } }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Rand01phcommented, Feb 27, 2020

Maybe we assume that it’s failed until it’s passed and somewhere along the line we dropped setting success = true. Looks like this line attempts to set it to true

I found this Issue still exists in the latest version. For custom reporter, success is set after report generated, so what does this success symbol mean? I found move await this._dispatcher.onRunComplete(contexts, aggregatedResults); after aggregatedResults.success = ! ... will fix the issue, but I’m not sure for other logics

0reactions
github-actions[bot]commented, Apr 30, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The 4 stages of flakiness (part 2/3): log failed tests with a Jest ...
Creating a custom reporter would allow to both control the output of the test run ... onRunComplete(contexts, results) { ... success: false,
Read more >
Configuring Jest
Whereas a reporter has the ability to receive test results after individual tests and/or test suites are finished. testRunner [string]​. Default: jest-circus/ ...
Read more >
Unable to make HTTP Post from custom Karma reporter
I have verified that the Axios POST request works by taking the entire contents of the onRunComplete as shown here, putting it in...
Read more >
Allure Framework
Allure Framework is a flexible lightweight multi-language test report tool that not only shows a very concise representation of what have ...
Read more >
How to setup a custom test reporter for Jest | by Chanon Roy
Here is a simple test reporter that logs test results when the test ... onRunComplete(_: Set<TestContext>, results: AggregatedResult) {
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found