Skip to content

Commit 797b6ff

Browse files
committed
test: gate perf tests behind env flag
1 parent 10c0402 commit 797b6ff

File tree

6 files changed

+54
-14
lines changed

6 files changed

+54
-14
lines changed

src/engine/template-property-types-feature-flag.test.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
21
import type { TFile } from 'obsidian';
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3+
import { itPerf } from '../../tests/perfUtils';
34
import { log } from '../logger/logManager';
45

56
// Mock logger to capture error messages
@@ -179,16 +180,24 @@ describe('Template Property Types Feature Flag & Edge Cases', () => {
179180
// Create large array
180181
const largeArray = new Array(10000).fill(0).map((_, i) => ({ id: i, data: `item-${i}` }));
181182
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+
183196
const start = performance.now();
184197
formatter.formatContent('items: {{bigData}}');
185198
const duration = performance.now() - start;
186199

187-
// Should complete within reasonable time (< 1 second)
188200
expect(duration).toBeLessThan(1000);
189-
190-
const vars = formatter.getAndClearTemplatePropertyVars();
191-
expect(vars.get('items')).toBe(largeArray);
192201
});
193202

194203
it('should handle undefined and null values properly', () => {
@@ -329,18 +338,34 @@ describe('Template Property Types Feature Flag & Edge Cases', () => {
329338
template += `prop${i}: {{var${i}}}\n`;
330339
}
331340

332-
const start = performance.now();
333341
formatter.formatContent(template);
334342
const vars = formatter.getAndClearTemplatePropertyVars();
335-
const duration = performance.now() - start;
336343

337344
expect(vars.size).toBe(1000);
338-
expect(duration).toBeLessThan(2000); // Should complete within 2 seconds
339345

340346
// After clearing, should be empty
341347
const clearedVars = formatter.getAndClearTemplatePropertyVars();
342348
expect(clearedVars.size).toBe(0);
343349
});
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+
});
344369
});
345370
});
346371

src/gui/suggesters/FileIndex.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, it, expect, beforeEach, vi } from 'vitest';
2+
import { itPerf } from '../../../tests/perfUtils';
23
import { FileIndex } from './FileIndex';
34
import { normalizeForSearch } from './utils';
45
import type { App, TFile, Vault, MetadataCache, Workspace } from 'obsidian';
@@ -423,7 +424,7 @@ describe('FileIndex', () => {
423424
});
424425

425426
describe('performance', () => {
426-
it.skip('should handle large vaults efficiently', async () => {
427+
itPerf('should handle large vaults efficiently', async () => {
427428
// Mock a large number of files
428429
const mockFiles = Array.from({ length: 1000 }, (_, i) => ({
429430
path: `file-${i}.md`,

src/gui/suggesters/headingSanitizer.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, it, expect } from 'vitest';
2+
import { itPerf } from '../../../tests/perfUtils';
23
import { sanitizeHeading } from './utils';
34

45
describe('sanitizeHeading', () => {
@@ -50,7 +51,7 @@ describe('sanitizeHeading', () => {
5051
});
5152

5253
// Performance test - ensure regex caching works
53-
it('performs well with many calls', () => {
54+
itPerf('performs well with many calls', () => {
5455
const heading = '**Important** [[Note|Alias]] with ![[image.png]]';
5556
const start = performance.now();
5657

src/template-property-types-performance.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, test, expect, beforeEach, vi, type MockedFunction } from 'vitest';
2+
import { describePerf } from '../tests/perfUtils';
23
import type { TFile } from 'obsidian';
34
import type QuickAdd from '../src/main';
45

@@ -177,7 +178,7 @@ class MockTemplateEngine {
177178
}
178179
}
179180

180-
describe('Template Property Types Performance Tests', () => {
181+
describePerf('Template Property Types Performance Tests', () => {
181182
let mockPlugin: QuickAdd;
182183
let mockApp: any;
183184
let templateEngine: MockTemplateEngine;

src/utils/FieldValueDeduplicator.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, it, expect } from "vitest";
2+
import { describePerf } from "../../tests/perfUtils";
23
import { FieldValueDeduplicator } from "./FieldValueDeduplicator";
34

45
describe("FieldValueDeduplicator", () => {
@@ -152,7 +153,7 @@ describe("FieldValueDeduplicator", () => {
152153
});
153154
});
154155

155-
describe("performance with large datasets", () => {
156+
describePerf("performance with large datasets", () => {
156157
it("should handle 1000+ values efficiently", () => {
157158
const values: string[] = [];
158159
for (let i = 0; i < 1000; i++) {
@@ -331,4 +332,4 @@ describe("FieldValueDeduplicator", () => {
331332
expect(result.values).toHaveLength(1);
332333
});
333334
});
334-
});
335+
});

tests/perfUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, it, test } from 'vitest';
2+
3+
const runPerfTests =
4+
process.env.RUN_PERF_TESTS === '1' ||
5+
process.env.RUN_PERF_TESTS === 'true';
6+
7+
const describePerf = runPerfTests ? describe : describe.skip;
8+
const itPerf = runPerfTests ? it : it.skip;
9+
const testPerf = runPerfTests ? test : test.skip;
10+
11+
export { runPerfTests, describePerf, itPerf, testPerf };

0 commit comments

Comments
 (0)