@@ -328,19 +328,25 @@ export const makeRunResult = (
328328 unhandledErrors : unhandledErrors . map ( _getError ) . map ( getErrorStack ) ,
329329} ) ;
330330
331+ const getTestNamesPath = ( test : Circus . TestEntry ) : Circus . TestNamesPath => {
332+ const titles = [ ] ;
333+ let parent : Circus . TestEntry | Circus . DescribeBlock | undefined = test ;
334+ do {
335+ titles . unshift ( parent . name ) ;
336+ } while ( ( parent = parent . parent ) ) ;
337+
338+ return titles ;
339+ } ;
340+
331341export const makeSingleTestResult = (
332342 test : Circus . TestEntry ,
333343) : Circus . TestResult => {
334344 const { includeTestLocationInResult} = getState ( ) ;
335- const testPath = [ ] ;
336- let parent : Circus . TestEntry | Circus . DescribeBlock | undefined = test ;
337345
338346 const { status} = test ;
339347 invariant ( status , 'Status should be present after tests are run.' ) ;
340348
341- do {
342- testPath . unshift ( parent . name ) ;
343- } while ( ( parent = parent . parent ) ) ;
349+ const testPath = getTestNamesPath ( test ) ;
344350
345351 let location = null ;
346352 if ( includeTestLocationInResult ) {
@@ -402,14 +408,9 @@ const makeTestResults = (
402408// Return a string that identifies the test (concat of parent describe block
403409// names + test title)
404410export const getTestID = ( test : Circus . TestEntry ) : string => {
405- const titles = [ ] ;
406- let parent : Circus . TestEntry | Circus . DescribeBlock | undefined = test ;
407- do {
408- titles . unshift ( parent . name ) ;
409- } while ( ( parent = parent . parent ) ) ;
410-
411- titles . shift ( ) ; // remove TOP_DESCRIBE_BLOCK_NAME
412- return titles . join ( ' ' ) ;
411+ const testNamesPath = getTestNamesPath ( test ) ;
412+ testNamesPath . shift ( ) ; // remove TOP_DESCRIBE_BLOCK_NAME
413+ return testNamesPath . join ( ' ' ) ;
413414} ;
414415
415416const _getError = (
@@ -464,6 +465,29 @@ export function invariant(
464465 }
465466}
466467
468+ type TestDescription = {
469+ ancestorTitles : Array < string > ;
470+ fullName : string ;
471+ title : string ;
472+ } ;
473+
474+ const resolveTestCaseStartInfo = (
475+ testNamesPath : Circus . TestNamesPath ,
476+ ) : TestDescription => {
477+ const ancestorTitles = testNamesPath . filter (
478+ name => name !== ROOT_DESCRIBE_BLOCK_NAME ,
479+ ) ;
480+ const fullName = ancestorTitles . join ( ' ' ) ;
481+ const title = testNamesPath [ testNamesPath . length - 1 ] ;
482+ // remove title
483+ ancestorTitles . pop ( ) ;
484+ return {
485+ ancestorTitles,
486+ fullName,
487+ title,
488+ } ;
489+ } ;
490+
467491export const parseSingleTestResult = (
468492 testResult : Circus . TestResult ,
469493) : AssertionResult => {
@@ -478,24 +502,36 @@ export const parseSingleTestResult = (
478502 status = 'passed' ;
479503 }
480504
481- const ancestorTitles = testResult . testPath . filter (
482- name => name !== ROOT_DESCRIBE_BLOCK_NAME ,
505+ const { ancestorTitles, fullName , title } = resolveTestCaseStartInfo (
506+ testResult . testPath ,
483507 ) ;
484- const title = ancestorTitles . pop ( ) ;
485508
486509 return {
487510 ancestorTitles,
488511 duration : testResult . duration ,
489512 failureDetails : testResult . errorsDetailed ,
490513 failureMessages : Array . from ( testResult . errors ) ,
491- fullName : title
492- ? ancestorTitles . concat ( title ) . join ( ' ' )
493- : ancestorTitles . join ( ' ' ) ,
514+ fullName,
494515 invocations : testResult . invocations ,
495516 location : testResult . location ,
496517 numPassingAsserts : testResult . numPassingAsserts ,
497518 retryReasons : Array . from ( testResult . retryReasons ) ,
498519 status,
499- title : testResult . testPath [ testResult . testPath . length - 1 ] ,
520+ title,
521+ } ;
522+ } ;
523+
524+ export const createTestCaseStartInfo = (
525+ test : Circus . TestEntry ,
526+ ) : Circus . TestCaseStartInfo => {
527+ const testPath = getTestNamesPath ( test ) ;
528+ const { ancestorTitles, fullName, title} = resolveTestCaseStartInfo ( testPath ) ;
529+
530+ return {
531+ ancestorTitles,
532+ fullName,
533+ mode : test . mode ,
534+ startedAt : test . startedAt ,
535+ title,
500536 } ;
501537} ;
0 commit comments