Merge branch 'kh/vitest' into develop

This commit is contained in:
Martin Raifer
2024-10-16 13:37:20 +02:00
23 changed files with 3533 additions and 10216 deletions
+3 -1
View File
@@ -74,8 +74,10 @@ export function coreFileFetcher() {
function getUrl(url, which) {
let prom = _inflight[url];
if (!prom) {
_inflight[url] = prom = fetch(url)
_inflight[url] = prom = (window.VITEST ? import(`../${url}`) : fetch(url))
.then(response => {
if (window.VITEST) return response.default;
if (!response.ok || !response.json) {
throw new Error(response.status + ' ' + response.statusText);
}
+12
View File
@@ -0,0 +1,12 @@
import type { FetchMockStatic } from 'fetch-mock';
declare global {
declare var iD: typeof import('.');
declare var d3: import('d3');
declare var fetchMock: FetchMockStatic;
declare var before: typeof beforeEach;
declare var after: typeof afterEach;
declare var VITEST: true;
}
export {};
+3
View File
@@ -23,6 +23,9 @@ export * from './validations/index';
// This is only done in testing because of the performance penalty.
export let debug = false;
/** @param {boolean} newValue */
export const setDebug = (newValue) => { debug = newValue; };
// Reexport just what our tests use, see #4379
import * as D3 from 'd3';
export let d3 = {
+1 -1
View File
@@ -11,7 +11,7 @@ import { IntervalTasksQueue } from '../util/IntervalTasksQueue';
var isRetina = window.devicePixelRatio && window.devicePixelRatio >= 2;
// listen for DPI change, e.g. when dragging a browser window from a retina to non-retina screen
window.matchMedia(`
window.matchMedia?.(`
(-webkit-min-device-pixel-ratio: 2), /* Safari */
(min-resolution: 2dppx), /* standard */
(min-resolution: 192dpi) /* fallback */
+1 -10
View File
@@ -34,18 +34,9 @@ async function fetchAvailableLayers() {
const urlForRequest = owsEndpoint + utilQsString(params);
const response = await d3_xml(urlForRequest);
const xPathSelector = '/wfs:WFS_Capabilities/wfs:FeatureTypeList/wfs:FeatureType/wfs:Name';
const regexMatcher = /^vegbilder_1_0:Vegbilder(?<image_type>_360)?_(?<year>\d{4})$/;
const NSResolver = response.createNSResolver(response);
const l = response.evaluate(
xPathSelector,
response,
NSResolver,
XPathResult.ANY_TYPE
);
let node;
const availableLayers = [];
while ( (node = l.iterateNext()) !== null ) {
for (const node of response.querySelectorAll('FeatureType > Name')) {
const match = node.textContent?.match(regexMatcher);
if (match) {
availableLayers.push({
+1 -1
View File
@@ -298,7 +298,7 @@ export function uiCombobox(context, klass) {
// https://stackoverflow.com/questions/11039885/scrollintoview-causing-the-whole-page-to-move
var selected = combo.selectAll('.combobox-option.selected').node();
if (selected) {
selected.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
selected.scrollIntoView?.({ behavior: 'smooth', block: 'nearest' });
}
}