@@ -42,6 +42,8 @@ import {
4242 KEY_ACTION_ROTATE ,
4343 SINGLE_CLICK_DELAY ,
4444 DEFAULT_OPACITY ,
45+ DEFAULT_IMAGE_LOAD_TIMEOUT ,
46+ IMAGE_LOAD_ERROR ,
4547} from '../src/constants' ;
4648
4749import { toRgba , isNormFloatArray } from '../src/utils' ;
@@ -196,17 +198,25 @@ test('createScatterplot({ cameraTarget, cameraDistance, cameraRotation, cameraVi
196198test ( 'createTextureFromUrl()' , async ( t ) => {
197199 const regl = createRegl ( createCanvas ( ) ) ;
198200
199- const texture = await createTextureFromUrl (
200- regl ,
201- 'https://picsum.photos/300/200/' ,
202- true
203- ) ;
201+ try {
202+ const texture = await createTextureFromUrl (
203+ regl ,
204+ 'https://picsum.photos/300/200/' ,
205+ true
206+ ) ;
204207
205- t . equal (
206- texture . _reglType , // eslint-disable-line no-underscore-dangle
207- 'texture2d' ,
208- 'texture should be a Regl texture object'
209- ) ;
208+ t . equal (
209+ texture . _reglType , // eslint-disable-line no-underscore-dangle
210+ 'texture2d' ,
211+ 'texture should be a Regl texture object'
212+ ) ;
213+ } catch ( e ) {
214+ if ( e . message === IMAGE_LOAD_ERROR ) {
215+ t . skip ( 'Skipping because image loading timed out' ) ;
216+ } else {
217+ t . fail ( 'Failed to load image from URL' ) ;
218+ }
219+ }
210220} ) ;
211221
212222test ( 'createRenderer()' , ( t ) => {
@@ -362,50 +372,76 @@ test('set({ backgroundImage })', async (t) => {
362372 const regl = createRegl ( canvas ) ;
363373 const scatterplot = createScatterplot ( { canvas, regl } ) ;
364374
365- let backgroundImage = await createTextureFromUrl (
366- regl ,
367- 'https://picsum.photos/300/200/'
368- ) ;
369-
370- scatterplot . set ( { backgroundImage } ) ;
371-
372- t . equal (
373- scatterplot . get ( 'backgroundImage' ) ,
374- backgroundImage ,
375- 'background image should be a Regl texture'
376- ) ;
375+ try {
376+ const backgroundImage = await createTextureFromUrl (
377+ regl ,
378+ 'https://picsum.photos/300/200/'
379+ ) ;
377380
378- backgroundImage = await scatterplot . createTextureFromUrl (
379- 'https://picsum.photos/300/200/'
380- ) ;
381+ scatterplot . set ( { backgroundImage } ) ;
381382
382- scatterplot . set ( { backgroundImage } ) ;
383+ t . equal (
384+ scatterplot . get ( 'backgroundImage' ) ,
385+ backgroundImage ,
386+ 'background image should be a Regl texture'
387+ ) ;
388+ } catch ( e ) {
389+ if ( e . message === IMAGE_LOAD_ERROR ) {
390+ t . skip ( `Failed to load image from URL: ${ e . message } ` ) ;
391+ } else {
392+ t . fail ( 'Could not create background image from URL' ) ;
393+ }
394+ }
383395
384- t . equal (
385- scatterplot . get ( 'backgroundImage' ) ,
386- backgroundImage ,
387- 'background image should be a Regl texture'
388- ) ;
396+ try {
397+ const backgroundImage = await scatterplot . createTextureFromUrl (
398+ 'https://picsum.photos/300/200/'
399+ ) ;
389400
390- scatterplot . set ( { backgroundImage : null } ) ;
401+ scatterplot . set ( { backgroundImage } ) ;
391402
392- t . equal (
393- scatterplot . get ( 'backgroundImage' ) ,
394- null ,
395- 'background image should be nullifyable '
396- ) ;
403+ t . equal (
404+ scatterplot . get ( 'backgroundImage' ) ,
405+ backgroundImage ,
406+ 'background image should be a Regl texture '
407+ ) ;
397408
398- scatterplot . set ( { backgroundImage : 'https://picsum.photos/300/200/' } ) ;
409+ scatterplot . set ( { backgroundImage : null } ) ;
399410
400- await new Promise ( ( resolve ) => {
401- scatterplot . subscribe ( 'backgroundImageReady' , resolve , 1 ) ;
402- } ) ;
411+ t . equal (
412+ scatterplot . get ( 'backgroundImage' ) ,
413+ null ,
414+ 'background image should be nullifyable'
415+ ) ;
416+ } catch ( e ) {
417+ if ( e . message === IMAGE_LOAD_ERROR ) {
418+ t . skip ( `Failed to load image from URL: ${ e . message } ` ) ;
419+ } else {
420+ t . fail ( 'Could not create background image from URL' ) ;
421+ }
422+ }
423+
424+ try {
425+ await new Promise ( ( resolve , reject ) => {
426+ scatterplot . subscribe ( 'backgroundImageReady' , resolve , 1 ) ;
427+ scatterplot . set ( { backgroundImage : 'https://picsum.photos/300/200/' } ) ;
428+ setTimeout ( ( ) => {
429+ reject ( new Error ( IMAGE_LOAD_ERROR ) ) ;
430+ } , DEFAULT_IMAGE_LOAD_TIMEOUT ) ;
431+ } ) ;
403432
404- t . equal (
405- scatterplot . get ( 'backgroundImage' ) . width ,
406- 300 ,
407- 'background image should be loaded by scatterplot'
408- ) ;
433+ t . equal (
434+ scatterplot . get ( 'backgroundImage' ) . width ,
435+ 300 ,
436+ 'background image should be loaded by scatterplot'
437+ ) ;
438+ } catch ( e ) {
439+ if ( e . message === IMAGE_LOAD_ERROR ) {
440+ t . skip ( `Failed to load image from URL: ${ e . message } ` ) ;
441+ } else {
442+ t . fail ( 'Could not create background image from URL' ) ;
443+ }
444+ }
409445
410446 // Base64 image
411447 scatterplot . set ( {
0 commit comments