-
Notifications
You must be signed in to change notification settings - Fork 44
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
Implementation - csv-delimiter #165
base: feat/c4gt
Are you sure you want to change the base?
Conversation
@@ -1,6 +1,7 @@ | |||
{ | |||
"globals": { | |||
"onlyCreateWhitelisted": true | |||
"onlyCreateWhitelisted": true, |
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.
remove onlyCreateWhitelist
changes from this PR.
'./test/fixtures/test-csvs/csvreader/invalid.reader.csv' | ||
); | ||
|
||
expect(res).toBeDefined(); |
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.
don't only check the result to be defined, since you are parsing with a different delimiter, make sure it is parsed correctly.
export function getCsvDelimiter(configPath: string): string | undefined { | ||
try { | ||
const configContent = fs1.readFileSync(configPath, 'utf-8'); | ||
const config = JSON.parse(configContent); |
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.
JSON.parse()
has the potential to throw an error, wrap this is in a try-catch
try { | ||
const configContent = fs1.readFileSync(configPath, 'utf-8'); | ||
const config = JSON.parse(configContent); | ||
return config.globals.csvDelimiter; |
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.
handle errors here as well, there is no gurantee that this particular element is defined or not. Also make sure you are handling the case of this function returning as undefined
wherever it is being being and defaulting to a ','
in such cases.
@@ -3,13 +3,20 @@ const fs = require('fs').promises; | |||
|
|||
import * as csv from 'csv-parser'; | |||
|
|||
export async function readCSV(filePath: string): Promise<string[][]> { | |||
export async function readCSV(filePath: string, configPath?: string, delimiter?: string): Promise<string[][]> { |
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.
don't pass in configPath
to a utility function like this. Read the required paramters (delimiter
in this case) at the initial top level when the config is parsed and pass in the delimiter from there only.
Added new config parameter along with test cases to increase coverage ( For the issue #64 )