(dir: string, plugin: PluginSpec[], opts?: { plugin_enabled?: Record<string, boolean> })
| 30 | } |
| 31 | |
| 32 | export function mockTuiRuntime(dir: string, plugin: PluginSpec[], opts?: { plugin_enabled?: Record<string, boolean> }) { |
| 33 | process.env.OPENCODE_PLUGIN_META_FILE = path.join(dir, "plugin-meta.json") |
| 34 | const plugin_origins = plugin.map((spec) => ({ |
| 35 | spec, |
| 36 | scope: "local" as const, |
| 37 | source: path.join(dir, "tui.json"), |
| 38 | })) |
| 39 | const wait = spyOn(TuiConfig, "waitForDependencies").mockResolvedValue() |
| 40 | const cwd = spyOn(process, "cwd").mockImplementation(() => dir) |
| 41 | |
| 42 | const config = createTuiResolvedConfig({ |
| 43 | plugin, |
| 44 | plugin_origins, |
| 45 | ...(opts?.plugin_enabled && { plugin_enabled: opts.plugin_enabled }), |
| 46 | }) |
| 47 | |
| 48 | return { |
| 49 | config, |
| 50 | restore: () => { |
| 51 | cwd.mockRestore() |
| 52 | wait.mockRestore() |
| 53 | delete process.env.OPENCODE_PLUGIN_META_FILE |
| 54 | }, |
| 55 | } |
| 56 | } |
no test coverage detected