-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from time-loop/mike-m/add-test-data-to-repo
chore(fields): add pregenerated test data
- Loading branch information
Showing
6 changed files
with
118 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,5 @@ jobs: | |
run: npm run lint | ||
- name: Build and Test | ||
run: | | ||
npm run test:generate | ||
npm run test | ||
npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** @type {import('jest').Config} */ | ||
const config = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
setupFilesAfterEnv: ['./test/jest.setup.js'], | ||
transform: { | ||
'^.+\\.[tj]s$': 'ts-jest', | ||
}, | ||
transformIgnorePatterns: ['^.+/.js$'], | ||
testRegex: '/test/unit/clickup/clickupFieldsDependencyTracker.perf.test.ts$', | ||
testPathIgnorePatterns: ['/node_modules/', '/dist/', '/test/_utils/', '/test/scripts', '/test/jest.setup.js'], | ||
collectCoverageFrom: ['**/*.[tj]s', '!src/grammar-parser/**'], | ||
}; | ||
|
||
process.env.TZ = 'UTC'; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
test/unit/clickup/clickupFieldsDependencyTracker.perf.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { ClickUpFieldsDependencyTracker } from '../../../src'; | ||
import { ClickUpParserVariable } from '../../../src/clickup/clickupParserVariable'; | ||
|
||
describe('ClickupFieldsDependencyTracker', () => { | ||
describe('performance tests', () => { | ||
interface AugmentedTracker { | ||
getDependencyGraph(): unknown; | ||
} | ||
|
||
const filePath = path.join(process.cwd(), 'test', 'data', 'test_custom_fields.json'); | ||
const data = fs.readFileSync(filePath, 'utf-8'); | ||
const variables = JSON.parse(data); | ||
|
||
function getVariables(): ClickUpParserVariable[] { | ||
return [...variables]; | ||
} | ||
|
||
function getRandomSample<T>(arr: T[], sampleSize: number): T[] { | ||
if (sampleSize > arr.length) { | ||
throw new Error('Sample size cannot be larger than the array size.'); | ||
} | ||
|
||
// Create a copy of the array to avoid modifying the original array | ||
const arrayCopy = arr.slice(); | ||
|
||
// Fisher-Yates shuffle, optimized to shuffle only up to sampleSize | ||
for (let i = 0; i < sampleSize; i++) { | ||
const j = Math.floor(Math.random() * (arr.length - i)) + i; | ||
[arrayCopy[i], arrayCopy[j]] = [arrayCopy[j], arrayCopy[i]]; | ||
} | ||
// Return the first N elements of the shuffled array | ||
return arrayCopy.slice(0, sampleSize); | ||
} | ||
it('graph creation should be fast enough', () => { | ||
const start = performance.now(); | ||
const iterations = 10; | ||
for (let i = 0; i < iterations; i++) { | ||
const variables = getVariables(); | ||
const tracker = new ClickUpFieldsDependencyTracker(variables) as unknown as AugmentedTracker; | ||
const graph = tracker.getDependencyGraph(); | ||
expect(graph).toBeDefined(); | ||
} | ||
const timeAverage = (performance.now() - start) / iterations; | ||
|
||
expect(timeAverage).toBeLessThan(250); | ||
console.log(`Graph creation for ${variables.length} variables (average time): ${timeAverage} ms`); | ||
}); | ||
|
||
it('dependencies validation should be fast enough', () => { | ||
const variables = getVariables(); | ||
const validator = new ClickUpFieldsDependencyTracker(variables); | ||
{ | ||
// initialze the graph outside of the measurement | ||
const augmented = validator as unknown as AugmentedTracker; | ||
augmented.getDependencyGraph(); | ||
} | ||
|
||
const start = performance.now(); | ||
const iterations = 100; | ||
for (let i = 0; i < iterations; i++) { | ||
validator.validate(); | ||
} | ||
const time = (performance.now() - start) / iterations; | ||
|
||
expect(time).toBeLessThan(250); | ||
console.log(`Dependencies validation for ${variables.length} variables (average time): ${time} ms`); | ||
}); | ||
|
||
it('fetching dependants should be fast enough', () => { | ||
const variables = getVariables(); | ||
const tracker = new ClickUpFieldsDependencyTracker(variables); | ||
{ | ||
// initialze the graph outside of the measurement | ||
const augmented = tracker as unknown as AugmentedTracker; | ||
augmented.getDependencyGraph(); | ||
} | ||
|
||
const varsSample = getRandomSample(variables, 1000); | ||
const start = performance.now(); | ||
for (const variable of varsSample) { | ||
tracker.getDependentFields(variable.name); | ||
} | ||
const time = (performance.now() - start) / variables.length; | ||
|
||
expect(time).toBeLessThan(250); | ||
console.log(`Fetching dependants for ${variables.length} variables (average time): ${time} ms`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters