Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

define-plugin.test.ts

37 lines1.1 KB

1import { describe, expect, it } from 'vitest'
2import { definePlugin } from '../src'
3import { mockAdapter } from './helpers'
4​
5describe('definePlugin', () => {
6 it('refuses a setup() contribution at the top level', () => {
7 const { adapter } = mockAdapter([])
8 expect(() =>
9 // @ts-expect-error `adapter` is returned from `setup()`
10 definePlugin({ name: 'acme/model', adapter: () => adapter }),
11 ).toThrow(
12 'definePlugin "acme/model": `adapter` is not a plugin option. Return it from `setup()` instead.',
13 )
14 })
15​
16 it('keeps an extra key as the plugin API', () => {
17 const plugin = definePlugin({
18 name: 'acme/api',
19 diff: (from: string) => `diff ${from}`,
20 })
21 expect(plugin.diff('a')).toBe('diff a')
22 })
23​
24 it('keeps every known option', () => {
25 const plugin = definePlugin({
26 name: 'acme/ok',
27 lifetime: 'turn',
28 requires: [],
29 provides: [],
30 optionalRequires: [],
31 needs: {},
32 setup: () => ({ prompts: ['hi'] }),
33 })
34 expect(plugin.name).toBe('acme/ok')
35 expect(plugin.lifetime).toBe('turn')
36 })
37})