diff --git a/package.json b/package.json index 973c243..e360941 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uschuster/webapp-scaffold", - "version": "0.3.2", + "version": "0.3.3", "description": "Shared build scripts + Vite config factories for webapp-template-derived projects.", "type": "module", "bin": { diff --git a/src/core-fetch.ts b/src/core-fetch.ts index c976ecb..3f6fd34 100644 --- a/src/core-fetch.ts +++ b/src/core-fetch.ts @@ -96,7 +96,11 @@ const MUTATING = new Set(['POST', 'PUT', 'PATCH', 'DELETE']); export function createCoreFetch(opts: CoreFetchOptions = {}): CoreFetch { const base = (opts.baseUrl ?? '').replace(/\/$/, ''); - const fetchImpl = opts.fetchImpl ?? fetch; + // Resolve fetch at call time, not construction time, so tests that + // `vi.stubGlobal('fetch', ...)` after module import see the stub. + const callFetch: typeof fetch = opts.fetchImpl + ? opts.fetchImpl + : ((...args) => fetch(...(args as Parameters))) as typeof fetch; const shape: ResponseShape = opts.responseShape ?? 'wrapped'; function wrap(data: unknown, status: number, headers: Headers): unknown { @@ -129,7 +133,7 @@ export function createCoreFetch(opts: CoreFetchOptions = {}): CoreFetch { let r: Response; try { - r = await fetchImpl(`${base}${url}`, { + r = await callFetch(`${base}${url}`, { credentials: 'include', ...init, headers,