|
1 | | -import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; |
2 | 1 | import type { TFile } from 'obsidian'; |
| 2 | +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
| 3 | +import { itPerf } from '../../tests/perfUtils'; |
3 | 4 | import { log } from '../logger/logManager'; |
4 | 5 |
|
5 | 6 | // Mock logger to capture error messages |
@@ -179,16 +180,24 @@ describe('Template Property Types Feature Flag & Edge Cases', () => { |
179 | 180 | // Create large array |
180 | 181 | const largeArray = new Array(10000).fill(0).map((_, i) => ({ id: i, data: `item-${i}` })); |
181 | 182 | formatter.setVariable('bigData', largeArray); |
182 | | - |
| 183 | + |
| 184 | + formatter.formatContent('items: {{bigData}}'); |
| 185 | + |
| 186 | + const vars = formatter.getAndClearTemplatePropertyVars(); |
| 187 | + expect(vars.get('items')).toBe(largeArray); |
| 188 | + }); |
| 189 | + |
| 190 | + itPerf('formats very large data structures within budget', () => { |
| 191 | + const formatter = new TestFormatter(mockApp, mockPlugin); |
| 192 | + |
| 193 | + const largeArray = new Array(10000).fill(0).map((_, i) => ({ id: i, data: `item-${i}` })); |
| 194 | + formatter.setVariable('bigData', largeArray); |
| 195 | + |
183 | 196 | const start = performance.now(); |
184 | 197 | formatter.formatContent('items: {{bigData}}'); |
185 | 198 | const duration = performance.now() - start; |
186 | 199 |
|
187 | | - // Should complete within reasonable time (< 1 second) |
188 | 200 | expect(duration).toBeLessThan(1000); |
189 | | - |
190 | | - const vars = formatter.getAndClearTemplatePropertyVars(); |
191 | | - expect(vars.get('items')).toBe(largeArray); |
192 | 201 | }); |
193 | 202 |
|
194 | 203 | it('should handle undefined and null values properly', () => { |
@@ -329,18 +338,34 @@ describe('Template Property Types Feature Flag & Edge Cases', () => { |
329 | 338 | template += `prop${i}: {{var${i}}}\n`; |
330 | 339 | } |
331 | 340 |
|
332 | | - const start = performance.now(); |
333 | 341 | formatter.formatContent(template); |
334 | 342 | const vars = formatter.getAndClearTemplatePropertyVars(); |
335 | | - const duration = performance.now() - start; |
336 | 343 |
|
337 | 344 | expect(vars.size).toBe(1000); |
338 | | - expect(duration).toBeLessThan(2000); // Should complete within 2 seconds |
339 | 345 |
|
340 | 346 | // After clearing, should be empty |
341 | 347 | const clearedVars = formatter.getAndClearTemplatePropertyVars(); |
342 | 348 | expect(clearedVars.size).toBe(0); |
343 | 349 | }); |
| 350 | + |
| 351 | + itPerf('formats large variable maps within budget', () => { |
| 352 | + const formatter = new TestFormatter(mockApp, mockPlugin); |
| 353 | + |
| 354 | + for (let i = 0; i < 1000; i++) { |
| 355 | + formatter.setVariable(`var${i}`, { data: `value${i}` }); |
| 356 | + } |
| 357 | + |
| 358 | + let template = ''; |
| 359 | + for (let i = 0; i < 1000; i++) { |
| 360 | + template += `prop${i}: {{var${i}}}\n`; |
| 361 | + } |
| 362 | + |
| 363 | + const start = performance.now(); |
| 364 | + formatter.formatContent(template); |
| 365 | + const duration = performance.now() - start; |
| 366 | + |
| 367 | + expect(duration).toBeLessThan(2000); |
| 368 | + }); |
344 | 369 | }); |
345 | 370 | }); |
346 | 371 |
|
|
0 commit comments