|
| 1 | +import * as v from 'valibot' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | +import { commonRpcFunctions, KNOWN_EDITORS, openInEditor, openInFinder } from '../common-rpc-functions' |
| 4 | +import { openHelpers } from '../open-helpers' |
| 5 | + |
| 6 | +describe('recipes/common-rpc-functions', () => { |
| 7 | + it('exposes `openInEditor` as a devframe-namespaced action', () => { |
| 8 | + expect(openInEditor.name).toBe('devframe:open-in-editor') |
| 9 | + expect(openInEditor.type).toBe('action') |
| 10 | + expect(openInEditor.args).toHaveLength(2) |
| 11 | + expect(typeof openInEditor.handler).toBe('function') |
| 12 | + }) |
| 13 | + |
| 14 | + it('restricts `openInEditor`\'s optional second argument to `KNOWN_EDITORS`', () => { |
| 15 | + expect(KNOWN_EDITORS).toContain('code') |
| 16 | + expect(KNOWN_EDITORS).toContain('vim') |
| 17 | + |
| 18 | + const editorSchema = openInEditor.args[1] |
| 19 | + expect(v.safeParse(editorSchema, undefined).success).toBe(true) |
| 20 | + for (const editor of KNOWN_EDITORS) |
| 21 | + expect(v.safeParse(editorSchema, editor).success).toBe(true) |
| 22 | + expect(v.safeParse(editorSchema, 'not-a-real-editor').success).toBe(false) |
| 23 | + }) |
| 24 | + |
| 25 | + it('exposes `openInFinder` as a devframe-namespaced action', () => { |
| 26 | + expect(openInFinder.name).toBe('devframe:open-in-finder') |
| 27 | + expect(openInFinder.type).toBe('action') |
| 28 | + expect(openInFinder.args).toHaveLength(1) |
| 29 | + expect(typeof openInFinder.handler).toBe('function') |
| 30 | + }) |
| 31 | + |
| 32 | + it('bundles both helpers in `commonRpcFunctions`', () => { |
| 33 | + expect(commonRpcFunctions).toHaveLength(2) |
| 34 | + expect(commonRpcFunctions).toContain(openInEditor) |
| 35 | + expect(commonRpcFunctions).toContain(openInFinder) |
| 36 | + }) |
| 37 | + |
| 38 | + it('keeps the deprecated `devframe/recipes/open-helpers` entry working as an alias', () => { |
| 39 | + expect(openHelpers).toBe(commonRpcFunctions) |
| 40 | + }) |
| 41 | +}) |
0 commit comments