Skip to main content
Glama
deleonio
by deleonio
snapshot.mjs1.41 kB
import assert from 'node:assert/strict'; import { mkdir, readFile, writeFile } from 'node:fs/promises'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const shouldUpdateSnapshots = () => { const value = process.env.SNAPSHOT_UPDATE?.toLowerCase(); return value === '1' || value === 'true' || value === 'yes'; }; const serialize = (data) => `${JSON.stringify(data, null, 2)}\n`; export const createSnapshotMatcher = (moduleUrl) => { const testDirectory = dirname(fileURLToPath(moduleUrl)); const snapshotsDirectory = join(testDirectory, '__snapshots__'); return async (snapshotName, data) => { const snapshotPath = join(snapshotsDirectory, `${snapshotName}.json`); try { const existing = JSON.parse(await readFile(snapshotPath, 'utf8')); if (shouldUpdateSnapshots()) { await mkdir(snapshotsDirectory, { recursive: true }); await writeFile(snapshotPath, serialize(data)); return; } assert.deepStrictEqual(data, existing); } catch (error) { if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') { if (shouldUpdateSnapshots()) { await mkdir(snapshotsDirectory, { recursive: true }); await writeFile(snapshotPath, serialize(data)); return; } throw new Error(`Snapshot "${snapshotName}" is missing. Run with SNAPSHOT_UPDATE=1 to create it.`); } throw error; } }; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/deleonio/public-ui-kolibri'

If you have feedback or need assistance with the MCP directory API, please join our Discord server