forked from near/near-sdk-js
-
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.
feat: include the wasm file size scripts for generating a markdown table
- Loading branch information
1 parent
0d25d1a
commit ddbd19c
Showing
19 changed files
with
1,033 additions
and
417 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
build | ||
file-sizes.json | ||
file-sizes.json |
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,60 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const resultsFilePath = path.resolve("temp-all-test-results.json"); | ||
|
||
/** | ||
* Reads existing test results from a JSON file if it exists. | ||
* | ||
* This function checks if the file specified by `resultsFilePath` exists. | ||
* If the file is found, it reads the file's content and parses it as JSON. | ||
* If the file does not exist, it returns an empty object. | ||
* | ||
* @returns {Object} The parsed JSON object from the file, or an empty object if the file does not exist. | ||
*/ | ||
function readExistingResults() { | ||
if (fs.existsSync(resultsFilePath)) { | ||
try { | ||
const fileContent = fs.readFileSync(resultsFilePath, "utf-8"); | ||
return JSON.parse(fileContent); | ||
} catch (error) { | ||
console.error("Failed to read or parse results file:", error); | ||
return {}; | ||
} | ||
} | ||
return {}; | ||
} | ||
|
||
/** | ||
* Function to add test results to the report if the GENERATE_REPORT environment variable is set to "true" | ||
* @param {string} testName - The name of the test. | ||
* @param {Object} result - The test result object. | ||
*/ | ||
export function addTestResults(testName, result) { | ||
// Check if we need to generate a report | ||
if (process.env.GENERATE_REPORT === "true") { | ||
// Create a temporary object for the new test results | ||
const tempResults = { | ||
[testName]: result, | ||
}; | ||
|
||
// Read existing results from the file | ||
const existingResults = readExistingResults(); | ||
|
||
// Combine existing results with new test results | ||
const combinedResults = { | ||
...existingResults, | ||
...tempResults, | ||
}; | ||
|
||
try { | ||
// Write the combined results to the file | ||
fs.writeFileSync( | ||
resultsFilePath, | ||
JSON.stringify(combinedResults, null, 2) | ||
); | ||
} catch (error) { | ||
console.error("Failed to write results to file:", error); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.