Skip to content

Commit

Permalink
feat: add a forceXHR option on geotiff grid source to support tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Bourianes committed Jun 21, 2024
1 parent 5bc07b2 commit 875bc9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion map/common/geotiff-grid-source.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/api/map/grid-sources.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 875bc9a

Please sign in to comment.