@@ -71,30 +71,14 @@ describe('generateMetrics', () => {
7171 const report = createReport ( [ createSuite ( ) ] )
7272 const metrics = generateMetrics ( report , config )
7373
74- expect ( metrics ) . toHaveLength ( 5 )
74+ expect ( metrics ) . toHaveLength ( 1 )
7575
7676 expect ( metrics . map ( ( m ) => ( { name : m . metricName , type : m . metricType } ) ) )
7777 . toMatchInlineSnapshot ( `
7878 [
7979 {
80- "name": "test.suite.duration",
81- "type": "histogram",
82- },
83- {
84- "name": "test.suite.cumulative_duration",
85- "type": "histogram",
86- },
87- {
88- "name": "test.suite.total",
89- "type": "updowncounter",
90- },
91- {
92- "name": "test.duration",
93- "type": "histogram",
94- },
95- {
96- "name": "test.status",
97- "type": "counter",
80+ "name": "test_duration_seconds",
81+ "type": "gauge",
9882 },
9983 ]
10084 ` )
@@ -116,17 +100,18 @@ describe('generateMetrics', () => {
116100 } )
117101 } )
118102
119- it ( 'generates histogram buckets for duration metrics ' , ( ) => {
103+ it ( 'generates gauge metrics for test duration ' , ( ) => {
120104 const report = createReport ( [ createSuite ( ) ] )
121105 const metrics = generateMetrics ( report , config )
122106
123- const testDuration = metrics . find ( ( m ) => m . metricName === 'test.duration' )
124- const suiteDuration = metrics . find (
125- ( m ) => m . metricName === 'test.suite.duration'
107+ const testDuration = metrics . find (
108+ ( m ) => m . metricName === 'test_duration_seconds'
126109 )
127110
128111 expect ( testDuration ) . toBeDefined ( )
129- expect ( suiteDuration ) . toBeDefined ( )
112+ expect ( testDuration ?. metricType ) . toBe ( 'gauge' )
113+ expect ( testDuration ?. value ) . toBe ( 1.5 )
114+ expect ( testDuration ?. unit ) . toBe ( 's' )
130115 } )
131116
132117 it ( 'generates metrics for all test statuses' , ( ) => {
@@ -172,19 +157,18 @@ describe('generateMetrics', () => {
172157 const report = createReport ( [ suite ] )
173158 const metrics = generateMetrics ( report , config )
174159
175- const suiteTotals = metrics . filter (
176- ( m ) => m . metricName === 'test.suite.total'
177- )
178- expect ( suiteTotals ) . toHaveLength ( 4 )
179- expect ( suiteTotals . map ( ( m ) => m . attributes [ 'test.status' ] ) . sort ( ) ) . toEqual ( [
160+ expect ( metrics ) . toHaveLength ( 4 )
161+ expect ( metrics . map ( ( m ) => m . attributes [ 'test.status' ] ) . sort ( ) ) . toEqual ( [
180162 'error' ,
181163 'failed' ,
182164 'passed' ,
183165 'skipped'
184166 ] )
185167
186- expect ( metrics . some ( ( m ) => m . metricName === 'test.failure' ) ) . toBe ( true )
187- expect ( metrics . some ( ( m ) => m . metricName === 'test.error' ) ) . toBe ( true )
168+ expect ( metrics . every ( ( m ) => m . metricName === 'test_duration_seconds' ) ) . toBe (
169+ true
170+ )
171+ expect ( metrics . every ( ( m ) => m . metricType === 'gauge' ) ) . toBe ( true )
188172 } )
189173
190174 it ( 'handles nested suites recursively' , ( ) => {
@@ -207,12 +191,9 @@ describe('generateMetrics', () => {
207191 const report = createReport ( [ parentSuite ] )
208192 const metrics = generateMetrics ( report , config )
209193
210- const suiteNames = metrics
211- . filter ( ( m ) => m . metricName === 'test.suite.duration' )
212- . map ( ( m ) => m . attributes [ 'test.suite.name' ] )
194+ expect ( metrics ) . toHaveLength ( 1 )
213195
214- expect ( suiteNames ) . toContain ( 'ParentSuite' )
215- expect ( suiteNames ) . toContain ( 'NestedSuite' )
196+ expect ( metrics [ 0 ] ! . attributes [ 'test.suite.name' ] ) . toBe ( 'NestedSuite' )
216197 } )
217198
218199 it ( 'uses OpenTelemetry semantic conventions for attribute names' , ( ) => {
@@ -237,7 +218,10 @@ describe('generateMetrics', () => {
237218 "deployment.environment": Any<String>,
238219 "service.name": Any<String>,
239220 "service.version": Any<String>,
221+ "test.class.name": "com.example.Test",
240222 "test.framework": "junit",
223+ "test.name": "test1",
224+ "test.status": "passed",
241225 "test.suite.name": "TestSuite",
242226 "vcs.repository.name": Any<String>,
243227 "vcs.repository.ref.name": Any<String>,
@@ -282,14 +266,12 @@ describe('generateMetrics', () => {
282266 const report = createReport ( [ suiteWithDuration ] )
283267 const metrics = generateMetrics ( report , config )
284268
285- const testDuration = metrics . find ( ( m ) => m . metricName === 'test.duration' )
286- const suiteDuration = metrics . find (
287- ( m ) => m . metricName === 'test.suite.duration'
269+ const testDuration = metrics . find (
270+ ( m ) => m . metricName === 'test_duration_seconds'
288271 )
289272
290273 expect ( testDuration ?. value ) . toBe ( 2.5 )
291274 expect ( testDuration ?. unit ) . toBe ( 's' )
292- expect ( suiteDuration ?. value ) . toBe ( 2.5 )
293- expect ( suiteDuration ?. unit ) . toBe ( 's' )
275+ expect ( testDuration ?. metricType ) . toBe ( 'gauge' )
294276 } )
295277} )
0 commit comments