@@ -6,11 +6,11 @@ import {
6
6
executeRunK6Command ,
7
7
extractTestRunId ,
8
8
fetchChecks ,
9
+ fetchTestRunSummary ,
9
10
generateK6RunCommand ,
10
11
isCloudIntegrationEnabled ,
11
12
validateTestPaths ,
12
13
} from '../src/k6helper'
13
- import { generateMarkdownSummary } from '../src/markdownRenderer'
14
14
import { TestRunUrlsMap } from '../src/types'
15
15
16
16
// Mock child_process.spawn
@@ -29,6 +29,7 @@ vi.mock('child_process', () => ({
29
29
stderr : { on : vi . fn ( ) } ,
30
30
pid : 123 ,
31
31
} ) ) ,
32
+ execSync : vi . fn ( ) . mockReturnValue ( Buffer . from ( 'k6 v0.38.0' ) ) ,
32
33
} ) )
33
34
34
35
// Mock @actions /core
@@ -248,50 +249,52 @@ describe('extractTestRunId', () => {
248
249
} )
249
250
} )
250
251
251
- describe ( 'generateMarkdownSummary' , ( ) => {
252
- it ( 'should return a default message for null metrics' , ( ) => {
253
- expect ( generateMarkdownSummary ( null , null ) ) . toBe (
254
- 'No metrics data available.'
255
- )
256
- } )
257
-
258
- it ( 'should return a default message for undefined metrics' , ( ) => {
259
- expect ( generateMarkdownSummary ( undefined , null ) ) . toBe (
260
- 'No metrics data available.'
261
- )
252
+ describe ( 'fetchTestRunSummary' , ( ) => {
253
+ beforeEach ( ( ) => {
254
+ vi . resetAllMocks ( )
262
255
} )
263
256
264
- it ( 'should return a default message for empty metrics' , ( ) => {
265
- const emptyMetrics = {
266
- http_metric_summary : null ,
267
- ws_metric_summary : null ,
268
- grpc_metric_summary : null ,
269
- checks_metric_summary : null ,
270
- thresholds_summary : null ,
271
- browser_metric_summary : null ,
257
+ it ( 'should return test run summary when API request succeeds' , async ( ) => {
258
+ // Mock response from the API
259
+ const mockTestRunSummary = {
260
+ metrics_summary : {
261
+ http_metric_summary : {
262
+ requests : 100 ,
263
+ failed_requests : 5 ,
264
+ } ,
265
+ checks_metric_summary : {
266
+ total : 200 ,
267
+ successes : 190 ,
268
+ } ,
269
+ } ,
270
+ baseline_test_run_details : null ,
272
271
}
273
272
274
- expect ( generateMarkdownSummary ( emptyMetrics , null ) ) . toBe (
275
- 'No metrics data available.'
273
+ // Mock the apiRequest function to return our mock response
274
+ vi . mocked ( apiRequest ) . mockResolvedValueOnce ( mockTestRunSummary )
275
+
276
+ // Call the function
277
+ const result = await fetchTestRunSummary ( '1234' )
278
+
279
+ // Verify the result
280
+ expect ( result ) . toEqual ( mockTestRunSummary )
281
+ expect ( apiRequest ) . toHaveBeenCalledWith (
282
+ expect . stringContaining ( '/test_runs(1234)/result_summary' )
276
283
)
277
284
} )
278
285
279
- it ( 'should display checks summary when present' , ( ) => {
280
- const metrics = {
281
- http_metric_summary : null ,
282
- ws_metric_summary : null ,
283
- grpc_metric_summary : null ,
284
- checks_metric_summary : {
285
- total : 10 ,
286
- successes : 8 ,
287
- } ,
288
- thresholds_summary : null ,
289
- browser_metric_summary : null ,
290
- }
286
+ it ( 'should return undefined when API request fails' , async ( ) => {
287
+ // Mock the apiRequest function to return undefined (API failure)
288
+ vi . mocked ( apiRequest ) . mockResolvedValueOnce ( undefined )
291
289
292
- const result = generateMarkdownSummary ( metrics , null )
290
+ // Call the function
291
+ const result = await fetchTestRunSummary ( '1234' )
293
292
294
- expect ( result ) . toContain ( 'checks were not successful' )
293
+ // Verify the result
294
+ expect ( result ) . toBeUndefined ( )
295
+ expect ( apiRequest ) . toHaveBeenCalledWith (
296
+ expect . stringContaining ( '/test_runs(1234)/result_summary' )
297
+ )
295
298
} )
296
299
} )
297
300
0 commit comments