66 * variables following the pattern `INPUT_<INPUT_NAME>`.
77 */
88
9- import * as core from '@actions/core'
10- import * as github from '@actions/github'
9+ import { Context } from '@actions/github/lib/context'
10+ import * as actionsCore from '@actions/core'
11+ import * as actionsGitHub from '@actions/github'
12+
1113import * as index from '../src/index'
1214import * as fs from '../src/fs'
1315import * as report from '../src/report'
14- import { Context } from '@actions/github/lib/context '
16+ import * as github from '../src/github '
1517
1618// Mock the GitHub Actions core library
17- jest . spyOn ( core , 'info' ) . mockImplementation ( jest . fn ( ) )
18- jest . spyOn ( core , 'warning' ) . mockImplementation ( jest . fn ( ) )
19- jest . spyOn ( core , 'error' ) . mockImplementation ( jest . fn ( ) )
20- const debugMock = jest . spyOn ( core , 'debug' ) . mockImplementation ( jest . fn ( ) )
21- const getInputMock = jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name : string ) => inputs [ name ] || '' )
22- const setFailedMock = jest . spyOn ( core , 'setFailed' ) . mockImplementation ( jest . fn ( ) )
23- const setOutputMock = jest . spyOn ( core , 'setOutput' ) . mockImplementation ( jest . fn ( ) )
19+ jest . spyOn ( actionsCore , 'info' ) . mockImplementation ( jest . fn ( ) )
20+ jest . spyOn ( actionsCore , 'warning' ) . mockImplementation ( jest . fn ( ) )
21+ jest . spyOn ( actionsCore , 'error' ) . mockImplementation ( jest . fn ( ) )
22+ const debugMock = jest . spyOn ( actionsCore , 'debug' ) . mockImplementation ( jest . fn ( ) )
23+ const getInputMock = jest . spyOn ( actionsCore , 'getInput' ) . mockImplementation ( ( name : string ) => inputs [ name ] || '' )
24+ const setFailedMock = jest . spyOn ( actionsCore , 'setFailed' ) . mockImplementation ( jest . fn ( ) )
25+ const setOutputMock = jest . spyOn ( actionsCore , 'setOutput' ) . mockImplementation ( jest . fn ( ) )
2426
2527// Mock the fs module
2628const readFileMock = jest . spyOn ( fs , 'readFile' )
@@ -29,11 +31,14 @@ const readFileMock = jest.spyOn(fs, 'readFile')
2931const parseReportMock = jest . spyOn ( report , 'parseReport' )
3032const renderReportSummaryMock = jest . spyOn ( report , 'renderReportSummary' )
3133
34+ // Mock the github module
35+ const createIssueCommentMock = jest . spyOn ( github , 'createIssueComment' )
36+
3237// Mock the GitHub Actions context library
3338// const contextMock = jest.spyOn(github, 'context')
3439
3540// Mock the GitHub Actions Octokit instance
36- type Octokit = ReturnType < typeof github . getOctokit >
41+ type Octokit = ReturnType < typeof actionsGitHub . getOctokit >
3742
3843const octokitMock = {
3944 rest : {
@@ -48,7 +53,7 @@ const octokitMock = {
4853 }
4954} as unknown as Octokit
5055
51- const getOctokitMock = jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => octokitMock )
56+ const getOctokitMock = jest . spyOn ( actionsGitHub , 'getOctokit' ) . mockImplementation ( ( ) => octokitMock )
5257
5358// Mock the action's entrypoint
5459const runMock = jest . spyOn ( index , 'run' )
@@ -58,7 +63,7 @@ const runMock = jest.spyOn(index, 'run')
5863
5964// Shallow clone original @actions /github context
6065// @ts -expect-error missing issue and repo keys
61- const originalContext : Context = { issue : { } , ...github . context }
66+ const originalContext : Context = { issue : { } , ...actionsGitHub . context }
6267
6368const defaultContext = {
6469 eventName : 'pull_request' ,
@@ -91,7 +96,7 @@ const defaultContext = {
9196let inputs : Record < string , string > = { }
9297
9398function setContext ( context : any ) : void {
94- Object . defineProperty ( github , 'context' , { value : context , writable : true } )
99+ Object . defineProperty ( actionsGitHub , 'context' , { value : context , writable : true } )
95100}
96101
97102describe ( 'action' , ( ) => {
@@ -127,6 +132,7 @@ describe('action', () => {
127132 expect ( getInputMock ) . toHaveBeenCalledWith ( 'report-tag' )
128133 expect ( getInputMock ) . toHaveBeenCalledWith ( 'comment-title' )
129134 expect ( getInputMock ) . toHaveBeenCalledWith ( 'icon-style' )
135+ expect ( getInputMock ) . toHaveBeenCalledWith ( 'create-comment' )
130136 expect ( getInputMock ) . toHaveBeenCalledWith ( 'job-summary' )
131137 expect ( getInputMock ) . toHaveBeenCalledWith ( 'test-command' )
132138 expect ( getInputMock ) . toHaveBeenCalledWith ( 'footer' )
@@ -145,6 +151,8 @@ describe('action', () => {
145151 expect ( debugMock ) . toHaveBeenNthCalledWith ( 2 , 'Report url: (none)' )
146152 expect ( debugMock ) . toHaveBeenNthCalledWith ( 3 , 'Report tag: (none)' )
147153 expect ( debugMock ) . toHaveBeenNthCalledWith ( 4 , 'Comment title: Custom comment title' )
154+ expect ( debugMock ) . toHaveBeenNthCalledWith ( 5 , 'Creating comment? yes' )
155+ expect ( debugMock ) . toHaveBeenNthCalledWith ( 6 , 'Creating job summary? no' )
148156 } )
149157
150158 it ( 'creates an Octokit instance' , async ( ) => {
@@ -194,17 +202,44 @@ describe('action', () => {
194202
195203 it ( 'sets a summary and comment id output' , async ( ) => {
196204 inputs = {
197- 'report-file' : '__tests__/__fixtures__/report-valid.json' ,
198- 'comment-title' : 'Custom comment title'
205+ 'report-file' : '__tests__/__fixtures__/report-valid.json'
199206 }
200207
201208 await index . run ( )
202209
203210 expect ( runMock ) . toHaveReturned ( )
204- expect ( setOutputMock ) . toHaveBeenNthCalledWith ( 1 , 'summary' , expect . anything ( ) )
211+ expect ( setOutputMock ) . toHaveBeenNthCalledWith ( 1 , 'summary' , expect . stringContaining ( '# Playwright test results' ) )
205212 expect ( setOutputMock ) . toHaveBeenNthCalledWith ( 2 , 'comment-id' , expect . anything ( ) )
206213 } )
207214
215+ it ( 'creates a comment' , async ( ) => {
216+ inputs = {
217+ 'report-file' : '__tests__/__fixtures__/report-valid.json'
218+ }
219+
220+ await index . run ( )
221+
222+ expect ( runMock ) . toHaveReturned ( )
223+ expect ( createIssueCommentMock ) . toHaveBeenCalledWith (
224+ expect . anything ( ) ,
225+ expect . objectContaining ( {
226+ body : expect . stringContaining ( '# Playwright test results' )
227+ } )
228+ )
229+ } )
230+
231+ it ( 'can disable creating a comment' , async ( ) => {
232+ inputs = {
233+ 'report-file' : '__tests__/__fixtures__/report-valid.json' ,
234+ 'create-comment' : 'false'
235+ }
236+
237+ await index . run ( )
238+
239+ expect ( runMock ) . toHaveReturned ( )
240+ expect ( createIssueCommentMock ) . not . toHaveBeenCalled ( )
241+ } )
242+
208243 it ( 'sets a failed status' , async ( ) => {
209244 inputs = {
210245 'report-file' : 'file-does-not-exist.json'
0 commit comments