feat: v0.4.1 — untrack map-asset pack (~100 MB): compose volume mount + runtime fallback to remote OFM styles

This commit is contained in:
2026-09-17 09:14:34 +00:00
parent 501c452377
commit 1c50cfeab2
791 changed files with 257 additions and 5171 deletions
+48 -2
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { DEFAULT_STYLE_ID, STYLES, isStyleId, rewriteStyle, styleUrl } from './mapStyles';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { DEFAULT_STYLE_ID, REMOTE_STYLE_BASE, STYLES, isStyleId, rewriteStyle, styleUrl, styleUrlFor } from './mapStyles';
// Mirrors the real OFM style JSONs (verified against tiles.openfreemap.org): same
// glyphs/sprite values and source shapes, no attribution anywhere.
@@ -76,3 +76,49 @@ describe('rewriteStyle', () => {
expect(JSON.stringify(RAW_OFM_STYLE)).toBe(before);
});
});
describe('styleUrlFor', () => {
it('points at the local style file when the asset pack is available', () => {
for (const s of STYLES) {
expect(styleUrlFor(s.id, true)).toBe(`/styles/${s.id}.json`);
}
});
it('points at the exact remote OFM style url otherwise', () => {
for (const s of STYLES) {
expect(styleUrlFor(s.id, false)).toBe(`${REMOTE_STYLE_BASE}/${s.id}`);
expect(styleUrlFor(s.id, false)).toBe(`https://tiles.openfreemap.org/styles/${s.id}`);
}
});
});
describe('localAssetsAvailable', () => {
// The probe caches its promise at module level, so each test gets a fresh module
// instance (resetModules + dynamic import) with its own stubbed fetch.
afterEach(() => {
vi.unstubAllGlobals();
vi.resetModules();
});
it('resolves false on non-200 responses', async () => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: false, status: 404 }));
const mod = await import('./mapStyles');
await expect(mod.localAssetsAvailable()).resolves.toBe(false);
});
it('resolves true on 200 and caches the probe (one fetch across awaits)', async () => {
const fetchMock = vi.fn().mockResolvedValue({ ok: true, status: 200 });
vi.stubGlobal('fetch', fetchMock);
const mod = await import('./mapStyles');
const [a, b] = await Promise.all([mod.localAssetsAvailable(), mod.localAssetsAvailable()]);
expect(a).toBe(true);
expect(b).toBe(true);
expect(fetchMock).toHaveBeenCalledTimes(1);
});
it('resolves false on network errors', async () => {
vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new Error('offline')));
const mod = await import('./mapStyles');
await expect(mod.localAssetsAvailable()).resolves.toBe(false);
});
});