UNPKG

@withpica/mcp-server

Version:

MCP Server for withPICA — enables AI assistants to interact with your withPICA music catalog

34 lines (30 loc) • 1.5 kB
// Copyright (c) 2025-2026 Withpica Ltd. All rights reserved. // Fail-fast guard for the mcp-server jest suite. // // This package runs jest in full ESM mode (see jest.config.js: the // ts-jest `default-esm` preset, `extensionsToTreatAsEsm`, and // `jest.unstable_mockModule` in the ESM-only suites such as // src/__tests__/apps/shared.test.ts, which also uses a top-level // `await import`). ESM mode requires Node's experimental VM modules, which the // package's `test` script enables via `NODE_OPTIONS=--experimental-vm-modules`. // // Running bare `npx jest` (without that flag) silently drops ESM mode: the // ESM-only suites fail to parse with a cryptic // "SyntaxError: await is only valid in async functions and the top level // bodies of modules", and `unstable_mockModule` becomes inert — so any partial // results are untrustworthy. This guard turns that footgun into one clear, // actionable error before any suite runs. // // `vm.SourceTextModule` exists ONLY when --experimental-vm-modules is active, // so it is a reliable probe for ESM mode. const vm = require("vm"); module.exports = async function requireEsmMode() { if (typeof vm.SourceTextModule !== "function") { throw new Error( "[mcp-server] jest must run in ESM mode. Use `npm test` (it sets " + "NODE_OPTIONS=--experimental-vm-modules) — bare `npx jest` drops the " + "flag and the ESM unstable_mockModule suites fail to load with a " + "misleading SyntaxError.", ); } };