Skip to content

Commit 9c34e04

Browse files
authored
Merge pull request #27 from time-loop/mike-m/add-test-data-to-repo
chore(fields): add pregenerated test data
2 parents 5928b7f + df57cbe commit 9c34e04

File tree

6 files changed

+118
-90
lines changed

6 files changed

+118
-90
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ jobs:
2020
run: npm run lint
2121
- name: Build and Test
2222
run: |
23-
npm run test:generate
2423
npm run test
2524
npm run build

jest-perf.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @type {import('jest').Config} */
2+
const config = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
setupFilesAfterEnv: ['./test/jest.setup.js'],
6+
transform: {
7+
'^.+\\.[tj]s$': 'ts-jest',
8+
},
9+
transformIgnorePatterns: ['^.+/.js$'],
10+
testRegex: '/test/unit/clickup/clickupFieldsDependencyTracker.perf.test.ts$',
11+
testPathIgnorePatterns: ['/node_modules/', '/dist/', '/test/_utils/', '/test/scripts', '/test/jest.setup.js'],
12+
collectCoverageFrom: ['**/*.[tj]s', '!src/grammar-parser/**'],
13+
};
14+
15+
process.env.TZ = 'UTC';
16+
17+
module.exports = config;

jest.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ const config = {
88
},
99
testRegex: '(/test/.*.(t|j)s)$',
1010
transformIgnorePatterns: ['^.+/.js$'],
11-
testPathIgnorePatterns: ['/node_modules/', '/dist/', '/test/_utils/', '/test/scripts', '/test/jest.setup.js'],
11+
testPathIgnorePatterns: [
12+
'/node_modules/',
13+
'/dist/',
14+
'/test/_utils/',
15+
'/test/scripts',
16+
'/test/jest.setup.js',
17+
'/test/unit/clickup/clickupFieldsDependencyTracker.perf.test.ts',
18+
],
1219
collectCoverageFrom: ['**/*.[tj]s', '!src/grammar-parser/**'],
1320
};
1421

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"test:clear": "jest --clearCache",
1616
"test": "jest --detectOpenHandles",
1717
"test:coverage": "jest --coverage",
18+
"test:perf": "jest --config=jest-perf.config.js",
1819
"test:generate": "ts-node test/scripts/generatePerfTestData.ts",
1920
"build": "tsc",
2021
"generate-parser": "cd src/grammar-parser && jison grammar-parser.jison",
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { ClickUpFieldsDependencyTracker } from '../../../src';
4+
import { ClickUpParserVariable } from '../../../src/clickup/clickupParserVariable';
5+
6+
describe('ClickupFieldsDependencyTracker', () => {
7+
describe('performance tests', () => {
8+
interface AugmentedTracker {
9+
getDependencyGraph(): unknown;
10+
}
11+
12+
const filePath = path.join(process.cwd(), 'test', 'data', 'test_custom_fields.json');
13+
const data = fs.readFileSync(filePath, 'utf-8');
14+
const variables = JSON.parse(data);
15+
16+
function getVariables(): ClickUpParserVariable[] {
17+
return [...variables];
18+
}
19+
20+
function getRandomSample<T>(arr: T[], sampleSize: number): T[] {
21+
if (sampleSize > arr.length) {
22+
throw new Error('Sample size cannot be larger than the array size.');
23+
}
24+
25+
// Create a copy of the array to avoid modifying the original array
26+
const arrayCopy = arr.slice();
27+
28+
// Fisher-Yates shuffle, optimized to shuffle only up to sampleSize
29+
for (let i = 0; i < sampleSize; i++) {
30+
const j = Math.floor(Math.random() * (arr.length - i)) + i;
31+
[arrayCopy[i], arrayCopy[j]] = [arrayCopy[j], arrayCopy[i]];
32+
}
33+
// Return the first N elements of the shuffled array
34+
return arrayCopy.slice(0, sampleSize);
35+
}
36+
it('graph creation should be fast enough', () => {
37+
const start = performance.now();
38+
const iterations = 10;
39+
for (let i = 0; i < iterations; i++) {
40+
const variables = getVariables();
41+
const tracker = new ClickUpFieldsDependencyTracker(variables) as unknown as AugmentedTracker;
42+
const graph = tracker.getDependencyGraph();
43+
expect(graph).toBeDefined();
44+
}
45+
const timeAverage = (performance.now() - start) / iterations;
46+
47+
expect(timeAverage).toBeLessThan(250);
48+
console.log(`Graph creation for ${variables.length} variables (average time): ${timeAverage} ms`);
49+
});
50+
51+
it('dependencies validation should be fast enough', () => {
52+
const variables = getVariables();
53+
const validator = new ClickUpFieldsDependencyTracker(variables);
54+
{
55+
// initialze the graph outside of the measurement
56+
const augmented = validator as unknown as AugmentedTracker;
57+
augmented.getDependencyGraph();
58+
}
59+
60+
const start = performance.now();
61+
const iterations = 100;
62+
for (let i = 0; i < iterations; i++) {
63+
validator.validate();
64+
}
65+
const time = (performance.now() - start) / iterations;
66+
67+
expect(time).toBeLessThan(250);
68+
console.log(`Dependencies validation for ${variables.length} variables (average time): ${time} ms`);
69+
});
70+
71+
it('fetching dependants should be fast enough', () => {
72+
const variables = getVariables();
73+
const tracker = new ClickUpFieldsDependencyTracker(variables);
74+
{
75+
// initialze the graph outside of the measurement
76+
const augmented = tracker as unknown as AugmentedTracker;
77+
augmented.getDependencyGraph();
78+
}
79+
80+
const varsSample = getRandomSample(variables, 1000);
81+
const start = performance.now();
82+
for (const variable of varsSample) {
83+
tracker.getDependentFields(variable.name);
84+
}
85+
const time = (performance.now() - start) / variables.length;
86+
87+
expect(time).toBeLessThan(250);
88+
console.log(`Fetching dependants for ${variables.length} variables (average time): ${time} ms`);
89+
});
90+
});
91+
});
Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import fs from 'fs';
2-
import path from 'path';
31
import { ClickUpFieldsDependencyTracker } from '../../../src/clickup/clickupFieldsDependencyTracker';
4-
import { ClickUpParserVariable, createClickUpParserVariable } from '../../../src/clickup/clickupParserVariable';
2+
import { createClickUpParserVariable } from '../../../src/clickup/clickupParserVariable';
53

64
describe('clickupFieldsValidator', () => {
75
const createName = (id: string) => `CUSTOM_FIELD_${id}`;
@@ -87,89 +85,4 @@ describe('clickupFieldsValidator', () => {
8785
}),
8886
});
8987
});
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-
});
17588
});

0 commit comments

Comments
 (0)