From 875bc9aa7712cde1e2aac90caad8f8bb6f2d59a1 Mon Sep 17 00:00:00 2001 From: Robin Bourianes Date: Fri, 21 Jun 2024 12:27:10 +0200 Subject: [PATCH] feat: add a forceXHR option on geotiff grid source to support tests --- map/common/geotiff-grid-source.js | 4 +++- test/api/map/grid-sources.test.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/map/common/geotiff-grid-source.js b/map/common/geotiff-grid-source.js index 684c69139..8eaef1b84 100644 --- a/map/common/geotiff-grid-source.js +++ b/map/common/geotiff-grid-source.js @@ -1,4 +1,5 @@ import * as GeoTIFF from 'geotiff' +import _ from 'lodash' import { unitConverters, SortOrder, GridSource, Grid1D } from './grid.js' // pack r,g,b in an uint32 @@ -56,7 +57,8 @@ export class GeoTiffGridSource extends GridSource { this.rgb = config.rgb try { - this.geotiff = await GeoTIFF.fromUrl(config.url) + // forceXHR is useful for tests because nock doesn't know how to intercept fetch + this.geotiff = await GeoTIFF.fromUrl(config.url, { forceXHR: _.get(config, 'forceXHR', false) }) } catch (error) { // fetching may fail, in this case the source // will remain in unusable state diff --git a/test/api/map/grid-sources.test.js b/test/api/map/grid-sources.test.js index 8303c1eb1..564538529 100644 --- a/test/api/map/grid-sources.test.js +++ b/test/api/map/grid-sources.test.js @@ -155,7 +155,9 @@ describe('map:grid-source', () => { describe('geotiff', () => { const geotiffOptions = { geotiff: { - url: 'http://kMap.test/data.tif' + url: 'http://kMap.test/data.tif', + // because nock doesnt know howto intercept fecth + forceXHR: true } }