@@ -26,14 +26,20 @@ import {convertDescriptorToString} from 'jest-util';
2626import isGeneratorFn from 'is-generator-fn' ;
2727import co from 'co' ;
2828
29+ import StackUtils from 'stack-utils' ;
30+
2931import prettyFormat from 'pretty-format' ;
3032
33+ import { getState } from './state' ;
34+
3135// Try getting the real promise object from the context, if available. Someone
3236// could have overridden it in a test. Async functions return it implicitly.
3337// eslint-disable-next-line no-unused-vars
3438const Promise = global [ Symbol . for ( 'jest-native-promise' ) ] || global . Promise ;
3539export const getOriginalPromise = ( ) => Promise ;
3640
41+ const stackUtils = new StackUtils ( { cwd : 'A path that does not exist' } ) ;
42+
3743export const makeDescribe = (
3844 name : BlockName ,
3945 parent : ?DescribeBlock ,
@@ -235,7 +241,8 @@ export const makeRunResult = (
235241 } ;
236242} ;
237243
238- const makeTestResults = ( describeBlock : DescribeBlock ) : TestResults => {
244+ const makeTestResults = ( describeBlock : DescribeBlock , config ) : TestResults => {
245+ const { includeTestLocationInResult} = getState ( ) ;
239246 let testResults = [ ] ;
240247 for ( const test of describeBlock . tests ) {
241248 const testPath = [ ] ;
@@ -249,16 +256,25 @@ const makeTestResults = (describeBlock: DescribeBlock): TestResults => {
249256 if ( ! status ) {
250257 throw new Error ( 'Status should be present after tests are run.' ) ;
251258 }
259+
260+ let location = null ;
261+ if ( includeTestLocationInResult ) {
262+ const stackLine = test . asyncError . stack . split ( '\n' ) [ 1 ] ;
263+ const { line, column} = stackUtils . parseLine ( stackLine ) ;
264+ location = { column, line} ;
265+ }
266+
252267 testResults . push ( {
253268 duration : test . duration ,
254269 errors : test . errors . map ( _formatError ) ,
270+ location,
255271 status,
256272 testPath,
257273 } ) ;
258274 }
259275
260276 for ( const child of describeBlock . children ) {
261- testResults = testResults . concat ( makeTestResults ( child ) ) ;
277+ testResults = testResults . concat ( makeTestResults ( child , config ) ) ;
262278 }
263279
264280 return testResults ;
0 commit comments