|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.dev/license |
| 7 | + */ |
| 8 | + |
| 9 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 10 | +import { Schema as ApplicationOptions } from '../application/schema'; |
| 11 | +import { Schema as WorkspaceOptions } from '../workspace/schema'; |
| 12 | +import { Schema as ConfigOptions, Tool as ConfigTool } from './schema'; |
| 13 | + |
| 14 | +describe('Ai Config Schematic', () => { |
| 15 | + const schematicRunner = new SchematicTestRunner( |
| 16 | + '@schematics/angular', |
| 17 | + require.resolve('../collection.json'), |
| 18 | + ); |
| 19 | + |
| 20 | + const workspaceOptions: WorkspaceOptions = { |
| 21 | + name: 'workspace', |
| 22 | + newProjectRoot: 'projects', |
| 23 | + version: '15.0.0', |
| 24 | + }; |
| 25 | + |
| 26 | + const defaultAppOptions: ApplicationOptions = { |
| 27 | + name: 'foo', |
| 28 | + inlineStyle: true, |
| 29 | + inlineTemplate: true, |
| 30 | + routing: false, |
| 31 | + skipPackageJson: false, |
| 32 | + }; |
| 33 | + |
| 34 | + let applicationTree: UnitTestTree; |
| 35 | + function runConfigSchematic(tool: ConfigTool[]): Promise<UnitTestTree> { |
| 36 | + return schematicRunner.runSchematic<ConfigOptions>( |
| 37 | + 'ai-config', |
| 38 | + { |
| 39 | + project: 'foo', |
| 40 | + tool, |
| 41 | + }, |
| 42 | + applicationTree, |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + beforeEach(async () => { |
| 47 | + const workspaceTree = await schematicRunner.runSchematic('workspace', workspaceOptions); |
| 48 | + applicationTree = await schematicRunner.runSchematic( |
| 49 | + 'application', |
| 50 | + defaultAppOptions, |
| 51 | + workspaceTree, |
| 52 | + ); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should create a GEMINI.MD file', async () => { |
| 56 | + const tree = await runConfigSchematic([ConfigTool.Gemini]); |
| 57 | + expect(tree.readContent('.gemini/GEMINI.md')).toMatch(/^You are an expert in TypeScript/); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should create a copilot-instructions.md file', async () => { |
| 61 | + const tree = await runConfigSchematic([ConfigTool.Copilot]); |
| 62 | + expect(tree.readContent('.github/copilot-instructions.md')).toContain( |
| 63 | + 'You are an expert in TypeScript', |
| 64 | + ); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should create a cursor file', async () => { |
| 68 | + const tree = await runConfigSchematic([ConfigTool.Cursor]); |
| 69 | + const cursorFile = tree.readContent('.cursor/rules/cursor.mdc'); |
| 70 | + expect(cursorFile).toContain('You are an expert in TypeScript'); |
| 71 | + expect(cursorFile).toContain('context: true'); |
| 72 | + expect(cursorFile).toContain('---\n\nYou are an expert in TypeScript'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should create a windsurf file', async () => { |
| 76 | + const tree = await runConfigSchematic([ConfigTool.Windsurf]); |
| 77 | + expect(tree.readContent('.windsurf/rules/guidelines.md')).toContain( |
| 78 | + 'You are an expert in TypeScript', |
| 79 | + ); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should create a claude file', async () => { |
| 83 | + const tree = await runConfigSchematic([ConfigTool.Claude]); |
| 84 | + expect(tree.readContent('.claude/CLAUDE.md')).toContain('You are an expert in TypeScript'); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should create multiple files when multiple tools are selected', async () => { |
| 88 | + const tree = await runConfigSchematic([ |
| 89 | + ConfigTool.Gemini, |
| 90 | + ConfigTool.Copilot, |
| 91 | + ConfigTool.Cursor, |
| 92 | + ]); |
| 93 | + expect(tree.readContent('.gemini/GEMINI.md').length).toBeGreaterThan(0); |
| 94 | + expect(tree.readContent('.github/copilot-instructions.md').length).toBeGreaterThan(0); |
| 95 | + expect(tree.readContent('.cursor/rules/cursor.mdc').length).toBeGreaterThan(0); |
| 96 | + }); |
| 97 | +}); |
0 commit comments