66import test from '@playwright/test' ;
77import { readFileSync } from 'fs' ;
88import { FINALIZER , introducer , sixelEncode } from 'sixel' ;
9- import { ITestContext , createTestContext , openTerminal , pollFor } from '../../../test/playwright/TestUtils' ;
9+ import { ITestContext , createTestContext , openTerminal , pollFor , timeout } from '../../../test/playwright/TestUtils' ;
1010import { deepStrictEqual , ok , strictEqual } from 'assert' ;
1111
1212/**
@@ -163,43 +163,51 @@ test.describe('ImageAddon', () => {
163163 test ( 'testdata default (scrolling with VT240 cursor pos)' , async ( ) => {
164164 const dim = await getDimensions ( ) ;
165165 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
166+ await timeout ( 50 ) ;
166167 deepStrictEqual ( await getCursor ( ) , [ 0 , Math . floor ( TESTDATA . height / dim . cellHeight ) ] ) ;
167168 // moved to right by 10 cells
168169 await ctx . proxy . write ( '#' . repeat ( 10 ) + SIXEL_SEQ_0 ) ;
170+ await timeout ( 50 ) ;
169171 deepStrictEqual ( await getCursor ( ) , [ 10 , Math . floor ( TESTDATA . height / dim . cellHeight ) * 2 ] ) ;
170172 } ) ;
171173 test ( 'write testdata noScrolling' , async ( ) => {
172174 await ctx . proxy . write ( '\x1b[?80h' + SIXEL_SEQ_0 ) ;
175+ await timeout ( 50 ) ;
173176 deepStrictEqual ( await getCursor ( ) , [ 0 , 0 ] ) ;
174177 // second draw does not change anything
175178 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
179+ await timeout ( 50 ) ;
176180 deepStrictEqual ( await getCursor ( ) , [ 0 , 0 ] ) ;
177181 } ) ;
178182 test ( 'testdata cursor always at VT240 pos' , async ( ) => {
179183 const dim = await getDimensions ( ) ;
180184 // offset 0
181185 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
186+ await timeout ( 50 ) ;
182187 deepStrictEqual ( await getCursor ( ) , [ 0 , Math . floor ( TESTDATA . height / dim . cellHeight ) ] ) ;
183188 // moved to right by 10 cells
184189 await ctx . proxy . write ( '#' . repeat ( 10 ) + SIXEL_SEQ_0 ) ;
190+ await timeout ( 50 ) ;
185191 deepStrictEqual ( await getCursor ( ) , [ 10 , Math . floor ( TESTDATA . height / dim . cellHeight ) * 2 ] ) ;
186192 // moved by 30 cells (+10 prev)
187193 await ctx . proxy . write ( '#' . repeat ( 30 ) + SIXEL_SEQ_0 ) ;
194+ await timeout ( 50 ) ;
188195 deepStrictEqual ( await getCursor ( ) , [ 10 + 30 , Math . floor ( TESTDATA . height / dim . cellHeight ) * 3 ] ) ;
189196 } ) ;
190197 } ) ;
191198
192199 test . describe ( 'image lifecycle & eviction' , ( ) => {
193200 test ( 'delete image once scrolled off' , async ( ) => {
194201 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
202+ await timeout ( 50 ) ;
195203 pollFor ( ctx . page , 'window.imageAddon._storage._images.size' , 1 ) ;
196204 // scroll to scrollback + rows - 1
197205 await ctx . page . evaluate (
198206 scrollback => new Promise ( res => ( window as any ) . term . write ( '\n' . repeat ( scrollback ) , res ) ) ,
199207 ( await getScrollbackPlusRows ( ) - 1 )
200208 ) ;
201209 // wait here, as we have to make sure, that eviction did not yet occur
202- await new Promise ( r => setTimeout ( r , 100 ) ) ;
210+ await timeout ( 100 ) ;
203211 pollFor ( ctx . page , 'window.imageAddon._storage._images.size' , 1 ) ;
204212 // scroll one further should delete the image
205213 await ctx . page . evaluate ( ( ) => new Promise ( res => ( window as any ) . term . write ( '\n' , res ) ) ) ;
@@ -208,6 +216,7 @@ test.describe('ImageAddon', () => {
208216 test ( 'get storageUsage' , async ( ) => {
209217 strictEqual ( await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) , 0 ) ;
210218 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
219+ await timeout ( 50 ) ;
211220 ok ( Math . abs ( ( await ctx . page . evaluate < number > ( 'window.imageAddon.storageUsage' ) ) - 640 * 80 * 4 / 1000000 ) < 0.05 ) ;
212221 } ) ;
213222 test ( 'get/set storageLimit' , async ( ) => {
@@ -222,18 +231,19 @@ test.describe('ImageAddon', () => {
222231 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
223232 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
224233 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
225- await new Promise ( r => setTimeout ( r , 50 ) ) ;
234+ await timeout ( 100 ) ;
226235 const usage = await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) ;
227236 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
228237 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
229238 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
230239 await ctx . proxy . write ( SIXEL_SEQ_0 ) ;
231- await new Promise ( r => setTimeout ( r , 50 ) ) ;
240+ await timeout ( 100 ) ;
232241 strictEqual ( await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) , usage ) ;
233242 strictEqual ( usage as number < 1 , true ) ;
234243 } ) ;
235244 test ( 'set storageLimit removes images synchronously' , async ( ) => {
236245 await ctx . proxy . write ( SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 ) ;
246+ await timeout ( 100 ) ;
237247 const usage : number = await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) ;
238248 const newUsage : number = await ctx . page . evaluate ( 'window.imageAddon.storageLimit = 0.5; window.imageAddon.storageUsage' ) ;
239249 strictEqual ( newUsage < usage , true ) ;
@@ -242,30 +252,32 @@ test.describe('ImageAddon', () => {
242252 test ( 'clear alternate images on buffer change' , async ( ) => {
243253 strictEqual ( await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) , 0 ) ;
244254 await ctx . proxy . write ( '\x1b[?1049h' + SIXEL_SEQ_0 ) ;
255+ await timeout ( 50 ) ;
245256 ok ( Math . abs ( ( await ctx . page . evaluate < number > ( 'window.imageAddon.storageUsage' ) ) - 640 * 80 * 4 / 1000000 ) < 0.05 ) ;
246257 await ctx . proxy . write ( '\x1b[?1049l' ) ;
247258 strictEqual ( await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) , 0 ) ;
248259 } ) ;
249260 test ( 'evict tiles by in-place overwrites (only full overwrite tested)' , async ( ) => {
250- await new Promise ( r => setTimeout ( r , 50 ) ) ;
261+ await timeout ( 50 ) ;
251262 await ctx . proxy . write ( '\x1b[H' + SIXEL_SEQ_0 + '\x1b[100;100H' ) ;
263+ await timeout ( 50 ) ;
252264 let usage = await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) ;
253265 while ( usage === 0 ) {
254- await new Promise ( r => setTimeout ( r , 50 ) ) ;
266+ await timeout ( 50 ) ;
255267 usage = await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) ;
256268 }
257269 await ctx . proxy . write ( '\x1b[H' + SIXEL_SEQ_0 + '\x1b[100;100H' ) ;
258- await new Promise ( r => setTimeout ( r , 200 ) ) ; // wait some time and re-check
270+ await timeout ( 200 ) ; // wait some time and re-check
259271 strictEqual ( await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) , usage ) ;
260272 } ) ;
261273 test ( 'manual eviction on alternate buffer must not miss images' , async ( ) => {
262274 await ctx . proxy . write ( '\x1b[?1049h' ) ;
263275 await ctx . proxy . write ( SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 ) ;
264- await new Promise ( r => setTimeout ( r , 50 ) ) ;
276+ await timeout ( 100 ) ;
265277 const usage : number = await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) ;
266278 await ctx . proxy . write ( SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 ) ;
267279 await ctx . proxy . write ( SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 + SIXEL_SEQ_0 ) ;
268- await new Promise ( r => setTimeout ( r , 50 ) ) ;
280+ await timeout ( 100 ) ;
269281 const newUsage : number = await ctx . page . evaluate ( 'window.imageAddon.storageUsage' ) ;
270282 strictEqual ( newUsage , usage ) ;
271283 } ) ;
@@ -274,22 +286,27 @@ test.describe('ImageAddon', () => {
274286 test . describe ( 'IIP support - testimages' , ( ) => {
275287 test ( 'palette.png' , async ( ) => {
276288 await ctx . proxy . write ( TESTDATA_IIP [ 0 ] [ 0 ] ) ;
289+ await timeout ( 50 ) ;
277290 deepStrictEqual ( await getOrigSize ( 1 ) , TESTDATA_IIP [ 0 ] [ 1 ] ) ;
278291 } ) ;
279292 test ( 'spinfox.png' , async ( ) => {
280293 await ctx . proxy . write ( TESTDATA_IIP [ 1 ] [ 0 ] ) ;
294+ await timeout ( 50 ) ;
281295 deepStrictEqual ( await getOrigSize ( 1 ) , TESTDATA_IIP [ 1 ] [ 1 ] ) ;
282296 } ) ;
283297 test ( 'w3c gif' , async ( ) => {
284298 await ctx . proxy . write ( TESTDATA_IIP [ 2 ] [ 0 ] ) ;
299+ await timeout ( 50 ) ;
285300 deepStrictEqual ( await getOrigSize ( 1 ) , TESTDATA_IIP [ 2 ] [ 1 ] ) ;
286301 } ) ;
287302 test ( 'w3c jpeg' , async ( ) => {
288303 await ctx . proxy . write ( TESTDATA_IIP [ 3 ] [ 0 ] ) ;
304+ await timeout ( 50 ) ;
289305 deepStrictEqual ( await getOrigSize ( 1 ) , TESTDATA_IIP [ 3 ] [ 1 ] ) ;
290306 } ) ;
291307 test ( 'w3c png' , async ( ) => {
292308 await ctx . proxy . write ( TESTDATA_IIP [ 4 ] [ 0 ] ) ;
309+ await timeout ( 50 ) ;
293310 deepStrictEqual ( await getOrigSize ( 1 ) , TESTDATA_IIP [ 4 ] [ 1 ] ) ;
294311 } ) ;
295312 } ) ;
0 commit comments