Skip to content

Commit

Permalink
test: Add script for performance measurements for metadata gen
Browse files Browse the repository at this point in the history
  • Loading branch information
maxreichmann committed Jan 8, 2025
1 parent b3450e0 commit a76c203
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
32 changes: 32 additions & 0 deletions scripts/_testPerformance/metadataExtendsResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable no-console */
import {loadApiExtract, ApiExtract} from "../../src/utils/ApiExtract.js";

Check failure on line 2 in scripts/_testPerformance/metadataExtendsResolver.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

'ApiExtract' is defined but never used. Allowed unused vars must match /^_/u

const main = async () => {
try {
const apiExtract = await loadApiExtract();

// Test Case 1: Check if option "backgroundColor" in "sap.m.App" exists
// (DON'T check borrowed ones):
// TODO:

// Test Case 2: Check if option "pages" in "sap.m.App" exists
// (check borrowed ones):
// TODO:

// Test Case 3: Collect all properties of "sap.m.App"
// (DON'T collect borrowed ones):
// TODO:

// Test Case 4: Collect defaultAggregation of "sap.m.App"
// (collect borrowed ones):
const defaultAggregation = apiExtract.getDefaultAggregation("sap.m.App");
console.log(defaultAggregation);

// TODO: add performance measurements
} catch (error) {
console.log(error);
process.exit(1);
}
};

await main();
35 changes: 31 additions & 4 deletions src/utils/ApiExtract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,37 @@ class ApiExtractImpl implements ApiExtract {
this.data = data;
}

getDefaultAggregation(className: string): string {
// return this.data.defaultAggregations[className];
// TODO: Implement this method
return "";
/**
* Returns the key of a given value in a given Record.
* @example _getKeyByValue({a: "b", c: "d"}, "d") // returns "c"
*/
_getKeyByValue(record: Record<string, string>, value: string): string | undefined {
return Object.keys(record).find((key) => record[key] === value);
}

// TODO: Outsource to separate function to reuse it for other options
// e.g. aggregation, association, event, method, property
getDefaultAggregation(symbolName: string): string | undefined {
// TODO: TEST !!!!!!!
let defaultAggregation: string | undefined;
const foundSymbolRecord = this.data.metadata[symbolName];
if (foundSymbolRecord) {
defaultAggregation = this._getKeyByValue(foundSymbolRecord, "defaultAggregation");
if (defaultAggregation) {
return defaultAggregation;
} else {
// Resolve borrowed aggregation with "extends":
while (foundSymbolRecord.extends) {
const extendsSymbolRecord = this.data.metadata[foundSymbolRecord.extends];
defaultAggregation = this._getKeyByValue(extendsSymbolRecord, "defaultAggregation");
if (defaultAggregation) {
return defaultAggregation;
}
}
}
}

return undefined;
}

getDeprecationInfo(symbolName: string): DeprecationInfo | undefined {
Expand Down

0 comments on commit a76c203

Please sign in to comment.