11import * as core from '@actions/core' ;
2- import { Context } from '@actions/github/lib/context' ;
3- import { GitHub } from '@actions/github/lib/utils' ;
2+ import type { Context } from '@actions/github/lib/context' ;
3+ import type { GitHub } from '@actions/github/lib/utils' ;
44import { Comments } from '../src/comment' ;
55
66jest . spyOn ( core , 'debug' ) . mockImplementation ( ( ) => { } ) ;
@@ -12,6 +12,8 @@ const issues = { createComment, updateComment, listComments };
1212
1313const rest = { issues } ;
1414const octokit = { rest } as unknown as InstanceType < typeof GitHub > ;
15+ let timestamp = '' ;
16+
1517const context : Context = {
1618 sha : 'some-sha' ,
1719 payload : {
@@ -63,6 +65,11 @@ const commentDataWithUnMatchedTag = {
6365beforeEach ( ( ) => {
6466 createComment . mockClear ( ) ;
6567 updateComment . mockClear ( ) ;
68+ jest . useFakeTimers ( {
69+ now : new Date ( '2021-02-26T22:42:16.652Z' ) ,
70+ advanceTimers : true ,
71+ } ) ;
72+ timestamp = new Date ( ) . toISOString ( ) ;
6673} ) ;
6774
6875describe ( 'comments' , ( ) => {
@@ -94,14 +101,14 @@ describe('comments', () => {
94101 `<!-- cdk diff action with hash ${ hash } -->` ,
95102 'message' ,
96103 '' ,
97- `_Generated for commit ${ context . payload . pull_request ?. head . sha } _` ,
104+ `_Generated for commit ${ context . payload . pull_request ?. head . sha } at ${ timestamp } _` ,
98105 ] . join ( '\n' ) ,
99106 comment_id : 1 ,
100107 } ) ;
101108 } ) ;
102109
103110 test ( 'create comment' , async ( ) => {
104- updateComment . mockResolvedValue ( { } ) ;
111+ createComment . mockResolvedValue ( { } ) ;
105112 const comments = new Comments ( octokit , context ) ;
106113 expect ( comments . createComment ( hash , [ 'message' ] ) ) . resolves ;
107114 expect ( createComment ) . toHaveBeenCalledWith ( {
@@ -110,7 +117,7 @@ describe('comments', () => {
110117 `<!-- cdk diff action with hash ${ hash } -->` ,
111118 'message' ,
112119 '' ,
113- `_Generated for commit ${ context . payload . pull_request ?. head . sha } _` ,
120+ `_Generated for commit ${ context . payload . pull_request ?. head . sha } at ${ timestamp } _` ,
114121 ] . join ( '\n' ) ,
115122 issue_number : context . payload . pull_request ?. number ,
116123 } ) ;
0 commit comments