import { expect, tap } from '@git.zone/tstest/tapbundle'; import * as tswatch from '../ts/index.js'; // ============================================ // ConfigHandler Tests // ============================================ tap.test('ConfigHandler: should return all preset names', async () => { const configHandler = new tswatch.ConfigHandler(); const presetNames = configHandler.getPresetNames(); expect(presetNames).toContain('npm'); expect(presetNames).toContain('test'); expect(presetNames).toContain('service'); expect(presetNames).toContain('element'); expect(presetNames).toContain('website'); expect(presetNames.length).toEqual(5); }); tap.test('ConfigHandler: should return npm preset with watchers', async () => { const configHandler = new tswatch.ConfigHandler(); const preset = configHandler.getPreset('npm'); expect(preset).toBeTruthy(); expect(preset.watchers).toBeTruthy(); expect(preset.watchers.length).toBeGreaterThan(0); expect(preset.watchers[0].name).toEqual('npm-test'); expect(preset.watchers[0].command).toEqual('npm run test'); }); tap.test('ConfigHandler: should return element preset with server', async () => { const configHandler = new tswatch.ConfigHandler(); const preset = configHandler.getPreset('element'); expect(preset).toBeTruthy(); expect(preset.server).toBeTruthy(); expect(preset.server.enabled).toBeTrue(); expect(preset.server.port).toEqual(3002); expect(preset.bundles).toBeTruthy(); expect(preset.bundles.length).toBeGreaterThan(0); }); tap.test('ConfigHandler: should return null for invalid preset', async () => { const configHandler = new tswatch.ConfigHandler(); const preset = configHandler.getPreset('invalid'); expect(preset).toBeNull(); }); tap.test('ConfigHandler: should return correct config key', async () => { const configHandler = new tswatch.ConfigHandler(); expect(configHandler.getConfigKey()).toEqual('@git.zone/tswatch'); }); // ============================================ // Watcher Tests // ============================================ tap.test('Watcher: should create from config with defaults', async () => { const watcher = tswatch.Watcher.fromConfig({ name: 'test-watcher', watch: './ts/**/*', command: 'echo test', }); expect(watcher).toBeInstanceOf(tswatch.Watcher); }); tap.test('Watcher: should handle array watch patterns', async () => { const watcher = tswatch.Watcher.fromConfig({ name: 'multi-watch', watch: ['./ts/**/*', './test/**/*'], command: 'echo test', }); expect(watcher).toBeInstanceOf(tswatch.Watcher); }); // ============================================ // TsWatch Tests // ============================================ let testTsWatch: tswatch.TsWatch; tap.test('TsWatch: should create with minimal config', async () => { testTsWatch = new tswatch.TsWatch({ watchers: [ { name: 'echo-test', watch: './ts/**/*', command: 'echo "test"', runOnStart: false, }, ], }); expect(testTsWatch).toBeInstanceOf(tswatch.TsWatch); expect(testTsWatch.config.watchers).toBeTruthy(); expect(testTsWatch.config.watchers.length).toEqual(1); }); tap.test('TsWatch: should start and populate watcherMap', async () => { await testTsWatch.start(); expect(testTsWatch.watcherMap.getArray().length).toBeGreaterThan(0); }); tap.test('TsWatch: should stop cleanly', async (tools) => { await tools.delayFor(500); await testTsWatch.stop(); }); export default tap.start();