Skip to content

Commit 0f9b46a

Browse files
Merge pull request #160 from sdwvit/patch-1
feat: add report json to github action outputs
2 parents 590095c + 52df07a commit 0f9b46a

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

__tests__/github/handler.test.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as core from '@actions/core'
2+
import { context } from '@actions/github'
23
import { createCheckRun } from '../../src/client/github/checks'
34
import {
45
createStatusCheck,
56
findExistingMarkedComment,
6-
handleComment
7+
handleComment,
8+
handleViewsAndComments
79
} from '../../src/github/handler'
810
import { CtrfReport, Inputs } from '../../src/types'
911
import * as githubClient from '../../src/client/github'
@@ -647,3 +649,45 @@ describe('handleComment', () => {
647649
})
648650
})
649651
})
652+
653+
describe('handleViewsAndComments', () => {
654+
const mockCore = jest.mocked(core)
655+
beforeEach(() => {
656+
jest.clearAllMocks()
657+
context.payload ||= {}
658+
mockCore.summary.stringify.mockReturnValue('Test summary')
659+
mockCore.summary.addRaw.mockImplementation(
660+
jest
661+
.requireActual<typeof core>('@actions/core')
662+
.summary.addRaw.bind(core.summary)
663+
)
664+
mockCore.summary.addEOL.mockImplementation(
665+
jest
666+
.requireActual<typeof core>('@actions/core')
667+
.summary.addEOL.bind(core.summary)
668+
)
669+
})
670+
671+
it('should create a check run with views and comments', async () => {
672+
const inputs: Inputs = {
673+
statusCheckName: 'Test Status',
674+
statusCheck: true
675+
} as Inputs
676+
677+
const report = {
678+
results: {
679+
summary: {
680+
failed: 0
681+
},
682+
tests: []
683+
}
684+
} as unknown as CtrfReport
685+
await handleViewsAndComments(inputs, report)
686+
687+
expect(mockCore.setOutput).toHaveBeenNthCalledWith(
688+
2,
689+
'report',
690+
'{"results":{"summary":{"failed":0},"tests":[]}}'
691+
)
692+
})
693+
})

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ inputs:
228228
outputs:
229229
summary:
230230
description: 'The markdown summary generated'
231+
report:
232+
description: 'The report json'
231233

232234
runs:
233235
using: 'node20'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-actions-ctrf",
3-
"version": "0.0.58",
3+
"version": "0.0.59",
44
"description": "View test results directly within your GitHub workflow summary and Pull Requests",
55
"main": "index.js",
66
"scripts": {

src/github/handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export async function handleViewsAndComments(
3636
generateViews(inputs, report)
3737

3838
core.setOutput('summary', core.summary.stringify())
39+
core.setOutput('report', JSON.stringify(report))
3940

4041
if (shouldAddCommentToPullRequest(inputs, report)) {
4142
await postOrUpdatePRComment(inputs, INVISIBLE_MARKER)

0 commit comments

Comments
 (0)