|
| 1 | +import { afterEach, beforeEach, describe, expect, it } from 'bun:test'; |
| 2 | +import { mkdtempSync, rmSync } from 'fs'; |
| 3 | +import { tmpdir } from 'os'; |
| 4 | +import { join } from 'path'; |
| 5 | + |
| 6 | +describe('mmx help', () => { |
| 7 | + let home: string; |
| 8 | + let originalHome: string | undefined; |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + home = mkdtempSync(join(tmpdir(), 'mmx-help-')); |
| 12 | + originalHome = process.env.HOME; |
| 13 | + process.env.HOME = home; |
| 14 | + }); |
| 15 | + |
| 16 | + afterEach(() => { |
| 17 | + if (originalHome === undefined) delete process.env.HOME; |
| 18 | + else process.env.HOME = originalHome; |
| 19 | + rmSync(home, { recursive: true, force: true }); |
| 20 | + }); |
| 21 | + |
| 22 | + it('prints documentation links without requiring credentials', async () => { |
| 23 | + const child = Bun.spawn({ |
| 24 | + cmd: [process.execPath, 'run', 'src/main.ts', 'help'], |
| 25 | + cwd: process.cwd(), |
| 26 | + env: { |
| 27 | + ...process.env, |
| 28 | + HOME: home, |
| 29 | + MMX_CONFIG_DIR: join(home, '.mmx'), |
| 30 | + NO_COLOR: '1', |
| 31 | + MINIMAX_API_KEY: '', |
| 32 | + }, |
| 33 | + stdout: 'pipe', |
| 34 | + stderr: 'pipe', |
| 35 | + }); |
| 36 | + |
| 37 | + const [stdout, stderr, exitCode] = await Promise.all([ |
| 38 | + new Response(child.stdout).text(), |
| 39 | + new Response(child.stderr).text(), |
| 40 | + child.exited, |
| 41 | + ]); |
| 42 | + |
| 43 | + expect(exitCode).toBe(0); |
| 44 | + expect(stdout).toContain('MiniMax API Documentation Links'); |
| 45 | + expect(stderr).not.toContain('No credentials found'); |
| 46 | + expect(stderr).not.toContain('How would you like to authenticate'); |
| 47 | + }); |
| 48 | +}); |
0 commit comments