@@ -72,6 +72,28 @@ test('emits <failure> when beforeAll/afterAll failed', async () => {
7272 expect ( xml ) . toMatchSnapshot ( )
7373} )
7474
75+ test ( 'time' , async ( ) => {
76+ const { stdout } = await runVitest ( { reporters : 'junit' , root : './fixtures/duration' } )
77+
78+ const xml = stabilizeReportWOTime ( stdout )
79+
80+ const fastTestRegex = / < t e s t c a s e c l a s s n a m e = " b a s i c \. t e s t \. t s " n a m e = " f a s t " t i m e = " (?< floatNumber > [ \d . ] + ) " > /
81+ const fastTestTime = matchJunitTime ( xml , fastTestRegex )
82+ expect ( fastTestTime ) . toBeGreaterThan ( 0 )
83+
84+ const slowTestRegex = / < t e s t c a s e c l a s s n a m e = " b a s i c \. t e s t \. t s " n a m e = " s l o w " t i m e = " (?< floatNumber > [ \d . ] + ) " > /
85+ const slowTestTime = matchJunitTime ( xml , slowTestRegex )
86+ expect ( slowTestTime ) . toBeGreaterThan ( 0.2 )
87+
88+ const testsuiteRegex = / < t e s t s u i t e n a m e = " b a s i c \. t e s t \. t s " t i m e s t a m p = " \. \. \. " h o s t n a m e = " \. \. \. " t e s t s = " 2 " f a i l u r e s = " 0 " e r r o r s = " 0 " s k i p p e d = " 0 " t i m e = " (?< floatNumber > [ \d . ] + ) " > /
89+ const testsuiteTime = matchJunitTime ( xml , testsuiteRegex )
90+ expect ( testsuiteTime ) . toBeCloseTo ( fastTestTime + slowTestTime , 1 )
91+
92+ const testsuitesRegex = / < t e s t s u i t e s n a m e = " v i t e s t t e s t s " t e s t s = " 2 " f a i l u r e s = " 0 " e r r o r s = " 0 " t i m e = " (?< floatNumber > [ \d . ] + ) " > /
93+ const testsuitesTime = matchJunitTime ( xml , testsuitesRegex )
94+ expect ( testsuitesTime ) . toBeCloseTo ( testsuiteTime , 1 )
95+ } )
96+
7597test ( 'format error' , async ( ) => {
7698 const { stdout } = await runVitest ( { reporters : 'junit' , root } , [ 'error.test.ts' ] )
7799 expect ( stabilizeReport ( stdout ) ) . toMatchSnapshot ( )
@@ -118,6 +140,18 @@ function stabilizeReport(report: string) {
118140 return report . replaceAll ( / ( t i m e s t a m p | h o s t n a m e | t i m e ) = " .* ?" / g, '$1="..."' )
119141}
120142
143+ function stabilizeReportWOTime ( report : string ) {
144+ return report . replaceAll ( / ( t i m e s t a m p | h o s t n a m e ) = " .* ?" / g, '$1="..."' )
145+ }
146+
147+ function matchJunitTime ( xml : string , regex : RegExp ) {
148+ const match = xml . match ( regex )
149+ expect ( match ) . not . toBeNull ( )
150+ const time = Number . parseFloat ( match ! . groups ! . floatNumber )
151+ expect ( time ) . toBeGreaterThanOrEqual ( 0 )
152+ return time
153+ }
154+
121155test . each ( [ true , false ] ) ( 'includeConsoleOutput %s' , async ( t ) => {
122156 const { stdout } = await runVitest ( {
123157 reporters : [ [ 'junit' , { includeConsoleOutput : t } ] ] ,
0 commit comments