|
1 | | -import fs from 'fs'; |
2 | | -import path from 'path'; |
3 | 1 | import { ClickUpFieldsDependencyTracker } from '../../../src/clickup/clickupFieldsDependencyTracker'; |
4 | | -import { ClickUpParserVariable, createClickUpParserVariable } from '../../../src/clickup/clickupParserVariable'; |
| 2 | +import { createClickUpParserVariable } from '../../../src/clickup/clickupParserVariable'; |
5 | 3 |
|
6 | 4 | describe('clickupFieldsValidator', () => { |
7 | 5 | const createName = (id: string) => `CUSTOM_FIELD_${id}`; |
@@ -87,89 +85,4 @@ describe('clickupFieldsValidator', () => { |
87 | 85 | }), |
88 | 86 | }); |
89 | 87 | }); |
90 | | - |
91 | | - describe('performance tests', () => { |
92 | | - interface AugmentedTracker { |
93 | | - getDependencyGraph(): unknown; |
94 | | - } |
95 | | - |
96 | | - const filePath = path.join(process.cwd(), 'test', 'data', 'test_custom_fields.json'); |
97 | | - const data = fs.readFileSync(filePath, 'utf-8'); |
98 | | - const variables = JSON.parse(data); |
99 | | - |
100 | | - function getVariables(): ClickUpParserVariable[] { |
101 | | - return [...variables]; |
102 | | - } |
103 | | - |
104 | | - function getRandomSample<T>(arr: T[], sampleSize: number): T[] { |
105 | | - if (sampleSize > arr.length) { |
106 | | - throw new Error('Sample size cannot be larger than the array size.'); |
107 | | - } |
108 | | - |
109 | | - // Create a copy of the array to avoid modifying the original array |
110 | | - const arrayCopy = arr.slice(); |
111 | | - |
112 | | - // Fisher-Yates shuffle, optimized to shuffle only up to sampleSize |
113 | | - for (let i = 0; i < sampleSize; i++) { |
114 | | - const j = Math.floor(Math.random() * (arr.length - i)) + i; |
115 | | - [arrayCopy[i], arrayCopy[j]] = [arrayCopy[j], arrayCopy[i]]; |
116 | | - } |
117 | | - // Return the first N elements of the shuffled array |
118 | | - return arrayCopy.slice(0, sampleSize); |
119 | | - } |
120 | | - it('graph creation should be fast enough', () => { |
121 | | - const start = performance.now(); |
122 | | - const iterations = 10; |
123 | | - for (let i = 0; i < iterations; i++) { |
124 | | - const variables = getVariables(); |
125 | | - const tracker = new ClickUpFieldsDependencyTracker(variables) as unknown as AugmentedTracker; |
126 | | - const graph = tracker.getDependencyGraph(); |
127 | | - expect(graph).toBeDefined(); |
128 | | - } |
129 | | - const timeAverage = (performance.now() - start) / iterations; |
130 | | - |
131 | | - expect(timeAverage).toBeLessThan(250); |
132 | | - console.log(`Graph creation for ${variables.length} variables (average time): ${timeAverage} ms`); |
133 | | - }); |
134 | | - |
135 | | - it('dependencies validation should be fast enough', () => { |
136 | | - const variables = getVariables(); |
137 | | - const validator = new ClickUpFieldsDependencyTracker(variables); |
138 | | - { |
139 | | - // initialze the graph outside of the measurement |
140 | | - const augmented = validator as unknown as AugmentedTracker; |
141 | | - augmented.getDependencyGraph(); |
142 | | - } |
143 | | - |
144 | | - const start = performance.now(); |
145 | | - const iterations = 100; |
146 | | - for (let i = 0; i < iterations; i++) { |
147 | | - validator.validate(); |
148 | | - } |
149 | | - const time = (performance.now() - start) / iterations; |
150 | | - |
151 | | - expect(time).toBeLessThan(250); |
152 | | - console.log(`Dependencies validation for ${variables.length} variables (average time): ${time} ms`); |
153 | | - }); |
154 | | - |
155 | | - it('fetching dependants should be fast enough', () => { |
156 | | - const variables = getVariables(); |
157 | | - const tracker = new ClickUpFieldsDependencyTracker(variables); |
158 | | - { |
159 | | - // initialze the graph outside of the measurement |
160 | | - const augmented = tracker as unknown as AugmentedTracker; |
161 | | - augmented.getDependencyGraph(); |
162 | | - } |
163 | | - |
164 | | - const varsSample = getRandomSample(variables, 1000); |
165 | | - const start = performance.now(); |
166 | | - for (const variable of varsSample) { |
167 | | - tracker.getDependentFields(variable.name); |
168 | | - } |
169 | | - const time = (performance.now() - start) / variables.length; |
170 | | - |
171 | | - expect(time).toBeLessThan(250); |
172 | | - console.log(`Fetching dependants for ${variables.length} variables (average time): ${time} ms`); |
173 | | - }); |
174 | | - }); |
175 | 88 | }); |
0 commit comments