Skip to content

Commit

Permalink
fix: UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Sep 17, 2024
1 parent 07401a8 commit 9646df1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,27 @@ module.exports.test = {

submittedData(dataFile) {
return function (key) {
if (!fs.existsSync(dataFile)) {
const waitTill = new Date(new Date().getTime() + 1 * 1000); // wait for one sec for file to be created
let retries = 10; // Set the number of retries
const retryInterval = 100; // Retry every 100ms (for a total of 1 second)

while (!fs.existsSync(dataFile) && retries > 0) {
retries--;
const waitTill = new Date(new Date().getTime() + retryInterval);
//
while (waitTill > new Date()) {} // eslint-disable-line no-empty
}

if (!fs.existsSync(dataFile)) {
throw new Error('Data file was not created in time');
}
const data = JSON.parse(fs.readFileSync(dataFile, 'utf8'));

const fileData = fs.readFileSync(dataFile, 'utf8');
const data = JSON.parse(fileData);

if (key) {
return data.form[key];
}

return data;
};
},
Expand Down

0 comments on commit 9646df1

Please sign in to comment.