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.
```js
// 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": "
"testRegex": "spec/javascripts/.
"testURL": "https://foo.com",
"transform": {
"^.+\.jsx?$": "
}
}
````
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.
https://github.com/jasmine/jasmine/issues/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)
If it's easy to add and doesn't slow down Jest, I'm on board.
PR: #4782
💯
Most helpful comment
PR: #4782