Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kentcdodds/google

Google helpers for Gmail, Calendar, Drive, People, YouTube (including upload), and Analytics.

FollowFork

Files

kody-runtime-stub.mjs

25 lines · 1014 B · JavaScript
// Test-only preload: resolves `kody:runtime` to an in-memory stub so modules that
// import it can run under plain Node. Tests set `globalThis.__kodyTestFetch` to a
// mocked fetch; `createAuthenticatedFetch(name)` returns it.
import { registerHooks } from 'node:module'

const stubSource = `
export async function createAuthenticatedFetch(name) {
	const fetchImpl = globalThis.__kodyTestFetch
	if (!fetchImpl) throw new Error('No mocked fetch for credential ' + name)
	return (input, init) => fetchImpl(input, init, name)
}
export function packageStorage() {
	const data = new Map()
	return { async get(key) { return data.get(key) }, async set(key, value) { data.set(key, value) }, async delete(key) { data.delete(key) } }
}
export const kody = {}
`
const stubUrl = 'data:text/javascript,' + encodeURIComponent(stubSource)

registerHooks({
	resolve(specifier, context, nextResolve) {
		if (specifier === 'kody:runtime') return { url: stubUrl, shortCircuit: true }
		return nextResolve(specifier, context)
	},
})