Skip to content
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

Expose the line number of a failing test block in output #4775

Closed
sharmilajesupaul opened this issue Oct 27, 2017 · 5 comments · Fixed by #4782
Closed

Expose the line number of a failing test block in output #4775

sharmilajesupaul opened this issue Oct 27, 2017 · 5 comments · Fixed by #4782

Comments

@sharmilajesupaul
Copy link

I'm trying to build an automated reporting tool that flags and skips flaky tests. It would be really helpful if Jest provided the line number for a failing test in the output file.

The script we're using to run generate the output file is:
jest --json --outputFile=./tmp/jest.json --silent .

cc. @gdborton, @ljharb

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
The information in the output file for a failing test includes a stack trace but does not expose the line number of the failing test block.

What is the expected behavior?
Expose the starting line number of the failing test block. So I can append .skip to it blocks.

e.g. For this file:

// failing_spec.js
import { expect } from 'chai';

describe('Failing test', () => {
  it('should fail', () => {
    expect(false).to.equal(true);
  });
});

Diff of output with added lineNumber:

{
  "numFailedTestSuites": 1,
  "numFailedTests": 1,
  "numPassedTestSuites": 0,
  "numPassedTests": 0,
  "numPendingTestSuites": 0,
  "numPendingTests": 0,
  "numRuntimeErrorTestSuites": 0,
  "numTotalTestSuites": 1,
  "numTotalTests": 1,
  "snapshot":
  {
    "added": 0,
    "didUpdate": false,
    "failure": false,
    "filesAdded": 0,
    "filesRemoved": 0,
    "filesUnmatched": 0,
    "filesUpdated": 0,
    "matched": 0,
    "total": 0,
    "unchecked": 0,
    "unmatched": 0,
    "updated": 0
  },
  "startTime": 1509064905195,
  "success": false,
  "testResults": [
  {
    "assertionResults": [
    {
      "ancestorTitles": ["Failing test"],
      "failureMessages": ["AssertionError: expected false to equal true\n    at Object.<anonymous> (/failing_spec.js:5:33)\n    at Object.asyncFn (/node_modules/jest-jasmine2/build/jasmine_async.js:68:30)\n    at e (/node_modules/jest-jasmine2/build/queue_runner.js:47:12)\n    at mapper (/node_modules/jest-jasmine2/build/queue_runner.js:34:19)\n    at promise.then (/node_modules/jest-jasmine2/build/queue_runner.js:75:39)\n    at process._tickCallback (internal/process/next_tick.js:109:7)"],
      "fullName": "Failing test should fail",
+     "lineNumber": [4, 3],
      "status": "failed",
      "title": "should fail"
    }],
    "endTime": 1509064906822,
    "message": "\u001b[1m\u001b[31m  \u001b[1m● \u001b[1mFailing test › should fail\u001b[39m\u001b[22m\n\n    AssertionError: expected false to equal true\n\u001b[2m      \u001b[22m\n\u001b[2m      \u001b[2mat Object.<anonymous> (\u001b[2m\u001b[0m\u001b[36mspec/javascripts/failing_spec.js\u001b[39m\u001b[0m\u001b[2m:5:33)\u001b[2m\u001b[22m\n\u001b[2m      \u001b[2mat process._tickCallback (\u001b[2minternal/process/next_tick.js\u001b[2m:109:7)\u001b[2m\u001b[22m\n",
    "name": "/spec/javascripts/failing_spec.js",
    "startTime": 1509064905271,
    "status": "failed",
    "summary": ""
  }],
  "wasInterrupted": false
}

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

// node: v6.11.1
// npm: 3.10.10

// jest config
{
  "bail": false,
  "collectCoverageFrom": [
    "**/app/assets/javascripts/**/*.{js,jsx}",
    "!**/vendor/**",
    "!**/node_modules/**",
    "!**/lib/**",
    "!**/spec/**",
    "!**/public/**",
    "!script/**",
    "!**/ext/**",
    "!test/**",
    "!coverage/**",
    "!**/packages/**",
    "!**/initializers/**",
    "!**/javascripts/facebook.js",
    "!**/javascripts/deep_link/branchSdkLoader.js",
    "!**/javascripts/april_fools/**",
  ],
  "coverageReporters": ["json-summary", "lcov", "html"],
  "testEnvironment": "node",
  "rootDir": "..",
  "roots": [
    "./app/assets/javascripts",
    "./spec/javascripts"
  ],
  "setupTestFrameworkScriptFile": "<rootDir>/spec/jest/setupJest.js",
  "testRegex": "spec/javascripts/.*(\\.|/|_)(test|spec)\\.jsx?$",
  "testURL": "https://foo.com",
  "transform": {
    "^.+\\.jsx?$": "<rootDir>/node_modules/babel-jest"
  }
}
@SimenB
Copy link
Member

SimenB commented Oct 27, 2017

This sounds like a cool idea. A quick look seems to indicate that this information is not currently available, though. Jasmine would have to expose it.

jasmine/jasmine#537

That issue links to a possible workaround overriding it, which we can maybe do. Instead of throwing an error, we can do V8 stack capture though. Probably opt-in as well to avoid the perf hit for everyone

@cpojer thoughts? I haven't dug far enough into it to see if it's possible, but based on https://github.com/agirorn/jasmine-slow-reporter it seems like it should be feasible (in the same way we alias it to test already)

@cpojer
Copy link
Member

cpojer commented Oct 27, 2017

If it's easy to add and doesn't slow down Jest, I'm on board.

SimenB added a commit to SimenB/jest that referenced this issue Oct 28, 2017
@SimenB
Copy link
Member

SimenB commented Oct 28, 2017

PR: #4782

cpojer pushed a commit that referenced this issue Nov 4, 2017
* Add `testLocationInResults` option

Fixes #4775

* Update snapshot

* Update changelog with link to PR

* Fix typo in docs

* Update Configuration.md

* Update index.js
@jasonfb

This comment has been minimized.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants