-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DRAFT] - [perf] - wasm optimisations #6
base: develop
Are you sure you want to change the base?
Changes from 6 commits
3047a36
d87245f
10b3c7a
2274270
098bacf
32d3558
dab3d33
de6034d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
node_modules | ||
vendor | ||
.idea | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
build | ||
build | ||
file-sizes.json | ||
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lack of error handling: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, you're right. Thanks for pointing that out. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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)) { | ||
const fileContent = fs.readFileSync(resultsFilePath, "utf-8"); | ||
return JSON.parse(fileContent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The JSON.parse() call could throw an error if the file contents are malformed or not valid JSON. It's good to wrap this in a try-catch block to handle such cases. |
||
} | ||
return {}; | ||
} | ||
|
||
/** Function to add test results to the report if the GENERATE_REPORT environment variable is set to "true" */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better Type Annotation (for TypeScript or JSDoc):
|
||
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, | ||
}; | ||
|
||
// Write the combined results to the file | ||
fs.writeFileSync(resultsFilePath, JSON.stringify(combinedResults, null, 2)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try/catch? |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add new line here ;)
POSIX ... If a file without a trailing newline is modified, Git's diff algorithm might show unexpected differences because the change will also affect the last line. Adding a newline at the end helps prevent diffs from being misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I did not know that. Thanks for mentioning it.