@@ -19,11 +19,8 @@ type DesktopScreenshotResult = {
1919 width : number ;
2020 height : number ;
2121} ;
22- type SuccessResult = { success : boolean } ;
23- type ScreenSizeResult = { success : boolean ; width : number ; height : number } ;
2422type CursorPositionResult = { success : boolean ; x : number ; y : number } ;
2523type StreamUrlResult = { url : string } ;
26- type ErrorResult = { error : string } ;
2724
2825const skipPortExposureTests =
2926 process . env . TEST_WORKER_URL ?. endsWith ( '.workers.dev' ) ?? false ;
@@ -109,8 +106,9 @@ describe('Desktop Environment', () => {
109106 } ) ;
110107
111108 expect ( response . status ) . toBe ( 200 ) ;
112- const data = ( await response . json ( ) ) as SuccessResult ;
113- expect ( data . success ) . toBe ( true ) ;
109+ await expect ( response . json ( ) ) . resolves . toEqual (
110+ expect . objectContaining ( { success : true } )
111+ ) ;
114112 } , 15000 ) ;
115113
116114 test ( 'should type text' , async ( ) => {
@@ -122,8 +120,9 @@ describe('Desktop Environment', () => {
122120 } ) ;
123121
124122 expect ( response . status ) . toBe ( 200 ) ;
125- const data = ( await response . json ( ) ) as SuccessResult ;
126- expect ( data . success ) . toBe ( true ) ;
123+ await expect ( response . json ( ) ) . resolves . toEqual (
124+ expect . objectContaining ( { success : true } )
125+ ) ;
127126 } , 15000 ) ;
128127
129128 test ( 'should press key combination' , async ( ) => {
@@ -135,8 +134,9 @@ describe('Desktop Environment', () => {
135134 } ) ;
136135
137136 expect ( response . status ) . toBe ( 200 ) ;
138- const data = ( await response . json ( ) ) as SuccessResult ;
139- expect ( data . success ) . toBe ( true ) ;
137+ await expect ( response . json ( ) ) . resolves . toEqual (
138+ expect . objectContaining ( { success : true } )
139+ ) ;
140140 } , 15000 ) ;
141141
142142 test ( 'should return screen size matching configured resolution' , async ( ) => {
@@ -147,12 +147,9 @@ describe('Desktop Environment', () => {
147147 } ) ;
148148
149149 expect ( response . status ) . toBe ( 200 ) ;
150- const data = ( await response . json ( ) ) as ScreenSizeResult ;
151- expect ( data . success ) . toBe ( true ) ;
152- expect ( data . width ) . toBeGreaterThan ( 0 ) ;
153- expect ( data . height ) . toBeGreaterThan ( 0 ) ;
154- expect ( data . width ) . toBe ( 1024 ) ;
155- expect ( data . height ) . toBe ( 768 ) ;
150+ await expect ( response . json ( ) ) . resolves . toEqual (
151+ expect . objectContaining ( { success : true , width : 1024 , height : 768 } )
152+ ) ;
156153 } , 15000 ) ;
157154
158155 test ( 'should return valid cursor coordinates' , async ( ) => {
@@ -199,8 +196,9 @@ describe('Desktop Environment', () => {
199196 } ) ;
200197
201198 expect ( response . status ) . toBe ( 200 ) ;
202- const data = ( await response . json ( ) ) as SuccessResult ;
203- expect ( data . success ) . toBe ( true ) ;
199+ await expect ( response . json ( ) ) . resolves . toEqual (
200+ expect . objectContaining ( { success : true } )
201+ ) ;
204202
205203 const posResponse = await fetch (
206204 `${ workerUrl } /api/desktop/cursor/position` ,
@@ -231,8 +229,9 @@ describe('Desktop Environment', () => {
231229 signal : AbortSignal . timeout ( 1000 )
232230 } ) ;
233231
234- const statusData = ( await statusResponse . json ( ) ) as DesktopStatusResult ;
235- expect ( statusData . status ) . toBe ( 'active' ) ;
232+ await expect ( statusResponse . json ( ) ) . resolves . toEqual (
233+ expect . objectContaining ( { status : 'active' } )
234+ ) ;
236235
237236 await fetch ( `${ workerUrl } /api/desktop/stop` , {
238237 method : 'POST' ,
@@ -249,8 +248,9 @@ describe('Desktop Environment', () => {
249248 } ) ;
250249
251250 expect ( stopResponse . status ) . toBe ( 200 ) ;
252- const stopData = ( await stopResponse . json ( ) ) as SuccessResult ;
253- expect ( stopData . success ) . toBe ( true ) ;
251+ await expect ( stopResponse . json ( ) ) . resolves . toEqual (
252+ expect . objectContaining ( { success : true } )
253+ ) ;
254254
255255 const statusResponse = await fetch ( `${ workerUrl } /api/desktop/status` , {
256256 method : 'GET' ,
@@ -259,8 +259,9 @@ describe('Desktop Environment', () => {
259259 } ) ;
260260
261261 expect ( statusResponse . status ) . toBe ( 200 ) ;
262- const statusData = ( await statusResponse . json ( ) ) as DesktopStatusResult ;
263- expect ( statusData . status ) . toBe ( 'inactive' ) ;
262+ await expect ( statusResponse . json ( ) ) . resolves . toEqual (
263+ expect . objectContaining ( { status : 'inactive' } )
264+ ) ;
264265
265266 // Assert that attempting to make a request to a stopped instance fails.
266267 const response = await fetch ( `${ workerUrl } /api/desktop/screenshot` , {
@@ -271,7 +272,8 @@ describe('Desktop Environment', () => {
271272 } ) ;
272273
273274 expect ( response . status ) . toBeGreaterThanOrEqual ( 400 ) ;
274- const data = ( await response . json ( ) ) as ErrorResult ;
275- expect ( data . error ) . toBeDefined ( ) ;
275+ await expect ( response . json ( ) ) . resolves . toEqual (
276+ expect . objectContaining ( { error : expect . anything ( ) } )
277+ ) ;
276278 } , 15000 ) ;
277279} ) ;
0 commit comments