11import { logger } from '@aws-github-runner/aws-powertools-util' ;
22import { APIGatewayEvent , Context } from 'aws-lambda' ;
3- import { mocked } from 'jest-mock' ;
3+
44import { WorkflowJobEvent } from '@octokit/webhooks-types' ;
55
66import { dispatchToRunners , eventBridgeWebhook , directWebhook } from './lambda' ;
@@ -9,6 +9,8 @@ import ValidationError from './ValidationError';
99import { getParameter } from '@aws-github-runner/aws-ssm-util' ;
1010import { dispatch } from './runners/dispatch' ;
1111import { EventWrapper } from './types' ;
12+ import { describe , it , expect , beforeEach , beforeAll , afterEach , afterAll , vi } from 'vitest' ;
13+
1214
1315const event : APIGatewayEvent = {
1416 body : JSON . stringify ( '' ) ,
@@ -76,22 +78,22 @@ const context: Context = {
7678 } ,
7779} ;
7880
79- jest . mock ( './runners/dispatch' ) ;
80- jest . mock ( './webhook' ) ;
81- jest . mock ( '@aws-github-runner/aws-ssm-util' ) ;
81+ vi . mock ( './runners/dispatch' ) ;
82+ vi . mock ( './webhook' ) ;
83+ vi . mock ( '@aws-github-runner/aws-ssm-util' ) ;
8284
8385describe ( 'Test webhook lambda wrapper.' , ( ) => {
8486 beforeEach ( ( ) => {
8587 // We mock all SSM request to resolve to a non empty array. Since we mock all implemeantions
8688 // relying on the config opbject that is enought to test the handlers.
87- const mockedGet = mocked ( getParameter ) ;
89+ const mockedGet = vi . mocked ( getParameter ) ;
8890 mockedGet . mockResolvedValue ( '["abc"]' ) ;
89- jest . clearAllMocks ( ) ;
91+ vi . clearAllMocks ( ) ;
9092 } ) ;
9193
9294 describe ( 'Test webhook lambda wrapper.' , ( ) => {
9395 it ( 'Happy flow, resolve.' , async ( ) => {
94- const mock = mocked ( publishForRunners ) ;
96+ const mock = vi . mocked ( publishForRunners ) ;
9597 mock . mockImplementation ( ( ) => {
9698 return new Promise ( ( resolve ) => {
9799 resolve ( { body : 'test' , statusCode : 200 } ) ;
@@ -103,16 +105,16 @@ describe('Test webhook lambda wrapper.', () => {
103105 } ) ;
104106
105107 it ( 'An expected error, resolve.' , async ( ) => {
106- const mock = mocked ( publishForRunners ) ;
108+ const mock = vi . mocked ( publishForRunners ) ;
107109 mock . mockRejectedValue ( new ValidationError ( 400 , 'some error' ) ) ;
108110
109111 const result = await directWebhook ( event , context ) ;
110112 expect ( result ) . toMatchObject ( { body : 'some error' , statusCode : 400 } ) ;
111113 } ) ;
112114
113115 it ( 'Errors are not thrown.' , async ( ) => {
114- const mock = mocked ( publishForRunners ) ;
115- const logSpy = jest . spyOn ( logger , 'error' ) ;
116+ const mock = vi . mocked ( publishForRunners ) ;
117+ const logSpy = vi . spyOn ( logger , 'error' ) ;
116118 mock . mockRejectedValue ( new Error ( 'some error' ) ) ;
117119 const result = await directWebhook ( event , context ) ;
118120 expect ( result ) . toMatchObject ( { body : 'Check the Lambda logs for the error details.' , statusCode : 500 } ) ;
@@ -126,7 +128,7 @@ describe('Test webhook lambda wrapper.', () => {
126128 } ) ;
127129
128130 it ( 'Happy flow, resolve.' , async ( ) => {
129- const mock = mocked ( publishOnEventBridge ) ;
131+ const mock = vi . mocked ( publishOnEventBridge ) ;
130132 mock . mockImplementation ( ( ) => {
131133 return new Promise ( ( resolve ) => {
132134 resolve ( { body : 'test' , statusCode : 200 } ) ;
@@ -138,7 +140,7 @@ describe('Test webhook lambda wrapper.', () => {
138140 } ) ;
139141
140142 it ( 'Reject events .' , async ( ) => {
141- const mock = mocked ( publishOnEventBridge ) ;
143+ const mock = vi . mocked ( publishOnEventBridge ) ;
142144 mock . mockRejectedValue ( new Error ( 'some error' ) ) ;
143145
144146 mock . mockRejectedValue ( new ValidationError ( 400 , 'some error' ) ) ;
@@ -148,8 +150,8 @@ describe('Test webhook lambda wrapper.', () => {
148150 } ) ;
149151
150152 it ( 'Errors are not thrown.' , async ( ) => {
151- const mock = mocked ( publishOnEventBridge ) ;
152- const logSpy = jest . spyOn ( logger , 'error' ) ;
153+ const mock = vi . mocked ( publishOnEventBridge ) ;
154+ const logSpy = vi . spyOn ( logger , 'error' ) ;
153155 mock . mockRejectedValue ( new Error ( 'some error' ) ) ;
154156 const result = await eventBridgeWebhook ( event , context ) ;
155157 expect ( result ) . toMatchObject ( { body : 'Check the Lambda logs for the error details.' , statusCode : 500 } ) ;
@@ -159,7 +161,7 @@ describe('Test webhook lambda wrapper.', () => {
159161
160162 describe ( 'Lambda dispatchToRunners.' , ( ) => {
161163 it ( 'Happy flow, resolve.' , async ( ) => {
162- const mock = mocked ( dispatch ) ;
164+ const mock = vi . mocked ( dispatch ) ;
163165 mock . mockImplementation ( ( ) => {
164166 return new Promise ( ( resolve ) => {
165167 resolve ( { body : 'test' , statusCode : 200 } ) ;
@@ -174,7 +176,7 @@ describe('Test webhook lambda wrapper.', () => {
174176 } ) ;
175177
176178 it ( 'Rejects non workflow_job events.' , async ( ) => {
177- const mock = mocked ( dispatch ) ;
179+ const mock = vi . mocked ( dispatch ) ;
178180 mock . mockImplementation ( ( ) => {
179181 return new Promise ( ( resolve ) => {
180182 resolve ( { body : 'test' , statusCode : 200 } ) ;
@@ -191,7 +193,7 @@ describe('Test webhook lambda wrapper.', () => {
191193 } ) ;
192194
193195 it ( 'Rejects any event causing an error.' , async ( ) => {
194- const mock = mocked ( dispatch ) ;
196+ const mock = vi . mocked ( dispatch ) ;
195197 mock . mockRejectedValue ( new Error ( 'some error' ) ) ;
196198
197199 const testEvent = {
0 commit comments