maplibre-gl 6.1.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/readme.md +0 -2
- package/dist/maplibre-gl-dev.mjs +179 -190
- package/dist/maplibre-gl-dev.mjs.map +1 -1
- package/dist/maplibre-gl-shared-dev.mjs +869 -825
- package/dist/maplibre-gl-shared-dev.mjs.map +1 -1
- package/dist/maplibre-gl-shared.mjs +2 -2
- package/dist/maplibre-gl-shared.mjs.map +1 -1
- package/dist/maplibre-gl-worker-dev.mjs +14 -12
- package/dist/maplibre-gl-worker-dev.mjs.map +1 -1
- package/dist/maplibre-gl-worker.mjs +2 -2
- package/dist/maplibre-gl-worker.mjs.map +1 -1
- package/dist/maplibre-gl.css +1 -1
- package/dist/maplibre-gl.d.ts +24 -6
- package/dist/maplibre-gl.mjs +13 -13
- package/dist/maplibre-gl.mjs.map +1 -1
- package/package.json +10 -13
- package/src/data/bucket/fill_extrusion_bucket.test.ts +22 -0
- package/src/data/bucket/fill_extrusion_bucket.ts +16 -4
- package/src/data/bucket/round_polygon_corners.test.ts +159 -0
- package/src/data/bucket/round_polygon_corners.ts +121 -0
- package/src/data/bucket/symbol_bucket.test.ts +1 -1
- package/src/data/dem_data.test.ts +23 -23
- package/src/data/feature_position_map.test.ts +1 -1
- package/src/data/segment.test.ts +14 -14
- package/src/geo/bounds.test.ts +4 -4
- package/src/geo/lng_lat_bounds.test.ts +1 -1
- package/src/geo/projection/mercator_transform.test.ts +1 -1
- package/src/geo/projection/mercator_utils.test.ts +8 -8
- package/src/index.test.ts +7 -12
- package/src/render/glyph_manager.test.ts +6 -22
- package/src/render/painter.test.ts +2 -0
- package/src/render/painter.ts +7 -5
- package/src/render/subdivision.test.ts +22 -22
- package/src/render/terrain.test.ts +68 -34
- package/src/render/terrain.ts +69 -26
- package/src/source/canvas_source.test.ts +1 -1
- package/src/source/geojson_source.test.ts +5 -4
- package/src/source/geojson_source_diff.test.ts +2 -2
- package/src/source/geojson_worker_source.test.ts +9 -5
- package/src/source/image_source.test.ts +0 -3
- package/src/source/raster_dem_tile_source.test.ts +2 -2
- package/src/source/raster_tile_source.test.ts +15 -9
- package/src/source/rtl_text_plugin_main_thread.test.ts +14 -14
- package/src/source/source.test.ts +8 -8
- package/src/source/vector_tile_source.test.ts +1 -1
- package/src/source/vector_tile_worker_source.test.ts +7 -5
- package/src/source/worker.test.ts +1 -1
- package/src/source/worker_tile.test.ts +4 -2
- package/src/style/load_glyph_range.test.ts +8 -8
- package/src/style/load_sprite.test.ts +1 -1
- package/src/style/style.test.ts +36 -34
- package/src/style/style_layer/color_relief_style_layer.test.ts +1 -1
- package/src/style/style_layer/fill_extrusion_style_layer.ts +6 -3
- package/src/style/style_layer/raster_style_layer.test.ts +2 -2
- package/src/style/style_layer.test.ts +3 -50
- package/src/symbol/collision_index.test.ts +1 -1
- package/src/symbol/grid_index.test.ts +1 -1
- package/src/tile/terrain_tile_manager.test.ts +2 -2
- package/src/tile/tile_id.test.ts +5 -5
- package/src/tile/tile_manager.test.ts +85 -72
- package/src/tile/tile_manager_in_view_tiles.test.ts +2 -2
- package/src/ui/camera.test.ts +137 -134
- package/src/ui/control/geolocate_control.test.ts +6 -29
- package/src/ui/handler/dblclick_zoom.test.ts +2 -2
- package/src/ui/handler/scroll_zoom.test.ts +2 -0
- package/src/ui/handler_manager.test.ts +7 -7
- package/src/ui/hash.test.ts +1 -0
- package/src/ui/map.ts +28 -18
- package/src/ui/map_tests/map_basic.test.ts +11 -23
- package/src/ui/map_tests/map_calculate_camera_options.test.ts +6 -6
- package/src/ui/map_tests/map_events.test.ts +5 -5
- package/src/ui/map_tests/map_global_state.test.ts +3 -3
- package/src/ui/map_tests/map_images.test.ts +3 -3
- package/src/ui/map_tests/map_is_moving.test.ts +1 -1
- package/src/ui/map_tests/map_is_rotating.test.ts +1 -1
- package/src/ui/map_tests/map_layer.test.ts +2 -1
- package/src/ui/map_tests/map_options.test.ts +1 -5
- package/src/ui/map_tests/map_pitch.test.ts +6 -6
- package/src/ui/map_tests/map_refresh_tiles.test.ts +2 -2
- package/src/ui/map_tests/map_render.test.ts +1 -1
- package/src/ui/map_tests/map_set_lod_params.test.ts +1 -1
- package/src/ui/map_tests/map_style.test.ts +9 -1
- package/src/ui/map_tests/map_terrain.test.ts +20 -0
- package/src/ui/map_tests/map_zoom.test.ts +15 -15
- package/src/ui/marker.test.ts +7 -13
- package/src/ui/popup.test.ts +3 -3
- package/src/util/actor.test.ts +6 -6
- package/src/util/ajax.test.ts +27 -39
- package/src/util/browser.test.ts +7 -9
- package/src/util/create_tile_mesh.test.ts +2 -2
- package/src/util/dispatcher.test.ts +1 -1
- package/src/util/evented.test.ts +4 -1
- package/src/util/fast_maths.test.ts +4 -4
- package/src/util/image_request.test.ts +6 -4
- package/src/util/struct_array.test.ts +2 -2
- package/src/util/task_queue.test.ts +1 -1
- package/src/util/test/util.ts +1 -0
- package/src/util/time_control.test.ts +2 -2
- package/src/util/transferable_grid_index.test.ts +1 -1
- package/src/util/util.test.ts +27 -13
- package/src/util/verticalize_punctuation.test.ts +4 -4
- package/src/util/web_worker_transfer.test.ts +5 -5
- package/src/webgl/draw/draw_custom.test.ts +13 -13
- package/src/webgl/draw/draw_debug.test.ts +1 -1
- package/src/webgl/draw/draw_fill.test.ts +12 -12
- package/src/webgl/draw/draw_symbol.test.ts +16 -16
- package/src/webgl/program.ts +2 -0
- package/src/webgl/render_to_texture.test.ts +5 -5
- package/src/webgl/state.test.ts +1 -1
- package/src/webgl/texture.test.ts +3 -3
- package/src/webgl/vertex_buffer.test.ts +1 -1
- package/build/rolldown_plugins.ts +0 -18
|
@@ -32,7 +32,7 @@ test('ignore minZooms over maxZoom', () => {
|
|
|
32
32
|
const map = createMap({zoom: 2, maxZoom: 5});
|
|
33
33
|
expect(() => {
|
|
34
34
|
map.setMinZoom(6);
|
|
35
|
-
}).toThrow();
|
|
35
|
+
}).toThrow('minZoom must be between -2 and the current maxZoom, inclusive');
|
|
36
36
|
map.setZoom(0);
|
|
37
37
|
expect(map.getZoom()).toBe(0);
|
|
38
38
|
});
|
|
@@ -62,7 +62,7 @@ test('ignore maxZooms over minZoom', () => {
|
|
|
62
62
|
const map = createMap({minZoom: 5});
|
|
63
63
|
expect(() => {
|
|
64
64
|
map.setMaxZoom(4);
|
|
65
|
-
}).toThrow();
|
|
65
|
+
}).toThrow('maxZoom must be greater than the current minZoom');
|
|
66
66
|
map.setZoom(5);
|
|
67
67
|
expect(map.getZoom()).toBe(5);
|
|
68
68
|
});
|
|
@@ -102,16 +102,16 @@ test('transformCameraUpdate is called after changing min or max zoom', async ()
|
|
|
102
102
|
map.setMaxZoom(18);
|
|
103
103
|
map.setZoom(18);
|
|
104
104
|
await map.once('style.load');
|
|
105
|
-
expect(map.getZoom()).
|
|
106
|
-
expect(map.getMinZoom()).
|
|
107
|
-
expect(map.getMaxZoom()).
|
|
105
|
+
expect(map.getZoom()).toBe(18);
|
|
106
|
+
expect(map.getMinZoom()).toBe(5);
|
|
107
|
+
expect(map.getMaxZoom()).toBe(18);
|
|
108
108
|
const transformCameraUpdate = vi.fn(t => t);
|
|
109
109
|
map.setTransformCameraUpdate(transformCameraUpdate);
|
|
110
110
|
|
|
111
111
|
map.setMaxZoom(16);
|
|
112
|
-
expect(map.getZoom()).
|
|
113
|
-
expect(map.getMinZoom()).
|
|
114
|
-
expect(map.getMaxZoom()).
|
|
112
|
+
expect(map.getZoom()).toBe(16);
|
|
113
|
+
expect(map.getMinZoom()).toBe(5);
|
|
114
|
+
expect(map.getMaxZoom()).toBe(16);
|
|
115
115
|
expect(transformCameraUpdate.mock.calls[0][0]).toMatchObject({
|
|
116
116
|
zoom: 16,
|
|
117
117
|
minZoom: 5,
|
|
@@ -127,9 +127,9 @@ test('transformCameraUpdate is called after changing min or max zoom', async ()
|
|
|
127
127
|
|
|
128
128
|
map.setMinZoom(6);
|
|
129
129
|
map.setTransformCameraUpdate(transformCameraUpdate);
|
|
130
|
-
expect(map.getZoom()).
|
|
131
|
-
expect(map.getMinZoom()).
|
|
132
|
-
expect(map.getMaxZoom()).
|
|
130
|
+
expect(map.getZoom()).toBe(6);
|
|
131
|
+
expect(map.getMinZoom()).toBe(6);
|
|
132
|
+
expect(map.getMaxZoom()).toBe(16);
|
|
133
133
|
expect(transformCameraUpdate.mock.calls[2][0]).toMatchObject({
|
|
134
134
|
zoom: 6,
|
|
135
135
|
minZoom: 6,
|
|
@@ -147,8 +147,8 @@ test('fire move and zoom events when zoom is changed due to minZoom change', ()
|
|
|
147
147
|
map.on('zoom', handleEvent);
|
|
148
148
|
map.on('zoomend', handleEvent);
|
|
149
149
|
map.setMinZoom(11);
|
|
150
|
-
expect(map.getZoom()).
|
|
151
|
-
expect(map.getMinZoom()).
|
|
150
|
+
expect(map.getZoom()).toBe(11);
|
|
151
|
+
expect(map.getMinZoom()).toBe(11);
|
|
152
152
|
expect(handleEvent).toHaveBeenCalledTimes(6);
|
|
153
153
|
});
|
|
154
154
|
|
|
@@ -162,7 +162,7 @@ test('fire move and zoom events when zoom is changed due to maxZoom change', ()
|
|
|
162
162
|
map.on('zoom', handleEvent);
|
|
163
163
|
map.on('zoomend', handleEvent);
|
|
164
164
|
map.setMaxZoom(10);
|
|
165
|
-
expect(map.getZoom()).
|
|
166
|
-
expect(map.getMaxZoom()).
|
|
165
|
+
expect(map.getZoom()).toBe(10);
|
|
166
|
+
expect(map.getMaxZoom()).toBe(10);
|
|
167
167
|
expect(handleEvent).toHaveBeenCalledTimes(6);
|
|
168
168
|
});
|
package/src/ui/marker.test.ts
CHANGED
|
@@ -35,7 +35,7 @@ describe('marker', () => {
|
|
|
35
35
|
|
|
36
36
|
test('Marker uses a default marker element with custom color', () => {
|
|
37
37
|
const marker = new Marker({color: '#123456'});
|
|
38
|
-
expect(marker.getElement().innerHTML.
|
|
38
|
+
expect(marker.getElement().innerHTML).toContain('#123456');
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
test('Marker uses a default marker element with custom scale', () => {
|
|
@@ -53,22 +53,16 @@ describe('marker', () => {
|
|
|
53
53
|
.addTo(map);
|
|
54
54
|
|
|
55
55
|
// initial dimensions of svg element
|
|
56
|
-
expect(
|
|
57
|
-
|
|
58
|
-
).toBeTruthy();
|
|
59
|
-
expect(defaultMarker.getElement().children[0].getAttribute('width').includes('27')).toBeTruthy();
|
|
56
|
+
expect(defaultMarker.getElement().children[0].getAttribute('height')).toContain('41');
|
|
57
|
+
expect(defaultMarker.getElement().children[0].getAttribute('width')).toContain('27');
|
|
60
58
|
|
|
61
59
|
// (41 * 0.8) = 32.8, (27 * 0.8) = 21.6
|
|
62
|
-
expect(
|
|
63
|
-
|
|
64
|
-
).toBeTruthy();
|
|
65
|
-
expect(
|
|
66
|
-
smallerMarker.getElement().children[0].getAttribute('width').includes('21.6')
|
|
67
|
-
).toBeTruthy();
|
|
60
|
+
expect(smallerMarker.getElement().children[0].getAttribute('height')).toContain('32.8');
|
|
61
|
+
expect(smallerMarker.getElement().children[0].getAttribute('width')).toContain('21.6');
|
|
68
62
|
|
|
69
63
|
// (41 * 2) = 82, (27 * 2) = 54
|
|
70
|
-
expect(largerMarker.getElement().children[0].getAttribute('height').
|
|
71
|
-
expect(largerMarker.getElement().children[0].getAttribute('width').
|
|
64
|
+
expect(largerMarker.getElement().children[0].getAttribute('height')).toContain('82');
|
|
65
|
+
expect(largerMarker.getElement().children[0].getAttribute('width')).toContain('54');
|
|
72
66
|
|
|
73
67
|
});
|
|
74
68
|
|
package/src/ui/popup.test.ts
CHANGED
|
@@ -333,7 +333,7 @@ describe('popup', () => {
|
|
|
333
333
|
expect(popup._pos).toEqual(map.project([5, 0]));
|
|
334
334
|
});
|
|
335
335
|
|
|
336
|
-
test('Popup wraps position after map move if it would otherwise go offscreen (
|
|
336
|
+
test('Popup wraps position after map move if it would otherwise go offscreen (left)', () => {
|
|
337
337
|
const map = createMap({width: 1024}); // longitude bounds: [-360, 360]
|
|
338
338
|
|
|
339
339
|
const popup = new Popup()
|
|
@@ -613,7 +613,7 @@ describe('popup', () => {
|
|
|
613
613
|
).toContain('maplibregl-popup-track-pointer');
|
|
614
614
|
});
|
|
615
615
|
|
|
616
|
-
test('Pointer-tracked popup with content set later is tagged with right class
|
|
616
|
+
test('Pointer-tracked popup with content set later is tagged with right class', () => {
|
|
617
617
|
const map = createMap();
|
|
618
618
|
const popup = new Popup()
|
|
619
619
|
.trackPointer()
|
|
@@ -626,7 +626,7 @@ describe('popup', () => {
|
|
|
626
626
|
).toContain('maplibregl-popup-track-pointer');
|
|
627
627
|
});
|
|
628
628
|
|
|
629
|
-
test('Pointer-tracked popup that is set afterwards is tagged with right class
|
|
629
|
+
test('Pointer-tracked popup that is set afterwards is tagged with right class', () => {
|
|
630
630
|
const map = createMap();
|
|
631
631
|
const popup = new Popup()
|
|
632
632
|
.addTo(map);
|
package/src/util/actor.test.ts
CHANGED
|
@@ -144,7 +144,7 @@ describe('Actor', () => {
|
|
|
144
144
|
const worker = await workerFactory() as any as WorkerGlobalScopeInterface & ActorTarget;
|
|
145
145
|
const actor = new Actor(worker, '1');
|
|
146
146
|
|
|
147
|
-
const spy = vi.fn().
|
|
147
|
+
const spy = vi.fn().mockResolvedValue({});
|
|
148
148
|
worker.worker.actor.registerMessageHandler(MessageType.getClusterExpansionZoom, spy);
|
|
149
149
|
|
|
150
150
|
worker.worker.actor.invoker.trigger = async () => {
|
|
@@ -209,7 +209,7 @@ describe('Actor', () => {
|
|
|
209
209
|
|
|
210
210
|
worker.worker.actor.mapId = '2';
|
|
211
211
|
|
|
212
|
-
const spy = vi.fn().
|
|
212
|
+
const spy = vi.fn().mockResolvedValue({});
|
|
213
213
|
worker.worker.actor.registerMessageHandler(MessageType.getClusterExpansionZoom, spy);
|
|
214
214
|
|
|
215
215
|
actor.sendAsync({type: MessageType.getClusterExpansionZoom, data: {} as any, targetMapId: '1'});
|
|
@@ -223,7 +223,7 @@ describe('Actor', () => {
|
|
|
223
223
|
const worker = await workerFactory() as any as WorkerGlobalScopeInterface & ActorTarget;
|
|
224
224
|
const actor = new Actor(worker, '1');
|
|
225
225
|
|
|
226
|
-
const spy = vi.fn().
|
|
226
|
+
const spy = vi.fn().mockResolvedValue({});
|
|
227
227
|
worker.worker.actor.registerMessageHandler(MessageType.getClusterExpansionZoom, spy);
|
|
228
228
|
|
|
229
229
|
actor.target.postMessage({type: 'getClusterExpansionZoom', data: {} as any, origin: 'https://example.com'});
|
|
@@ -237,7 +237,7 @@ describe('Actor', () => {
|
|
|
237
237
|
const worker = await workerFactory() as any as WorkerGlobalScopeInterface & ActorTarget;
|
|
238
238
|
const actor = new Actor(worker, '1');
|
|
239
239
|
|
|
240
|
-
const spy = vi.fn().
|
|
240
|
+
const spy = vi.fn().mockResolvedValue({});
|
|
241
241
|
worker.worker.actor.registerMessageHandler(MessageType.getClusterExpansionZoom, spy);
|
|
242
242
|
|
|
243
243
|
actor.target.postMessage({type: MessageType.getClusterExpansionZoom, data: {} as any, origin: 'null'});
|
|
@@ -251,7 +251,7 @@ describe('Actor', () => {
|
|
|
251
251
|
const worker = await workerFactory() as any as WorkerGlobalScopeInterface & ActorTarget;
|
|
252
252
|
const actor = new Actor(worker, '1');
|
|
253
253
|
|
|
254
|
-
const spy = vi.fn().
|
|
254
|
+
const spy = vi.fn().mockResolvedValue({});
|
|
255
255
|
worker.worker.actor.registerMessageHandler(MessageType.getClusterExpansionZoom, spy);
|
|
256
256
|
|
|
257
257
|
actor.target.postMessage({type: MessageType.getClusterExpansionZoom, data: {} as any, origin: 'file://'});
|
|
@@ -265,7 +265,7 @@ describe('Actor', () => {
|
|
|
265
265
|
const worker = await workerFactory() as any as WorkerGlobalScopeInterface & ActorTarget;
|
|
266
266
|
const actor = new Actor(worker, '1');
|
|
267
267
|
|
|
268
|
-
const spy = vi.fn().
|
|
268
|
+
const spy = vi.fn().mockResolvedValue({});
|
|
269
269
|
worker.worker.actor.registerMessageHandler(MessageType.getClusterExpansionZoom, spy);
|
|
270
270
|
|
|
271
271
|
actor.target.postMessage({type: MessageType.getClusterExpansionZoom, data: {} as any, origin: 'resource://android'});
|
package/src/util/ajax.test.ts
CHANGED
|
@@ -20,6 +20,12 @@ function readAsText(blob) {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
async function expectRejection(promise: Promise<unknown>): Promise<AJAXError> {
|
|
24
|
+
const error = await promise.catch((e) => e);
|
|
25
|
+
expect(error).toBeInstanceOf(Error);
|
|
26
|
+
return error as AJAXError;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
const originalFetch = global.fetch;
|
|
24
30
|
|
|
25
31
|
describe('ajax', () => {
|
|
@@ -37,18 +43,14 @@ describe('ajax', () => {
|
|
|
37
43
|
request.respond(404, undefined, '404 Not Found');
|
|
38
44
|
});
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
expect(ajaxError.statusText).toBe('Not Found');
|
|
49
|
-
expect(ajaxError.url).toBe('http://example.com/test.bin');
|
|
50
|
-
expect(body).toBe('404 Not Found');
|
|
51
|
-
}
|
|
46
|
+
const promise = getArrayBuffer({url: 'http://example.com/test.bin'}, new AbortController());
|
|
47
|
+
server.respond();
|
|
48
|
+
|
|
49
|
+
const ajaxError = await expectRejection(promise);
|
|
50
|
+
expect(ajaxError.status).toBe(404);
|
|
51
|
+
expect(ajaxError.statusText).toBe('Not Found');
|
|
52
|
+
expect(ajaxError.url).toBe('http://example.com/test.bin');
|
|
53
|
+
await expect(readAsText(ajaxError.body)).resolves.toBe('404 Not Found');
|
|
52
54
|
});
|
|
53
55
|
|
|
54
56
|
test('getJSON', async () => {
|
|
@@ -68,11 +70,8 @@ describe('ajax', () => {
|
|
|
68
70
|
});
|
|
69
71
|
const promise = getJSON({url: ''}, new AbortController());
|
|
70
72
|
server.respond();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} catch (error) {
|
|
74
|
-
expect(error).toBeTruthy();
|
|
75
|
-
}
|
|
73
|
+
|
|
74
|
+
await expect(promise).rejects.toThrow(SyntaxError);
|
|
76
75
|
});
|
|
77
76
|
|
|
78
77
|
test('getJSON, 404', async () => {
|
|
@@ -82,16 +81,11 @@ describe('ajax', () => {
|
|
|
82
81
|
const promise = getJSON({url: 'http://example.com/test.json'}, new AbortController());
|
|
83
82
|
server.respond();
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
expect(ajaxError.status).toBe(404);
|
|
91
|
-
expect(ajaxError.statusText).toBe('Not Found');
|
|
92
|
-
expect(ajaxError.url).toBe('http://example.com/test.json');
|
|
93
|
-
expect(body).toBe('404 Not Found');
|
|
94
|
-
}
|
|
84
|
+
const ajaxError = await expectRejection(promise);
|
|
85
|
+
expect(ajaxError.status).toBe(404);
|
|
86
|
+
expect(ajaxError.statusText).toBe('Not Found');
|
|
87
|
+
expect(ajaxError.url).toBe('http://example.com/test.json');
|
|
88
|
+
await expect(readAsText(ajaxError.body)).resolves.toBe('404 Not Found');
|
|
95
89
|
});
|
|
96
90
|
|
|
97
91
|
test('getJSON, aborted', async () => {
|
|
@@ -103,12 +97,9 @@ describe('ajax', () => {
|
|
|
103
97
|
abortController.abort();
|
|
104
98
|
server.respond();
|
|
105
99
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
expect(ensureError(error).name).toBe('AbortError');
|
|
110
|
-
expect(isAbortError(error)).toBe(true);
|
|
111
|
-
}
|
|
100
|
+
const error = await expectRejection(promise);
|
|
101
|
+
expect(ensureError(error).name).toBe('AbortError');
|
|
102
|
+
expect(isAbortError(error)).toBe(true);
|
|
112
103
|
});
|
|
113
104
|
|
|
114
105
|
test('getJSON with fetch, aborted', async () => {
|
|
@@ -126,12 +117,9 @@ describe('ajax', () => {
|
|
|
126
117
|
abortController.abort();
|
|
127
118
|
server.respond();
|
|
128
119
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
expect(ensureError(error).name).toBe('AbortError');
|
|
133
|
-
expect(isAbortError(error)).toBe(true);
|
|
134
|
-
}
|
|
120
|
+
const error = await expectRejection(promise);
|
|
121
|
+
expect(ensureError(error).name).toBe('AbortError');
|
|
122
|
+
expect(isAbortError(error)).toBe(true);
|
|
135
123
|
});
|
|
136
124
|
|
|
137
125
|
test('getReferrer method (outside Worker), same origin https URL', () => {
|
package/src/util/browser.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {describe, test, expect, beforeEach, vi, afterEach
|
|
1
|
+
import {describe, test, expect, beforeEach, vi, afterEach} from 'vitest';
|
|
2
2
|
import {beforeMapTest, createMap as globalCreateMap} from './test/util.ts';
|
|
3
3
|
import {browser} from './browser.ts';
|
|
4
|
+
import {AbortError} from './abort_error.ts';
|
|
4
5
|
|
|
5
6
|
describe('browser', () => {
|
|
6
7
|
describe('frame',() => {
|
|
@@ -56,7 +57,7 @@ describe('browser', () => {
|
|
|
56
57
|
|
|
57
58
|
expect(fn).toHaveBeenCalledTimes(1);
|
|
58
59
|
const callArg = fn.mock.calls[0][0];
|
|
59
|
-
expect(
|
|
60
|
+
expect(callArg).toBeTypeOf('number');
|
|
60
61
|
|
|
61
62
|
expect(window.cancelAnimationFrame).not.toHaveBeenCalled();
|
|
62
63
|
expect(reject).not.toHaveBeenCalled();
|
|
@@ -69,11 +70,8 @@ describe('browser', () => {
|
|
|
69
70
|
test('when AbortController is aborted before frame fires, calls cancelAnimationFrame and reject', () => {
|
|
70
71
|
// We override the default mock so that the callback is NOT called immediately
|
|
71
72
|
// giving us time to abort.
|
|
72
|
-
(window.requestAnimationFrame
|
|
73
|
-
|
|
74
|
-
// Return ID but do not invoke cb
|
|
75
|
-
return 42;
|
|
76
|
-
}
|
|
73
|
+
(vi.mocked(window.requestAnimationFrame)).mockReturnValue(
|
|
74
|
+
42
|
|
77
75
|
);
|
|
78
76
|
|
|
79
77
|
const abortController = new AbortController();
|
|
@@ -145,7 +143,7 @@ describe('browser', () => {
|
|
|
145
143
|
const abortController = new AbortController();
|
|
146
144
|
const promise = browser.frameAsync(abortController);
|
|
147
145
|
abortController.abort();
|
|
148
|
-
await expect(promise).rejects.toThrow();
|
|
146
|
+
await expect(promise).rejects.toThrow(AbortError);
|
|
149
147
|
});
|
|
150
148
|
});
|
|
151
149
|
|
|
@@ -177,6 +175,6 @@ describe('browser', () => {
|
|
|
177
175
|
});
|
|
178
176
|
|
|
179
177
|
test('hardwareConcurrency', () => {
|
|
180
|
-
expect(
|
|
178
|
+
expect(browser.hardwareConcurrency).toBeTypeOf('number');
|
|
181
179
|
});
|
|
182
180
|
});
|
|
@@ -12,8 +12,8 @@ describe('create_tile_mesh', () => {
|
|
|
12
12
|
const options: CreateTileMeshOptions = {};
|
|
13
13
|
createTileMeshWithBuffers(contextMock, options);
|
|
14
14
|
|
|
15
|
-
expect(createVertexBufferSpy.mock.calls[0][0]
|
|
16
|
-
expect(createIndexBufferSpy.mock.calls[0][0]
|
|
15
|
+
expect(createVertexBufferSpy.mock.calls[0][0]).toHaveLength(4);
|
|
16
|
+
expect(createIndexBufferSpy.mock.calls[0][0]).toHaveLength(2);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
test('createTileMesh 32bit', () => {
|
|
@@ -60,7 +60,7 @@ describe('Dispatcher', () => {
|
|
|
60
60
|
test('remove destroys actors', async () => {
|
|
61
61
|
const actorsRemoved = [];
|
|
62
62
|
const mapId = 1;
|
|
63
|
-
Actor.prototype
|
|
63
|
+
vi.spyOn(Actor.prototype, 'remove').mockImplementation(() => {
|
|
64
64
|
actorsRemoved.push(this);
|
|
65
65
|
});
|
|
66
66
|
WorkerPool.workerCount = 4;
|
package/src/util/evented.test.ts
CHANGED
|
@@ -120,10 +120,13 @@ describe('Evented', () => {
|
|
|
120
120
|
|
|
121
121
|
test('does not immediately call listeners added within another listener', () => {
|
|
122
122
|
const evented = new StubbedEvented();
|
|
123
|
+
const nestedListener = vi.fn();
|
|
123
124
|
evented.on('a', () => {
|
|
124
|
-
evented.on('a',
|
|
125
|
+
evented.on('a', nestedListener);
|
|
125
126
|
});
|
|
126
127
|
evented.fire(new Event('a'));
|
|
128
|
+
|
|
129
|
+
expect(nestedListener).not.toHaveBeenCalled();
|
|
127
130
|
});
|
|
128
131
|
|
|
129
132
|
test('has backward compatibility for fire(string, object) API', () => {
|
|
@@ -2,7 +2,7 @@ import {describe, test, expect} from 'vitest';
|
|
|
2
2
|
import {mat4, vec3, quat} from 'gl-matrix';
|
|
3
3
|
import {fastInvertTransformMat4, fastInvertProjMat4, fastInvertSkewMat4} from './fast_maths.ts';
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function expectMatricesClose(mat: mat4, matRef: mat4){
|
|
6
6
|
for (let i=0; i<16; ++i){
|
|
7
7
|
expect(mat[i]).toBeCloseTo(matRef[i], 6);
|
|
8
8
|
}
|
|
@@ -74,7 +74,7 @@ describe('fast_maths', () => {
|
|
|
74
74
|
// compute ref:
|
|
75
75
|
mat4.invert(mInvRef, m);
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
expectMatricesClose(mInv, mInvRef);
|
|
78
78
|
};
|
|
79
79
|
});
|
|
80
80
|
|
|
@@ -114,7 +114,7 @@ describe('fast_maths', () => {
|
|
|
114
114
|
fastInvertProjMat4(mInv, m);
|
|
115
115
|
// compute ref:
|
|
116
116
|
mat4.invert(mInvRef, m);
|
|
117
|
-
|
|
117
|
+
expectMatricesClose(mInv, mInvRef);
|
|
118
118
|
};
|
|
119
119
|
});
|
|
120
120
|
|
|
@@ -171,7 +171,7 @@ describe('fast_maths', () => {
|
|
|
171
171
|
// compute ref:
|
|
172
172
|
mat4.invert(mInvRef, m);
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
expectMatricesClose(mInv, mInvRef);
|
|
175
175
|
};
|
|
176
176
|
});
|
|
177
177
|
});
|
|
@@ -57,8 +57,9 @@ describe('ImageRequest', () => {
|
|
|
57
57
|
|
|
58
58
|
for (let i = 0; i < maxRequests + 1; i++) {
|
|
59
59
|
const abortController = new AbortController();
|
|
60
|
-
ImageRequest.getImage({url: ''}, abortController)
|
|
60
|
+
const request = ImageRequest.getImage({url: ''}, abortController);
|
|
61
61
|
abortController.abort();
|
|
62
|
+
await expect(request).rejects.toSatisfy(isAbortError);
|
|
62
63
|
await sleep(0);
|
|
63
64
|
}
|
|
64
65
|
expect(server.requests).toHaveLength(maxRequests + 1);
|
|
@@ -79,7 +80,7 @@ describe('ImageRequest', () => {
|
|
|
79
80
|
|
|
80
81
|
const queuedURL = 'this-is-the-queued-request';
|
|
81
82
|
const abortController = new AbortController();
|
|
82
|
-
ImageRequest.getImage({url: queuedURL}, abortController)
|
|
83
|
+
const queuedRequestPromise = ImageRequest.getImage({url: queuedURL}, abortController);
|
|
83
84
|
|
|
84
85
|
// the new requests is queued because the limit is reached
|
|
85
86
|
expect(server.requests).toHaveLength(maxRequests);
|
|
@@ -95,11 +96,12 @@ describe('ImageRequest', () => {
|
|
|
95
96
|
expect((queuedRequest as any).aborted).toBeUndefined();
|
|
96
97
|
abortController.abort();
|
|
97
98
|
expect((queuedRequest as any).aborted).toBe(true);
|
|
99
|
+
await expect(queuedRequestPromise).rejects.toSatisfy(isAbortError);
|
|
98
100
|
});
|
|
99
101
|
|
|
100
102
|
test('getImage sends accept/webp header', async () => {
|
|
101
103
|
server.respondWith((request) => {
|
|
102
|
-
expect(request.requestHeaders.accept.
|
|
104
|
+
expect(request.requestHeaders.accept).toContain('image/webp');
|
|
103
105
|
request.respond(200, {'Content-Type': 'image/webp'}, '');
|
|
104
106
|
});
|
|
105
107
|
|
|
@@ -140,7 +142,7 @@ describe('ImageRequest', () => {
|
|
|
140
142
|
|
|
141
143
|
server.respond();
|
|
142
144
|
|
|
143
|
-
await expect(promise).rejects.toThrow();
|
|
145
|
+
await expect(promise).rejects.toThrow('error');
|
|
144
146
|
});
|
|
145
147
|
|
|
146
148
|
test('getImage uses HTMLImageElement when createImageBitmap is not supported', async () => {
|
|
@@ -87,8 +87,8 @@ describe('StructArray', () => {
|
|
|
87
87
|
// Typed views should no longer reference the original buffer
|
|
88
88
|
expect(array.uint8.buffer).not.toBe(originalBuffer);
|
|
89
89
|
expect(array.int16.buffer).not.toBe(originalBuffer);
|
|
90
|
-
expect(array.uint8
|
|
91
|
-
expect(array.int16
|
|
90
|
+
expect(array.uint8).toHaveLength(0);
|
|
91
|
+
expect(array.int16).toHaveLength(0);
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
|
|
@@ -85,7 +85,7 @@ describe('TaskQueue', () => {
|
|
|
85
85
|
test('TaskQueue.run() throws on attempted re-entrance', () => {
|
|
86
86
|
const q = new TaskQueue();
|
|
87
87
|
q.add(() => q.run());
|
|
88
|
-
expect(() => q.run()).toThrow();
|
|
88
|
+
expect(() => q.run()).toThrow('Attempting to run(), but is already running.');
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
test('TaskQueue.clear() prevents queued task from being executed', () => {
|
package/src/util/test/util.ts
CHANGED
|
@@ -242,6 +242,7 @@ export function createTerrain(): Terrain {
|
|
|
242
242
|
getElevationForLngLatZoom: () => 1000,
|
|
243
243
|
getElevationForLngLat: () => 1000,
|
|
244
244
|
getMinTileElevationForLngLatZoom: () => 0,
|
|
245
|
+
resetElevationCache: () => {},
|
|
245
246
|
getFramebuffer: () => ({}),
|
|
246
247
|
getCoordsTexture: () => ({}),
|
|
247
248
|
depthAtPoint: () => .9,
|
|
@@ -26,7 +26,7 @@ describe('time_control', () => {
|
|
|
26
26
|
describe('now()', () => {
|
|
27
27
|
test('returns a valid number when not frozen', () => {
|
|
28
28
|
const currentTime = now();
|
|
29
|
-
expect(
|
|
29
|
+
expect(currentTime).toBeTypeOf('number');
|
|
30
30
|
expect(currentTime).toBeGreaterThanOrEqual(0);
|
|
31
31
|
});
|
|
32
32
|
|
|
@@ -133,7 +133,7 @@ describe('time_control', () => {
|
|
|
133
133
|
expect(isTimeFrozen()).toBe(false);
|
|
134
134
|
|
|
135
135
|
const time = now();
|
|
136
|
-
expect(
|
|
136
|
+
expect(time).toBeTypeOf('number');
|
|
137
137
|
expect(time).toBeGreaterThanOrEqual(0);
|
|
138
138
|
});
|
|
139
139
|
});
|
|
@@ -40,7 +40,7 @@ describe('TransferableGridIndex', () => {
|
|
|
40
40
|
expect(grid.query(-6, 0, -7, 100)).toEqual([2]);
|
|
41
41
|
expect(grid.query(-Infinity, -Infinity, Infinity, Infinity).sort()).toEqual([0, 1, 2]);
|
|
42
42
|
|
|
43
|
-
expect(() => grid.insert(3, 0, 0, 0, 0)).toThrow();
|
|
43
|
+
expect(() => grid.insert(3, 0, 0, 0, 0)).toThrow('Cannot insert into a GridIndex created from an ArrayBuffer.');
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
test('serialize round trip', () => {
|
package/src/util/util.test.ts
CHANGED
|
@@ -7,16 +7,30 @@ import {expectToBeCloseToArray} from './test/util.ts';
|
|
|
7
7
|
import {vec3, type vec4} from 'gl-matrix';
|
|
8
8
|
|
|
9
9
|
describe('util', () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
test('easeCubicInOut', () => {
|
|
11
|
+
expect(easeCubicInOut(0)).toBe(0);
|
|
12
|
+
expect(easeCubicInOut(0.2)).toBe(0.03200000000000001);
|
|
13
|
+
expect(easeCubicInOut(0.5)).toBe(0.5);
|
|
14
|
+
expect(easeCubicInOut(1)).toBe(1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('keysDifference', () => {
|
|
18
|
+
expect(keysDifference({a: 1}, {})).toEqual(['a']);
|
|
19
|
+
expect(keysDifference({a: 1}, {a: 1})).toEqual([]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('extend', () => {
|
|
23
|
+
expect(extend({a: 1}, {b: 2})).toEqual({a: 1, b: 2});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('pick', () => {
|
|
27
|
+
expect(pick({a: 1, b: 2, c: 3}, ['a', 'c'])).toEqual({a: 1, c: 3});
|
|
28
|
+
expect(pick({a: 1, b: 2, c: 3}, ['a', 'c', 'd'] as any)).toEqual({a: 1, c: 3});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('uniqueId', () => {
|
|
32
|
+
expect(uniqueId()).toBeTypeOf('number');
|
|
33
|
+
});
|
|
20
34
|
|
|
21
35
|
test('isPowerOfTwo', () => {
|
|
22
36
|
expect(isPowerOfTwo(1)).toBe(true);
|
|
@@ -38,7 +52,7 @@ describe('util', () => {
|
|
|
38
52
|
expect(nextPowerOfTwo(42)).toBe(64);
|
|
39
53
|
});
|
|
40
54
|
|
|
41
|
-
test('nextPowerOfTwo', () => {
|
|
55
|
+
test('nextPowerOfTwo always returns a power of two', () => {
|
|
42
56
|
expect(isPowerOfTwo(nextPowerOfTwo(1))).toBe(true);
|
|
43
57
|
expect(isPowerOfTwo(nextPowerOfTwo(2))).toBe(true);
|
|
44
58
|
expect(isPowerOfTwo(nextPowerOfTwo(256))).toBe(true);
|
|
@@ -435,7 +449,7 @@ describe('util readImageUsingVideoFrame', () => {
|
|
|
435
449
|
|
|
436
450
|
test('ignore bad format', async () => {
|
|
437
451
|
format = 'OTHER';
|
|
438
|
-
await expect(readImageUsingVideoFrame(canvas, 0, 0, 2, 2)).rejects.toThrow();
|
|
452
|
+
await expect(readImageUsingVideoFrame(canvas, 0, 0, 2, 2)).rejects.toThrow('Unrecognized format OTHER');
|
|
439
453
|
expect(frame.close).toHaveBeenCalledTimes(1);
|
|
440
454
|
});
|
|
441
455
|
|
|
@@ -590,7 +604,7 @@ describe('util getAngleDelta', () => {
|
|
|
590
604
|
expect(getAngleDelta(lastPoint, currentPoint, center)).toBe(90);
|
|
591
605
|
});
|
|
592
606
|
|
|
593
|
-
test('
|
|
607
|
+
test('negative direction', () => {
|
|
594
608
|
const lastPoint = new Point(1, 0);
|
|
595
609
|
const currentPoint = new Point(0, 1);
|
|
596
610
|
const center = new Point(0, 0);
|
|
@@ -3,13 +3,13 @@ import {verticalizePunctuation} from './verticalize_punctuation.ts';
|
|
|
3
3
|
|
|
4
4
|
describe('verticalizePunctuation', () => {
|
|
5
5
|
test('preserves characters without fullwidth variants', () => {
|
|
6
|
-
expect(verticalizePunctuation('ABC123')).
|
|
6
|
+
expect(verticalizePunctuation('ABC123')).toBe('ABC123');
|
|
7
7
|
});
|
|
8
8
|
test('replaces punctuation marks with fullwidth variants', () => {
|
|
9
|
-
expect(verticalizePunctuation('!?')).
|
|
9
|
+
expect(verticalizePunctuation('!?')).toBe('︕︖');
|
|
10
10
|
});
|
|
11
11
|
test('replaces rotatable punctuation marks', () => {
|
|
12
|
-
expect(verticalizePunctuation('(…)')).
|
|
13
|
-
expect(verticalizePunctuation('(⋯)')).
|
|
12
|
+
expect(verticalizePunctuation('(…)')).toBe('︵︙︶');
|
|
13
|
+
expect(verticalizePunctuation('(⋯)')).toBe('︵︙︶');
|
|
14
14
|
});
|
|
15
15
|
});
|
|
@@ -119,7 +119,7 @@ describe('web worker transfer', () => {
|
|
|
119
119
|
const trySerialize = () => {
|
|
120
120
|
serialize(new BadClass());
|
|
121
121
|
};
|
|
122
|
-
expect(trySerialize).toThrow();
|
|
122
|
+
expect(trySerialize).toThrow('can\'t serialize object of unregistered class BadClass');
|
|
123
123
|
});
|
|
124
124
|
test('serialize can not used reserved property #name', () => {
|
|
125
125
|
class BadClass {
|
|
@@ -133,7 +133,7 @@ describe('web worker transfer', () => {
|
|
|
133
133
|
const badObject = new BadClass();
|
|
134
134
|
expect(() => {
|
|
135
135
|
serialize(badObject);
|
|
136
|
-
}).toThrow();
|
|
136
|
+
}).toThrow('$name property is reserved for worker serialization logic.');
|
|
137
137
|
});
|
|
138
138
|
test('deserialize Object has $name', () => {
|
|
139
139
|
const badObject = {
|
|
@@ -142,18 +142,18 @@ describe('web worker transfer', () => {
|
|
|
142
142
|
const tryDeserialize = () => {
|
|
143
143
|
deserialize(badObject);
|
|
144
144
|
};
|
|
145
|
-
expect(tryDeserialize).toThrow();
|
|
145
|
+
expect(tryDeserialize).toThrow('can\'t deserialize unregistered class foo');
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
test('some objects can not be serialized', () => {
|
|
149
149
|
expect(() => {
|
|
150
150
|
serialize(BigInt(123));
|
|
151
|
-
}).toThrow();
|
|
151
|
+
}).toThrow('can\'t serialize object of type bigint');
|
|
152
152
|
});
|
|
153
153
|
test('some objects can not be deserialized', () => {
|
|
154
154
|
expect(() => {
|
|
155
155
|
deserialize(BigInt(123) as unknown);
|
|
156
|
-
}).toThrow();
|
|
156
|
+
}).toThrow('can\'t deserialize object of type bigint');
|
|
157
157
|
});
|
|
158
158
|
|
|
159
159
|
test('"has" filter returns false for undefined or missing properties after serialization', () => {
|