|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { isHostConfig } from '../src/utils/plugin-detection'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Tests for the host config detection logic used in serve.ts |
| 6 | + * |
| 7 | + * When the root config is a host/aggregator (i.e. its `plugins` array |
| 8 | + * contains already-instantiated Plugin objects), the CLI must NOT wrap |
| 9 | + * it again with AppPlugin, as that would cause duplicate registration |
| 10 | + * and a `plugin.app.<id> failed to start` error. |
| 11 | + */ |
| 12 | +describe('Host config detection', () => { |
| 13 | + |
| 14 | + it('should detect host config with instantiated plugins', () => { |
| 15 | + const config = { |
| 16 | + manifest: { id: 'dev-workspace', name: 'dev_workspace' }, |
| 17 | + plugins: [ |
| 18 | + { name: 'objectql', init: async () => {}, start: async () => {} }, |
| 19 | + { name: 'driver', init: async () => {}, start: async () => {} }, |
| 20 | + ], |
| 21 | + }; |
| 22 | + expect(isHostConfig(config)).toBe(true); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should NOT detect pure app bundle config (no plugins)', () => { |
| 26 | + const config = { |
| 27 | + manifest: { id: 'my-app', name: 'my_app' }, |
| 28 | + objects: [{ name: 'task', fields: [] }], |
| 29 | + }; |
| 30 | + expect(isHostConfig(config)).toBe(false); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should NOT detect config with empty plugins array', () => { |
| 34 | + const config = { |
| 35 | + manifest: { id: 'my-app', name: 'my_app' }, |
| 36 | + objects: [{ name: 'task', fields: [] }], |
| 37 | + plugins: [], |
| 38 | + }; |
| 39 | + expect(isHostConfig(config)).toBe(false); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should NOT detect config with string plugin references', () => { |
| 43 | + const config = { |
| 44 | + manifest: { id: 'my-app', name: 'my_app' }, |
| 45 | + plugins: ['@objectstack/plugin-auth', '@objectstack/objectql'], |
| 46 | + }; |
| 47 | + expect(isHostConfig(config)).toBe(false); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should NOT detect config with plain object plugins (no init method)', () => { |
| 51 | + const config = { |
| 52 | + manifest: { id: 'my-app', name: 'my_app' }, |
| 53 | + plugins: [ |
| 54 | + { name: 'some-plugin', version: '1.0.0' }, |
| 55 | + ], |
| 56 | + }; |
| 57 | + expect(isHostConfig(config)).toBe(false); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should detect if at least one plugin has init method', () => { |
| 61 | + const config = { |
| 62 | + manifest: { id: 'dev-workspace' }, |
| 63 | + plugins: [ |
| 64 | + { name: 'plain-bundle', version: '1.0.0' }, |
| 65 | + { name: 'real-plugin', init: async () => {}, start: async () => {} }, |
| 66 | + ], |
| 67 | + }; |
| 68 | + expect(isHostConfig(config)).toBe(true); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should handle config without plugins property', () => { |
| 72 | + const config = { |
| 73 | + manifest: { id: 'my-app', name: 'my_app' }, |
| 74 | + }; |
| 75 | + expect(isHostConfig(config)).toBe(false); |
| 76 | + }); |
| 77 | +}); |
0 commit comments