emulate 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -49,6 +49,65 @@ emulate list
49
49
 
50
50
  The port can also be set via `EMULATE_PORT` or `PORT` environment variables.
51
51
 
52
+ ## Programmatic API
53
+
54
+ ```bash
55
+ npm install emulate
56
+ ```
57
+
58
+ Each call to `createEmulator` starts a single service:
59
+
60
+ ```typescript
61
+ import { createEmulator } from 'emulate'
62
+
63
+ const github = await createEmulator({ service: 'github', port: 4001 })
64
+ const vercel = await createEmulator({ service: 'vercel', port: 4002 })
65
+
66
+ github.url // 'http://localhost:4001'
67
+ vercel.url // 'http://localhost:4002'
68
+
69
+ await github.close()
70
+ await vercel.close()
71
+ ```
72
+
73
+ ### Vitest / Jest setup
74
+
75
+ ```typescript
76
+ // vitest.setup.ts
77
+ import { createEmulator, type Emulator } from 'emulate'
78
+
79
+ let github: Emulator
80
+ let vercel: Emulator
81
+
82
+ beforeAll(async () => {
83
+ ;[github, vercel] = await Promise.all([
84
+ createEmulator({ service: 'github', port: 4001 }),
85
+ createEmulator({ service: 'vercel', port: 4002 }),
86
+ ])
87
+ process.env.GITHUB_URL = github.url
88
+ process.env.VERCEL_URL = vercel.url
89
+ })
90
+
91
+ afterEach(() => { github.reset(); vercel.reset() })
92
+ afterAll(() => Promise.all([github.close(), vercel.close()]))
93
+ ```
94
+
95
+ ### Options
96
+
97
+ | Option | Default | Description |
98
+ |--------|---------|-------------|
99
+ | `service` | *(required)* | Service to emulate: `'github'`, `'vercel'`, or `'google'` |
100
+ | `port` | `4000` | Port for the HTTP server |
101
+ | `seed` | none | Inline seed data (same shape as YAML config) |
102
+
103
+ ### Instance methods
104
+
105
+ | Method | Description |
106
+ |--------|-------------|
107
+ | `url` | Base URL of the running server |
108
+ | `reset()` | Wipe the store and replay seed data |
109
+ | `close()` | Shut down the HTTP server, returns a Promise |
110
+
52
111
  ## Configuration
53
112
 
54
113
  Configuration is optional. To customize seed data, create `emulate.config.yaml` in your project root (or pass `--seed`):
package/dist/api.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import * as _internal_core from '@internal/core';
2
+ import { VercelSeedConfig } from '@internal/vercel';
3
+ import { GitHubSeedConfig } from '@internal/github';
4
+ import { GoogleSeedConfig } from '@internal/google';
5
+
6
+ declare const SERVICE_PLUGINS: {
7
+ readonly vercel: _internal_core.ServicePlugin;
8
+ readonly github: _internal_core.ServicePlugin;
9
+ readonly google: _internal_core.ServicePlugin;
10
+ };
11
+ type ServiceName = keyof typeof SERVICE_PLUGINS;
12
+ interface SeedConfig {
13
+ tokens?: Record<string, {
14
+ login: string;
15
+ scopes?: string[];
16
+ }>;
17
+ vercel?: VercelSeedConfig;
18
+ github?: GitHubSeedConfig;
19
+ google?: GoogleSeedConfig;
20
+ }
21
+ interface EmulatorOptions {
22
+ service: ServiceName;
23
+ port?: number;
24
+ seed?: SeedConfig;
25
+ }
26
+ interface Emulator {
27
+ url: string;
28
+ reset(): void;
29
+ close(): Promise<void>;
30
+ }
31
+ declare function createEmulator(options: EmulatorOptions): Promise<Emulator>;
32
+
33
+ export { type Emulator, type EmulatorOptions, type SeedConfig, type ServiceName, createEmulator };