|
1 | 1 | import { describe, it, expect } from 'vitest'; |
2 | 2 | import { Tidewave } from '../src/index'; |
3 | | -import { isExtractError, isResolveError, type EvaluationRequest } from '../src/core'; |
| 3 | +import { |
| 4 | + isExtractError, |
| 5 | + isResolveError, |
| 6 | + type EvaluationRequest, |
| 7 | + type ResolvedModule, |
| 8 | + type SymbolInfo, |
| 9 | +} from '../src/core'; |
4 | 10 |
|
5 | 11 | describe('Integration Tests', () => { |
6 | 12 | describe('JavaScript Files', () => { |
7 | 13 | it('should extract function from CommonJS export', async () => { |
8 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.js:greetUser'); |
9 | | - |
10 | | - expect(isExtractError(result)).toBe(false); |
11 | | - if (!isExtractError(result)) { |
12 | | - expect(result.name).toBe('greetUser'); |
13 | | - expect(result.kind).toBe('function'); |
14 | | - expect(result.documentation).toContain('A sample function for testing'); |
15 | | - expect(result.jsDoc).toContain('@param name'); |
16 | | - expect(result.jsDoc).toContain('@returns A greeting message'); |
17 | | - expect(result.location).toContain('sample.js'); |
18 | | - } |
| 14 | + const result = (await Tidewave.extractDocs( |
| 15 | + './test/fixtures/sample.js:greetUser', |
| 16 | + )) as SymbolInfo; |
| 17 | + |
| 18 | + expect(result.name).toBe('greetUser'); |
| 19 | + expect(result.kind).toBe('function'); |
| 20 | + expect(result.documentation).toContain('A sample function for testing'); |
| 21 | + expect(result.jsDoc).toContain('@param name'); |
| 22 | + expect(result.jsDoc).toContain('@returns A greeting message'); |
| 23 | + expect(result.location).toContain('sample.js'); |
19 | 24 | }); |
20 | 25 |
|
21 | 26 | it('should extract class from CommonJS export', async () => { |
22 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.js:TestClass'); |
23 | | - |
24 | | - expect(isExtractError(result)).toBe(false); |
25 | | - if (!isExtractError(result)) { |
26 | | - expect(result.name).toBe('TestClass'); |
27 | | - expect(result.kind).toBe('class'); |
28 | | - expect(result.documentation).toContain('A sample class for testing'); |
29 | | - expect(result.location).toContain('sample.js'); |
30 | | - } |
| 27 | + const result = (await Tidewave.extractDocs( |
| 28 | + './test/fixtures/sample.js:TestClass', |
| 29 | + )) as SymbolInfo; |
| 30 | + |
| 31 | + expect(result.name).toBe('TestClass'); |
| 32 | + expect(result.kind).toBe('class'); |
| 33 | + expect(result.documentation).toContain('A sample class for testing'); |
| 34 | + expect(result.location).toContain('sample.js'); |
31 | 35 | }); |
32 | 36 |
|
33 | 37 | it('should extract instance method from JavaScript class', async () => { |
34 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.js:TestClass#getValue'); |
35 | | - |
36 | | - expect(isExtractError(result)).toBe(false); |
37 | | - if (!isExtractError(result)) { |
38 | | - expect(result.name).toBe('TestClass#getValue'); |
39 | | - expect(result.kind).toBe('method'); |
40 | | - expect(result.documentation).toContain('Get the value'); |
41 | | - expect(result.jsDoc).toContain('@returns The current value'); |
42 | | - } |
| 38 | + const result = (await Tidewave.extractDocs( |
| 39 | + './test/fixtures/sample.js:TestClass#getValue', |
| 40 | + )) as SymbolInfo; |
| 41 | + |
| 42 | + expect(result.name).toBe('TestClass#getValue'); |
| 43 | + expect(result.kind).toBe('method'); |
| 44 | + expect(result.documentation).toContain('Get the value'); |
| 45 | + expect(result.jsDoc).toContain('@returns The current value'); |
43 | 46 | }); |
44 | 47 |
|
45 | 48 | it('should extract static method from JavaScript class', async () => { |
46 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.js:TestClass.create'); |
47 | | - |
48 | | - expect(isExtractError(result)).toBe(false); |
49 | | - if (!isExtractError(result)) { |
50 | | - expect(result.name).toBe('TestClass.create'); |
51 | | - expect(result.kind).toBe('method'); |
52 | | - expect(result.documentation).toContain('Static factory method'); |
53 | | - expect(result.jsDoc).toContain('@returns New instance'); |
54 | | - } |
| 49 | + const result = (await Tidewave.extractDocs( |
| 50 | + './test/fixtures/sample.js:TestClass.create', |
| 51 | + )) as SymbolInfo; |
| 52 | + |
| 53 | + expect(result.name).toBe('TestClass.create'); |
| 54 | + expect(result.kind).toBe('method'); |
| 55 | + expect(result.documentation).toContain('Static factory method'); |
| 56 | + expect(result.jsDoc).toContain('@returns New instance'); |
55 | 57 | }); |
56 | 58 | }); |
57 | 59 |
|
58 | 60 | describe('TypeScript Files', () => { |
59 | 61 | it('should extract interface from TypeScript export', async () => { |
60 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.ts:User'); |
61 | | - |
62 | | - expect(isExtractError(result)).toBe(false); |
63 | | - if (!isExtractError(result)) { |
64 | | - expect(result.name).toBe('User'); |
65 | | - expect(result.kind).toBe('interface'); |
66 | | - expect(result.documentation).toContain('A sample TypeScript interface'); |
67 | | - expect(result.location).toContain('sample.ts'); |
68 | | - } |
| 62 | + const result = (await Tidewave.extractDocs('./test/fixtures/sample.ts:User')) as SymbolInfo; |
| 63 | + |
| 64 | + expect(result.name).toBe('User'); |
| 65 | + expect(result.kind).toBe('interface'); |
| 66 | + expect(result.documentation).toContain('A sample TypeScript interface'); |
| 67 | + expect(result.location).toContain('sample.ts'); |
69 | 68 | }); |
70 | 69 |
|
71 | 70 | it('should extract class from TypeScript export', async () => { |
72 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.ts:UserManager'); |
73 | | - |
74 | | - expect(isExtractError(result)).toBe(false); |
75 | | - if (!isExtractError(result)) { |
76 | | - expect(result.name).toBe('UserManager'); |
77 | | - expect(result.kind).toBe('class'); |
78 | | - expect(result.documentation).toContain('A sample TypeScript class'); |
79 | | - } |
| 71 | + const result = (await Tidewave.extractDocs( |
| 72 | + './test/fixtures/sample.ts:UserManager', |
| 73 | + )) as SymbolInfo; |
| 74 | + |
| 75 | + expect(result.name).toBe('UserManager'); |
| 76 | + expect(result.kind).toBe('class'); |
| 77 | + expect(result.documentation).toContain('A sample TypeScript class'); |
80 | 78 | }); |
81 | 79 |
|
82 | 80 | it('should extract instance method from TypeScript class', async () => { |
83 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.ts:UserManager#addUser'); |
84 | | - |
85 | | - expect(isExtractError(result)).toBe(false); |
86 | | - if (!isExtractError(result)) { |
87 | | - expect(result.name).toBe('UserManager#addUser'); |
88 | | - expect(result.kind).toBe('method'); |
89 | | - expect(result.documentation).toContain('Add a user'); |
90 | | - } |
| 81 | + const result = (await Tidewave.extractDocs( |
| 82 | + './test/fixtures/sample.ts:UserManager#addUser', |
| 83 | + )) as SymbolInfo; |
| 84 | + |
| 85 | + expect(result.name).toBe('UserManager#addUser'); |
| 86 | + expect(result.kind).toBe('method'); |
| 87 | + expect(result.documentation).toContain('Add a user'); |
91 | 88 | }); |
92 | 89 |
|
93 | 90 | it('should extract static method from TypeScript class', async () => { |
94 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.ts:UserManager.create'); |
95 | | - |
96 | | - expect(isExtractError(result)).toBe(false); |
97 | | - if (!isExtractError(result)) { |
98 | | - expect(result.name).toBe('UserManager.create'); |
99 | | - expect(result.kind).toBe('method'); |
100 | | - expect(result.documentation).toContain('Static factory method'); |
101 | | - } |
| 91 | + const result = (await Tidewave.extractDocs( |
| 92 | + './test/fixtures/sample.ts:UserManager.create', |
| 93 | + )) as SymbolInfo; |
| 94 | + |
| 95 | + expect(result.name).toBe('UserManager.create'); |
| 96 | + expect(result.kind).toBe('method'); |
| 97 | + expect(result.documentation).toContain('Static factory method'); |
102 | 98 | }); |
103 | 99 |
|
104 | 100 | it('should extract generic function', async () => { |
105 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.ts:processItems'); |
106 | | - |
107 | | - expect(isExtractError(result)).toBe(false); |
108 | | - if (!isExtractError(result)) { |
109 | | - expect(result.name).toBe('processItems'); |
110 | | - expect(result.kind).toBe('function'); |
111 | | - expect(result.documentation).toContain('Sample utility function'); |
112 | | - expect(result.signature).toContain('processItems'); |
113 | | - } |
| 101 | + const result = (await Tidewave.extractDocs( |
| 102 | + './test/fixtures/sample.ts:processItems', |
| 103 | + )) as SymbolInfo; |
| 104 | + |
| 105 | + expect(result.name).toBe('processItems'); |
| 106 | + expect(result.kind).toBe('function'); |
| 107 | + expect(result.documentation).toContain('Sample utility function'); |
| 108 | + expect(result.signature).toContain('processItems'); |
114 | 109 | }); |
115 | 110 | }); |
116 | 111 |
|
117 | 112 | describe('Source Path Resolution', () => { |
118 | 113 | it('should resolve JavaScript file path', async () => { |
119 | | - const sourcePath = await Tidewave.getSourceLocation('./test/fixtures/sample.js'); |
| 114 | + const sourcePath = (await Tidewave.getSourceLocation( |
| 115 | + './test/fixtures/sample.js', |
| 116 | + )) as ResolvedModule; |
120 | 117 |
|
121 | | - expect(isResolveError(sourcePath)).toBe(false); |
122 | | - if (!isResolveError(sourcePath)) { |
123 | | - expect(sourcePath.path).toContain('test/fixtures/sample.js'); |
124 | | - } |
| 118 | + expect(sourcePath.path).toContain('test/fixtures/sample.js'); |
125 | 119 | }); |
126 | 120 |
|
127 | 121 | it('should resolve TypeScript file path', async () => { |
128 | | - const sourcePath = await Tidewave.getSourceLocation('./test/fixtures/sample.ts'); |
| 122 | + const sourcePath = (await Tidewave.getSourceLocation( |
| 123 | + './test/fixtures/sample.ts', |
| 124 | + )) as ResolvedModule; |
129 | 125 |
|
130 | | - expect(isResolveError(sourcePath)).toBe(false); |
131 | | - if (!isResolveError(sourcePath)) { |
132 | | - expect(sourcePath.path).toContain('test/fixtures/sample.ts'); |
133 | | - } |
| 126 | + expect(sourcePath.path).toContain('test/fixtures/sample.ts'); |
134 | 127 | }); |
135 | 128 |
|
136 | 129 | it('should resolve node_modules dependency', async () => { |
137 | | - const sourcePath = await Tidewave.getSourceLocation('typescript'); |
| 130 | + const sourcePath = (await Tidewave.getSourceLocation('typescript')) as ResolvedModule; |
138 | 131 |
|
139 | | - expect(isResolveError(sourcePath)).toBe(false); |
140 | | - if (!isResolveError(sourcePath)) { |
141 | | - expect(sourcePath.path).toMatch(/typescript.*\.d\.ts$/); |
142 | | - } |
| 132 | + expect(sourcePath.path).toMatch(/typescript.*\.d\.ts$/); |
143 | 133 | }); |
144 | 134 | }); |
145 | 135 |
|
146 | 136 | describe('Builtin Modules', () => { |
147 | 137 | it('should extract Math global', async () => { |
148 | | - const result = await Tidewave.extractDocs('node:Math'); |
149 | | - |
150 | | - expect(isExtractError(result)).toBe(false); |
151 | | - if (!isExtractError(result)) { |
152 | | - expect(result.name).toBe('Math'); |
153 | | - expect(result.kind).toBe('interface'); |
154 | | - expect(result.documentation).toContain('mathematics functionality'); |
155 | | - } |
| 138 | + const result = (await Tidewave.extractDocs('node:Math')) as SymbolInfo; |
| 139 | + |
| 140 | + expect(result.name).toBe('Math'); |
| 141 | + expect(result.kind).toBe('interface'); |
| 142 | + expect(result.documentation).toContain('mathematics functionality'); |
156 | 143 | }); |
157 | 144 |
|
158 | 145 | it('should extract Math.max static method', async () => { |
159 | | - const result = await Tidewave.extractDocs('node:Math.max'); |
160 | | - |
161 | | - expect(isExtractError(result)).toBe(false); |
162 | | - if (!isExtractError(result)) { |
163 | | - expect(result.name).toBe('Math.max'); |
164 | | - expect(result.kind).toBe('method'); |
165 | | - expect(result.documentation).toContain('Returns the larger of a set'); |
166 | | - expect(result.signature).toContain('(...values: number[]): number'); |
167 | | - } |
| 146 | + const result = (await Tidewave.extractDocs('node:Math.max')) as SymbolInfo; |
| 147 | + |
| 148 | + expect(result.name).toBe('Math.max'); |
| 149 | + expect(result.kind).toBe('method'); |
| 150 | + expect(result.documentation).toContain('Returns the larger of a set'); |
| 151 | + expect(result.signature).toContain('(...values: number[]): number'); |
168 | 152 | }); |
169 | 153 | }); |
170 | 154 |
|
@@ -198,31 +182,25 @@ describe('Integration Tests', () => { |
198 | 182 |
|
199 | 183 | describe('Output Formatting', () => { |
200 | 184 | it('should format symbol info correctly', async () => { |
201 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.ts:User'); |
202 | | - |
203 | | - expect(isExtractError(result)).toBe(false); |
204 | | - if (!isExtractError(result)) { |
205 | | - const formatted = Tidewave.formatOutput(result); |
206 | | - |
207 | | - expect(formatted).toContain('User'); |
208 | | - expect(formatted).toContain('Kind: interface'); |
209 | | - expect(formatted).toContain('Location:'); |
210 | | - expect(formatted).toContain('Type:'); |
211 | | - expect(formatted).toContain('Documentation:'); |
212 | | - } |
| 185 | + const result = (await Tidewave.extractDocs('./test/fixtures/sample.ts:User')) as SymbolInfo; |
| 186 | + |
| 187 | + const formatted = Tidewave.formatOutput(result); |
| 188 | + expect(formatted).toContain('User'); |
| 189 | + expect(formatted).toContain('Kind: interface'); |
| 190 | + expect(formatted).toContain('Location:'); |
| 191 | + expect(formatted).toContain('Type:'); |
| 192 | + expect(formatted).toContain('Documentation:'); |
213 | 193 | }); |
214 | 194 |
|
215 | 195 | it('should format function with signature', async () => { |
216 | | - const result = await Tidewave.extractDocs('./test/fixtures/sample.ts:processItems'); |
217 | | - |
218 | | - expect(isExtractError(result)).toBe(false); |
219 | | - if (!isExtractError(result)) { |
220 | | - const formatted = Tidewave.formatOutput(result); |
221 | | - |
222 | | - expect(formatted).toContain('processItems'); |
223 | | - expect(formatted).toContain('Signature:'); |
224 | | - expect(formatted).toContain('processItems'); |
225 | | - } |
| 196 | + const result = (await Tidewave.extractDocs( |
| 197 | + './test/fixtures/sample.ts:processItems', |
| 198 | + )) as SymbolInfo; |
| 199 | + |
| 200 | + const formatted = Tidewave.formatOutput(result); |
| 201 | + expect(formatted).toContain('processItems'); |
| 202 | + expect(formatted).toContain('Signature:'); |
| 203 | + expect(formatted).toContain('processItems'); |
226 | 204 | }); |
227 | 205 | }); |
228 | 206 | }); |
|
0 commit comments