Skip to content

feat: emulate.config.ts#1

Open
tmm wants to merge 1 commit into
composition-exportsfrom
emulate-config-ts
Open

feat: emulate.config.ts#1
tmm wants to merge 1 commit into
composition-exportsfrom
emulate-config-ts

Conversation

@tmm

@tmm tmm commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Adds defineConfig and emulate.config.ts / .js loading so the CLI can launch custom or extended emulator plugins. Existing YAML and JSON seed configs still work through --seed and autodiscovery.

Use emulate.config.ts to extend a built-in emulator from the CLI, including custom ports and seed data. This example adds GitHub's Contents API for a downstream app while preserving the built-in GitHub routes.

import { defineConfig } from 'emulate'
import { createPlugin } from 'emulate/core'
import { githubPlugin } from 'emulate/plugins'

const github = createPlugin({
  name: 'github',
  register(app, store, webhooks, baseUrl, tokenMap) {
    // Preserve built-in GitHub behavior.
    githubPlugin.register(app, store, webhooks, baseUrl, tokenMap)

    // Add GitHub's Contents API, which this app uses but emulate does not support yet.
    app.get('/repos/:owner/:repo/contents/:path{.+}', (c) => {
      const path = c.req.param('path')
      return c.json({
        name: path.split('/').at(-1),
        path,
        type: 'file',
        encoding: 'base64',
        content: 'SGVsbG8gZnJvbSBlbXVsYXRlCg==',
      })
    })
  },
  seed: githubPlugin.seed,
})

export default defineConfig({
  services: {
    github: {
      plugin: github,
      // Override the default auto-incremented port for this service.
      port: 4001,
      seed: { users: [{ login: 'octocat' }] },
    },
  },
})

The same config file can register a fully custom emulator service that is not part of the built-in registry. This keeps app-specific test APIs available through npx emulate without publishing a separate emulator package.

import { defineConfig } from 'emulate'
import { createPlugin } from 'emulate/core'

const custom = createPlugin({
  name: 'custom',
  register(app) {
    // Define whatever API surface your app needs for tests.
    app.get('/ping', (c) => c.json({ ok: true }))
  },
})

export default defineConfig({
  services: {
    custom: {
      plugin: custom,
      port: 4100,
    },
  },
})

Needs vercel-labs#178

@tmm tmm force-pushed the emulate-config-ts branch from 8471d62 to f2c09e7 Compare June 12, 2026 22:02
@tmm tmm changed the title Add emulate.config.ts support feat: emulate.config.ts Jun 12, 2026
@tmm tmm force-pushed the emulate-config-ts branch from f2c09e7 to 39d1d65 Compare June 12, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant