-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV-5579 Use benchmark.js to test performance of fontoxpath with qt3t…
…ests
- Loading branch information
Mehmet Coskun
committed
Apr 15, 2020
1 parent
c6e90d1
commit 46e6cf3
Showing
8 changed files
with
747 additions
and
313 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { evaluateXPathToNodes, evaluateXPathToString, evaluateXPathToFirstNode } from 'fontoxpath'; | ||
|
||
import testFs from './testFs'; | ||
import { | ||
ALL_TESTS_QUERY, | ||
getAllTestSets, | ||
getFile, | ||
unrunnableTestCasesByName, | ||
} from './qt3TestsTools'; | ||
|
||
const PERFORMANCE_TESTS_FILE = 'runnablePerformanceTestNames.csv'; | ||
const DEFAULT_NUMBER_OF_TEST = 50; | ||
|
||
const createNewRunnableTests = (numberOfTest) => { | ||
const allTestSets = getAllTestSets(); | ||
const allTestNames = []; | ||
const newRunnableTests = new Set(); | ||
|
||
for (const testSetFileName of allTestSets) { | ||
const testSet = getFile(testSetFileName); | ||
|
||
// Find all the tests we can run | ||
const testCases = evaluateXPathToNodes(ALL_TESTS_QUERY, testSet); | ||
|
||
for (const testCase of testCases) { | ||
try { | ||
const testName = evaluateXPathToString('./@name', testCase); | ||
|
||
if (unrunnableTestCasesByName[testName]) { | ||
continue; | ||
} | ||
|
||
const assertionNode = evaluateXPathToFirstNode('./result/*', testCase); | ||
const assertionType = assertionNode && (assertionNode as any).localName; | ||
|
||
switch (assertionType) { | ||
case 'assert': | ||
case 'assert-true': | ||
case 'assert-eq': | ||
case 'assert-deep-eq': | ||
case 'assert-empty': | ||
case 'assert-false': | ||
case 'assert-count': | ||
case 'assert-type': | ||
case 'assert-xml': | ||
case 'assert-string-value': | ||
case 'all-of': | ||
case 'any-of': | ||
allTestNames.push(testName); | ||
} | ||
} catch (e) { | ||
// tslint:disable-next-line: no-console | ||
console.error(e); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
while (newRunnableTests.size < numberOfTest) { | ||
const randomTestName = allTestNames[Math.floor(Math.random() * allTestNames.length)]; | ||
newRunnableTests.add(randomTestName); | ||
} | ||
|
||
testFs.writeFileSync(PERFORMANCE_TESTS_FILE, [...newRunnableTests].join('\n')); | ||
}; | ||
|
||
export default function getPerformanceTests() { | ||
const regenerateIndex = process.argv.indexOf('--regenerate'); | ||
if (regenerateIndex !== -1) { | ||
const nextArg = process.argv[regenerateIndex + 1]; | ||
const numberOfTest = nextArg === undefined ? DEFAULT_NUMBER_OF_TEST : parseInt(nextArg, 10); | ||
|
||
if (isNaN(numberOfTest) || numberOfTest < 1) { | ||
throw new Error('The parameter for the number of tests must be a positive number.'); | ||
} | ||
|
||
createNewRunnableTests(numberOfTest); | ||
} | ||
|
||
return testFs.readFileSync(PERFORMANCE_TESTS_FILE).split(/\r?\n/); | ||
} |
Oops, something went wrong.