11import { logger } from '@aws-github-runner/aws-powertools-util' ;
22import { Context } from 'aws-lambda' ;
3- import { mocked } from 'jest-mock' ;
3+
44
55import { handle as interruptionWarningHandlerImpl } from './termination-warning' ;
66import { handle as terminationHandlerImpl } from './termination' ;
77import { interruptionWarning , termination } from './lambda' ;
88import { BidEvictedDetail , BidEvictedEvent , SpotInterruptionWarning , SpotTerminationDetail } from './types' ;
9+ import { describe , it , expect , beforeEach , beforeAll , afterEach , afterAll , vi } from 'vitest' ;
10+
911
10- jest . mock ( './termination-warning' ) ;
11- jest . mock ( './termination' ) ;
12+ vi . mock ( './termination-warning' ) ;
13+ vi . mock ( './termination' ) ;
1214
1315process . env . POWERTOOLS_METRICS_NAMESPACE = 'test' ;
1416process . env . POWERTOOLS_TRACE_ENABLED = 'true' ;
@@ -87,11 +89,11 @@ const context: Context = {
8789// Docs for testing async with jest: https://jestjs.io/docs/tutorial-async
8890describe ( 'Handle sport termination interruption warning' , ( ) => {
8991 beforeEach ( ( ) => {
90- jest . clearAllMocks ( ) ;
92+ vi . clearAllMocks ( ) ;
9193 } ) ;
9294
9395 it ( 'should not throw or log in error.' , async ( ) => {
94- const mock = mocked ( interruptionWarningHandlerImpl ) ;
96+ const mock = vi . mocked ( interruptionWarningHandlerImpl ) ;
9597 mock . mockImplementation ( ( ) => {
9698 return new Promise ( ( resolve ) => {
9799 resolve ( ) ;
@@ -101,9 +103,9 @@ describe('Handle sport termination interruption warning', () => {
101103 } ) ;
102104
103105 it ( 'should not throw only log in error in case of an exception.' , async ( ) => {
104- const logSpy = jest . spyOn ( logger , 'error' ) ;
106+ const logSpy = vi . spyOn ( logger , 'error' ) ;
105107 const error = new Error ( 'An error.' ) ;
106- const mock = mocked ( interruptionWarningHandlerImpl ) ;
108+ const mock = vi . mocked ( interruptionWarningHandlerImpl ) ;
107109 mock . mockRejectedValue ( error ) ;
108110 await expect ( interruptionWarning ( spotInstanceInterruptionEvent , context ) ) . resolves . toBeUndefined ( ) ;
109111
@@ -113,11 +115,11 @@ describe('Handle sport termination interruption warning', () => {
113115
114116describe ( 'Handle sport termination (BidEvictEvent' , ( ) => {
115117 beforeEach ( ( ) => {
116- jest . clearAllMocks ( ) ;
118+ vi . clearAllMocks ( ) ;
117119 } ) ;
118120
119121 it ( 'should not throw or log in error.' , async ( ) => {
120- const mock = mocked ( terminationHandlerImpl ) ;
122+ const mock = vi . mocked ( terminationHandlerImpl ) ;
121123 mock . mockImplementation ( ( ) => {
122124 return new Promise ( ( resolve ) => {
123125 resolve ( ) ;
@@ -127,9 +129,9 @@ describe('Handle sport termination (BidEvictEvent', () => {
127129 } ) ;
128130
129131 it ( 'should not throw only log in error in case of an exception.' , async ( ) => {
130- const logSpy = jest . spyOn ( logger , 'error' ) ;
132+ const logSpy = vi . spyOn ( logger , 'error' ) ;
131133 const error = new Error ( 'An error.' ) ;
132- const mock = mocked ( terminationHandlerImpl ) ;
134+ const mock = vi . mocked ( terminationHandlerImpl ) ;
133135 mock . mockRejectedValue ( error ) ;
134136 await expect ( termination ( bidEvictedEvent , context ) ) . resolves . toBeUndefined ( ) ;
135137
0 commit comments