@@ -26,14 +26,20 @@ import {convertDescriptorToString} from 'jest-util';
26
26
import isGeneratorFn from 'is-generator-fn' ;
27
27
import co from 'co' ;
28
28
29
+ import StackUtils from 'stack-utils' ;
30
+
29
31
import prettyFormat from 'pretty-format' ;
30
32
33
+ import { getState } from './state' ;
34
+
31
35
// Try getting the real promise object from the context, if available. Someone
32
36
// could have overridden it in a test. Async functions return it implicitly.
33
37
// eslint-disable-next-line no-unused-vars
34
38
const Promise = global [ Symbol . for ( 'jest-native-promise' ) ] || global . Promise ;
35
39
export const getOriginalPromise = ( ) => Promise ;
36
40
41
+ const stackUtils = new StackUtils ( { cwd : 'A path that does not exist' } ) ;
42
+
37
43
export const makeDescribe = (
38
44
name : BlockName ,
39
45
parent : ?DescribeBlock ,
@@ -235,7 +241,8 @@ export const makeRunResult = (
235
241
} ;
236
242
} ;
237
243
238
- const makeTestResults = ( describeBlock : DescribeBlock ) : TestResults => {
244
+ const makeTestResults = ( describeBlock : DescribeBlock , config ) : TestResults => {
245
+ const { includeTestLocationInResult} = getState ( ) ;
239
246
let testResults = [ ] ;
240
247
for ( const test of describeBlock . tests ) {
241
248
const testPath = [ ] ;
@@ -249,16 +256,25 @@ const makeTestResults = (describeBlock: DescribeBlock): TestResults => {
249
256
if ( ! status ) {
250
257
throw new Error ( 'Status should be present after tests are run.' ) ;
251
258
}
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
+
252
267
testResults . push ( {
253
268
duration : test . duration ,
254
269
errors : test . errors . map ( _formatError ) ,
270
+ location,
255
271
status,
256
272
testPath,
257
273
} ) ;
258
274
}
259
275
260
276
for ( const child of describeBlock . children ) {
261
- testResults = testResults . concat ( makeTestResults ( child ) ) ;
277
+ testResults = testResults . concat ( makeTestResults ( child , config ) ) ;
262
278
}
263
279
264
280
return testResults ;
0 commit comments