Skip to content

Commit

Permalink
Test Case 2 Pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Deborg201 committed May 21, 2024
1 parent 3c45d4c commit 0d15ad0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"author": "Chakshu Gautam",
"license": "ISC",
"devDependencies": {
"csv-parser": "^3.0.0",
"jest": "^29.7.0"
},
"dependencies": {
"csv-parser": "^3.0.0",
"json2csv": "^6.0.0-alpha.2",
"xterm": "^5.3.0"
}
}
}
20 changes: 20 additions & 0 deletions src/csvReader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const fs = require('fs');
const csv = require('csv-parser');

function readCSV(filePath) {
const results = [];

return new Promise((resolve, reject) => {
fs.createReadStream(filePath)
.pipe(csv())
.on('data', (data) => results.push(data))
.on('end', () => {
resolve(results);
})
.on('error', (error) => {
reject(error);
});
});
}

module.exports = readCSV;
Empty file added src/index.js
Empty file.
4 changes: 4 additions & 0 deletions src/sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,age
1,John,30
2,Jane,25
3,Bob,22
4 changes: 2 additions & 2 deletions tests/step-02/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const readCSV = require('../../src/csvReader');
const readCSV = require("../../src/csvReader");

test('Read CSV File', async () => {
const data = await readCSV('./sample.csv');
const data = await readCSV("./src/sample.csv");
expect(data.length).toBeGreaterThan(0);
expect(data.length).toBe(3);
expect(data[0].name).toBe('John');
Expand Down

0 comments on commit 0d15ad0

Please sign in to comment.