|
| 1 | +import { readFileSync } from 'node:fs' |
| 2 | +import { resolve } from 'node:path' |
| 3 | +import { describe, expect, it } from 'vitest' |
| 4 | +import { |
| 5 | + Context, |
| 6 | + ifDirective, |
| 7 | + includeDirective, |
| 8 | + MessageDirective, |
| 9 | + theDefineDirective, |
| 10 | +} from '../src' |
| 11 | + |
| 12 | +describe('performance', () => { |
| 13 | + const root = resolve(__dirname, './fixtures') |
| 14 | + |
| 15 | + const context = new Context({ |
| 16 | + directives: [ifDirective, theDefineDirective, includeDirective, MessageDirective], |
| 17 | + cwd: root, |
| 18 | + }) |
| 19 | + |
| 20 | + it.skip('should transform quickly', () => { |
| 21 | + const code = readFileSync(resolve(root, 'include-main.txt'), 'utf-8') |
| 22 | + |
| 23 | + const start = performance.now() |
| 24 | + for (let i = 0; i < 100; i++) { |
| 25 | + context.transform(code, 'test.js') |
| 26 | + } |
| 27 | + const end = performance.now() |
| 28 | + const duration = end - start |
| 29 | + |
| 30 | + // Expect it to take less than 100ms for 100 transforms |
| 31 | + expect(duration).toBeLessThan(100) |
| 32 | + }) |
| 33 | + |
| 34 | + it.skip('should not consume excessive memory', () => { |
| 35 | + const code = readFileSync(resolve(root, 'include-main.txt'), 'utf-8') |
| 36 | + |
| 37 | + const initialMemory = process.memoryUsage().heapUsed |
| 38 | + for (let i = 0; i < 10000; i++) { |
| 39 | + context.transform(code, 'test.js') |
| 40 | + } |
| 41 | + const finalMemory = process.memoryUsage().heapUsed |
| 42 | + const memoryIncrease = finalMemory - initialMemory |
| 43 | + |
| 44 | + // Expect memory increase to be less than 10MB |
| 45 | + expect(memoryIncrease).toBeLessThan(10 * 1024 * 1024) |
| 46 | + }) |
| 47 | +}) |
0 commit comments