@@ -4,21 +4,10 @@ const { performance } = require('perf_hooks');
44
55global . currentSpec = null ;
66
7- /**
8- * Names of tests that fail randomly and are considered flaky. These tests will be retried
9- * a number of times to reduce the chance of false negatives. The test name must be the same
10- * as the one displayed in the CI log test output.
11- */
12- const flakyTests = [ ] ;
13-
147/** The minimum execution time in seconds for a test to be considered slow. */
158const slowTestLimit = 2 ;
169
17- /** The number of times to retry a flaky test. */
18- const retries = 5 ;
19-
2010const timerMap = { } ;
21- const retryMap = { } ;
2211const duplicates = [ ] ;
2312class CurrentSpecReporter {
2413 specStarted ( spec ) {
@@ -52,61 +41,6 @@ global.displayTestStats = function() {
5241 console . warn ( 'Duplicate spec: ' + spec ) ;
5342 } ) ;
5443 console . log ( '\n' ) ;
55- Object . keys ( retryMap ) . forEach ( ( spec ) => {
56- console . warn ( `Flaky test: ${ spec } failed ${ retryMap [ spec ] } times` ) ;
57- } ) ;
58- console . log ( '\n' ) ;
5944} ;
6045
61- global . retryFlakyTests = function ( ) {
62- const originalSpecConstructor = jasmine . Spec ;
63-
64- jasmine . Spec = function ( attrs ) {
65- const spec = new originalSpecConstructor ( attrs ) ;
66- const originalTestFn = spec . queueableFn . fn ;
67- const runOriginalTest = ( ) => {
68- if ( originalTestFn . length == 0 ) {
69- // handle async testing
70- return originalTestFn ( ) ;
71- } else {
72- // handle done() callback
73- return new Promise ( ( resolve ) => {
74- originalTestFn ( resolve ) ;
75- } ) ;
76- }
77- } ;
78- spec . queueableFn . fn = async function ( ) {
79- const isFlaky = flakyTests . includes ( spec . result . fullName ) ;
80- const runs = isFlaky ? retries : 1 ;
81- let exceptionCaught ;
82- let returnValue ;
83-
84- for ( let i = 0 ; i < runs ; ++ i ) {
85- spec . result . failedExpectations = [ ] ;
86- returnValue = undefined ;
87- exceptionCaught = undefined ;
88- try {
89- returnValue = await runOriginalTest ( ) ;
90- } catch ( exception ) {
91- exceptionCaught = exception ;
92- }
93- const failed = ! spec . markedPending &&
94- ( exceptionCaught || spec . result . failedExpectations . length != 0 ) ;
95- if ( ! failed ) {
96- break ;
97- }
98- if ( isFlaky ) {
99- retryMap [ spec . result . fullName ] = ( retryMap [ spec . result . fullName ] || 0 ) + 1 ;
100- await global . afterEachFn ( ) ;
101- }
102- }
103- if ( exceptionCaught ) {
104- throw exceptionCaught ;
105- }
106- return returnValue ;
107- } ;
108- return spec ;
109- } ;
110- }
111-
11246module . exports = CurrentSpecReporter ;
0 commit comments