Skip to content

Commit

Permalink
geoJSON source getBounds method, move tests from unit to integration,…
Browse files Browse the repository at this point in the history
… multiple errors local
  • Loading branch information
AbelVM committed Jan 28, 2025
1 parent 8c60411 commit 0c49eda
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 46 deletions.
63 changes: 18 additions & 45 deletions test/integration/browser/browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ import type {AddressInfo} from 'net';
import type {default as MapLibreGL, Map} from '../../../dist/maplibre-gl';
import {sleep} from '../../../src/util/test/util';

import {type Actor} from '../../../src/util/actor';
import {type Dispatcher} from '../../../src/util/dispatcher';
import {GeoJSONSource, type GeoJSONSourceOptions} from '../../../src/source/geojson_source';
import {LngLatBounds} from '../../../src/geo/lng_lat_bounds';
import type {FeatureCollection} from 'geojson';

const wrapDispatcher = (dispatcher) => {
return {
getActor() {
return dispatcher as Actor;
}
} as Dispatcher;
};

const mockDispatcher = wrapDispatcher({
sendAsync() { return Promise.resolve({}); }
});

const hawkHill = {
'type': 'FeatureCollection',
'features': [{
Expand Down Expand Up @@ -56,7 +38,7 @@ const hawkHill = {
]
}
}]
} as GeoJSON.GeoJSON;
} as GeoJSON.FeatureCollection;

const testWidth = 800;
const testHeight = 600;
Expand Down Expand Up @@ -500,33 +482,24 @@ describe('Browser tests', () => {
expect(center.lng).toBeCloseTo(11.39770);
expect(center.lat).toBeCloseTo(47.29960);
});
});

describe('GeoJSONSource#getBounds', () => {
const probe = hawkHill as FeatureCollection;
test('FeatureCollection', async () => {
const source = new GeoJSONSource('id', {data: probe} as GeoJSONSourceOptions, mockDispatcher, undefined);
const testbounds = new LngLatBounds([-122.49378204345702, 37.82880236636284, -122.48339653015138, 37.83381888486939]);
const bounds = await source.getBounds();
expect(bounds).toEqual(testbounds);
});
test('Feature', async () => {
const source = new GeoJSONSource('id', {data: probe.features[0]} as GeoJSONSourceOptions, mockDispatcher, undefined);
const testbounds = new LngLatBounds([-122.49378204345702, 37.82880236636284, -122.48339653015138, 37.83381888486939]);
const bounds = await source.getBounds();
expect(bounds).toEqual(testbounds);
});
test('GeometryCollection', async () => {
const geometrycollection = {'type': 'GeometryCollection', 'geometries': [probe.features[0].geometry, probe.features[0].geometry]};
const source = new GeoJSONSource('id', {data: geometrycollection} as GeoJSONSourceOptions, mockDispatcher, undefined);
const testbounds = new LngLatBounds([-122.49378204345702, 37.82880236636284, -122.48339653015138, 37.83381888486939]);
const bounds = await source.getBounds();
expect(bounds).toEqual(testbounds);
});
test('Geometry', async () => {
const source = new GeoJSONSource('id', {data: probe.features[0].geometry} as GeoJSONSourceOptions, mockDispatcher, undefined);
const testbounds = new LngLatBounds([-122.49378204345702, 37.82880236636284, -122.48339653015138, 37.83381888486939]);
const bounds = await source.getBounds();
test('GeoJSONSource#getBounds: FeatureCollection', async () => {
const bounds = await page.evaluate(async () => {

Check failure on line 487 in test/integration/browser/browser.test.ts

View workflow job for this annotation

GitHub Actions / Integration tests (ubuntu-latest)

test/integration/browser/browser.test.ts > Browser tests > GeoJSONSource#getBounds: FeatureCollection

ReferenceError: hawkHill is not defined ❯ evaluate evaluate at /home/runner/work/maplibre-gl-js/maplibre-gl-js/test/integration/browser/browser.test.ts:415:31, <anonymous>:9:14 ❯ ExecutionContext.#evaluate node_modules/puppeteer-core/src/cdp/ExecutionContext.ts:448:13 ❯ ExecutionContext.evaluate node_modules/puppeteer-core/src/cdp/ExecutionContext.ts:291:12 ❯ IsolatedWorld.evaluate node_modules/puppeteer-core/src/cdp/IsolatedWorld.ts:196:12 ❯ CdpFrame.evaluate node_modules/puppeteer-core/src/api/Frame.ts:474:12 ❯ CdpPage.evaluate node_modules/puppeteer-core/src/api/Page.ts:2241:12 ❯ test/integration/browser/browser.test.ts:487:24
const map = new maplibregl.Map({
container: 'map',
style: 'https://demotiles.maplibre.org/style.json',
center: [10, 10],
zoom: 10
});
map.addSource('testid', {
type: 'geojson',
data: hawkHill
});
const testsource: maplibregl.GeoJSONSource = map.getSource('testid');
return testsource.getBounds();
});
const testbounds = new maplibregl.LngLatBounds([-122.49378204345702, 37.82880236636284, -122.48339653015138, 37.83381888486939]);
expect(bounds).toEqual(testbounds);
});

});
3 changes: 2 additions & 1 deletion vitest.config.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export default defineConfig({
name: 'integration',
environment: 'node',
include: [
'test/integration/**/*.test.{ts,js}',
'test/integration/browser/browser.test.ts'
//'test/integration/**/*.test.{ts,js}',
],
coverage: {
provider: 'v8',
Expand Down

0 comments on commit 0c49eda

Please sign in to comment.