1
1
/**
2
2
* Copyright 2017 Google Inc. All rights reserved.
3
+ * Modifications copyright (c) Microsoft Corporation.
3
4
*
4
5
* Licensed under the Apache License, Version 2.0 (the "License");
5
6
* you may not use this file except in compliance with the License.
17
18
const EventEmitter = require ( 'events' ) ;
18
19
const { SourceMapSupport} = require ( './SourceMapSupport' ) ;
19
20
const debug = require ( 'debug' ) ;
20
- const { getCallerLocation } = require ( './utils ' ) ;
21
+ const Location = require ( './Location ' ) ;
21
22
22
23
const INFINITE_TIMEOUT = 100000000 ;
23
24
const TimeoutError = new Error ( 'Timeout' ) ;
@@ -53,7 +54,7 @@ const TestResult = {
53
54
} ;
54
55
55
56
function createHook ( callback , name ) {
56
- const location = getCallerLocation ( __filename ) ;
57
+ const location = Location . getCallerLocation ( __filename ) ;
57
58
return { name, body : callback , location } ;
58
59
}
59
60
@@ -456,14 +457,13 @@ class TestWorker {
456
457
this . _runningHookTerminate = null ;
457
458
458
459
if ( error ) {
459
- const locationString = `${ hook . location . fileName } :${ hook . location . lineNumber } :${ hook . location . columnNumber } ` ;
460
460
if ( testRun && testRun . _result !== TestResult . Terminated ) {
461
461
// Prefer terminated result over any hook failures.
462
462
testRun . _result = error === TerminatedError ? TestResult . Terminated : TestResult . Crashed ;
463
463
}
464
464
let message ;
465
465
if ( error === TimeoutError ) {
466
- message = `${ locationString } - Timeout Exceeded ${ timeout } ms while running "${ hook . name } " in "${ fullName } "` ;
466
+ message = `${ hook . location . toDetailedString ( ) } - Timeout Exceeded ${ timeout } ms while running "${ hook . name } " in "${ fullName } "` ;
467
467
error = null ;
468
468
} else if ( error === TerminatedError ) {
469
469
// Do not report termination details - it's just noise.
@@ -472,7 +472,7 @@ class TestWorker {
472
472
} else {
473
473
if ( error . stack )
474
474
await this . _testPass . _runner . _sourceMapSupport . rewriteStackTraceWithSourceMaps ( error ) ;
475
- message = `${ locationString } - FAILED while running "${ hook . name } " in suite "${ fullName } ": ` ;
475
+ message = `${ hook . location . toDetailedString ( ) } - FAILED while running "${ hook . name } " in suite "${ fullName } ": ` ;
476
476
}
477
477
await this . _didFailHook ( hook , fullName , message , error ) ;
478
478
if ( testRun )
@@ -497,26 +497,26 @@ class TestWorker {
497
497
}
498
498
499
499
async _willStartTestBody ( testRun ) {
500
- debug ( 'testrunner:test' ) ( `[${ this . _workerId } ] starting "${ testRun . test ( ) . fullName ( ) } " (${ testRun . test ( ) . location ( ) . fileName + ':' + testRun . test ( ) . location ( ) . lineNumber } )` ) ;
500
+ debug ( 'testrunner:test' ) ( `[${ this . _workerId } ] starting "${ testRun . test ( ) . fullName ( ) } " (${ testRun . test ( ) . location ( ) } )` ) ;
501
501
}
502
502
503
503
async _didFinishTestBody ( testRun ) {
504
- debug ( 'testrunner:test' ) ( `[${ this . _workerId } ] ${ testRun . _result . toUpperCase ( ) } "${ testRun . test ( ) . fullName ( ) } " (${ testRun . test ( ) . location ( ) . fileName + ':' + testRun . test ( ) . location ( ) . lineNumber } )` ) ;
504
+ debug ( 'testrunner:test' ) ( `[${ this . _workerId } ] ${ testRun . _result . toUpperCase ( ) } "${ testRun . test ( ) . fullName ( ) } " (${ testRun . test ( ) . location ( ) } )` ) ;
505
505
}
506
506
507
507
async _willStartHook ( hook , fullName ) {
508
- debug ( 'testrunner:hook' ) ( `[${ this . _workerId } ] "${ hook . name } " started for "${ fullName } " (${ hook . location . fileName + ':' + hook . location . lineNumber } )` ) ;
508
+ debug ( 'testrunner:hook' ) ( `[${ this . _workerId } ] "${ hook . name } " started for "${ fullName } " (${ hook . location } )` ) ;
509
509
}
510
510
511
511
async _didFailHook ( hook , fullName , message , error ) {
512
- debug ( 'testrunner:hook' ) ( `[${ this . _workerId } ] "${ hook . name } " FAILED for "${ fullName } " (${ hook . location . fileName + ':' + hook . location . lineNumber } )` ) ;
512
+ debug ( 'testrunner:hook' ) ( `[${ this . _workerId } ] "${ hook . name } " FAILED for "${ fullName } " (${ hook . location } )` ) ;
513
513
if ( message )
514
514
this . _testPass . _result . addError ( message , error , this ) ;
515
515
this . _testPass . _result . setResult ( TestResult . Crashed , message ) ;
516
516
}
517
517
518
518
async _didCompleteHook ( hook , fullName ) {
519
- debug ( 'testrunner:hook' ) ( `[${ this . _workerId } ] "${ hook . name } " OK for "${ fullName } " (${ hook . location . fileName + ':' + hook . location . lineNumber } )` ) ;
519
+ debug ( 'testrunner:hook' ) ( `[${ this . _workerId } ] "${ hook . name } " OK for "${ fullName } " (${ hook . location } )` ) ;
520
520
}
521
521
522
522
async shutdown ( ) {
@@ -581,7 +581,7 @@ class TestPass {
581
581
async _runWorker ( testRunIndex , testRuns , parallelIndex ) {
582
582
let worker = new TestWorker ( this , this . _nextWorkerId ++ , parallelIndex ) ;
583
583
this . _workers [ parallelIndex ] = worker ;
584
- while ( ! worker . _terminating ) {
584
+ while ( ! this . _terminating ) {
585
585
let skipped = 0 ;
586
586
while ( skipped < testRuns . length && testRuns [ testRunIndex ] . _result !== null ) {
587
587
testRunIndex = ( testRunIndex + 1 ) % testRuns . length ;
@@ -613,6 +613,7 @@ class TestPass {
613
613
614
614
async _terminate ( result , message , force , error ) {
615
615
debug ( 'testrunner' ) ( `TERMINATED result = ${ result } , message = ${ message } ` ) ;
616
+ this . _terminating = true ;
616
617
for ( const worker of this . _workers )
617
618
worker . terminate ( force /* terminateHooks */ ) ;
618
619
this . _result . setResult ( result , message ) ;
@@ -638,8 +639,7 @@ class TestRunner extends EventEmitter {
638
639
} = options ;
639
640
this . _crashIfTestsAreFocusedOnCI = crashIfTestsAreFocusedOnCI ;
640
641
this . _sourceMapSupport = new SourceMapSupport ( ) ;
641
- const dummyLocation = { fileName : '' , filePath : '' , lineNumber : 0 , columnNumber : 0 } ;
642
- this . _rootSuite = new Suite ( null , '' , dummyLocation ) ;
642
+ this . _rootSuite = new Suite ( null , '' , new Location ( ) ) ;
643
643
this . _currentSuite = this . _rootSuite ;
644
644
this . _tests = [ ] ;
645
645
this . _suites = [ ] ;
@@ -670,7 +670,7 @@ class TestRunner extends EventEmitter {
670
670
671
671
_suiteBuilder ( callbacks ) {
672
672
return new Proxy ( ( name , callback , ...suiteArgs ) => {
673
- const location = getCallerLocation ( __filename ) ;
673
+ const location = Location . getCallerLocation ( __filename ) ;
674
674
const suite = new Suite ( this . _currentSuite , name , location ) ;
675
675
for ( const { callback, args } of callbacks )
676
676
callback ( suite , ...args ) ;
@@ -692,7 +692,7 @@ class TestRunner extends EventEmitter {
692
692
693
693
_testBuilder ( callbacks ) {
694
694
return new Proxy ( ( name , callback ) => {
695
- const location = getCallerLocation ( __filename ) ;
695
+ const location = Location . getCallerLocation ( __filename ) ;
696
696
const test = new Test ( this . _currentSuite , name , callback , location ) ;
697
697
test . setTimeout ( this . _timeout ) ;
698
698
for ( const { callback, args } of callbacks )
0 commit comments