Skip to content

Instantly share code, notes, and snippets.

@kavioshanaiesecer
Created June 15, 2021 18:32
Show Gist options
  • Save kavioshanaiesecer/5f3563c57a0ffc80158d77aa07289c84 to your computer and use it in GitHub Desktop.
Save kavioshanaiesecer/5f3563c57a0ffc80158d77aa07289c84 to your computer and use it in GitHub Desktop.
Function to Update the Test Results
function updateCSVFile(testResults) {
//Read the Provided CSV File
fs.readFile('./DATA_CSV_FILE_NAME.csv', 'utf-8', (error, data) => {
if (error) {
throw error;
}
const jsonData = Papa.parse(data, { header: true });
//console.log(jsonData);
//Iterate Each Request
jsonData.data.map((item, index) => item.testResult = testResults[index]);
//Updating the JSON Data with Test Results
const updatedCSV = Papa.unparse(jsonData.data);
console.log(updateCSVFile);
//Write to File
fs.writeFile('./TestResults/UPDATED_CSV_FILE_NAME.csv', updatedCSV, (error) => {
if (error) {
throw error;
}
console.log('Updated Successfully!!');
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment