Skip to content

Commit

Permalink
fix(helpers): improve readfileasync log
Browse files Browse the repository at this point in the history
  • Loading branch information
venturalp committed May 14, 2021
1 parent e56566b commit 055d553
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/editor.ts
Expand Up @@ -84,9 +84,8 @@ export const getNewReadme = (readmeFile: string, coverageFile: string) => (
};

export const writeNewReadme = (readmePath: string) => (newReadmeData: string): boolean | void => {
logInfo('- Writing new readme data...');

try {
console.log('writing file in', readmePath)
return fs.writeFileSync(readmePath, newReadmeData, 'utf8');
} catch {
return false;
Expand Down
16 changes: 8 additions & 8 deletions src/helpers.ts
Expand Up @@ -4,29 +4,29 @@ import { getArgumentValue } from "./arguments";
export const getCoveragePath = (path: string): string => {
let coveragePath: string = path;
const argPath = getArgumentValue('coverageDir');

if (argPath) {
coveragePath = `${argPath}/coverage-summary.json`;
coveragePath = `${argPath}/coverage-summary.json`;
}

return coveragePath;
};
};

export const getReadmePath = (path: string): string => {
export const getReadmePath = (path: string): string => {
let readmePath: string = path;
const argPath = getArgumentValue('readmeDir');

if (argPath) {
readmePath = `${argPath}/README.md`;
}

return readmePath;
};

export const readFileAsync = async (path: string, encode: string): Promise<string> => {
return new Promise((resolve, reject) =>{
fs.readFile(path, encode, (err, data) => {
if (err) reject()
if (err) reject(`file not found: ${path}`)
resolve(data)
} )
})
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.spec.ts
Expand Up @@ -20,6 +20,6 @@ describe('test helpers file', () => {
});

it ('should fail to read an async file', async () => {
await readFileAsync('./foo/bar.biz', 'utf-8').catch(e => expect(e).toBeUndefined())
await readFileAsync('./foo/bar.biz', 'utf-8').catch(e => expect(e).toEqual('file not found: ./foo/bar.biz'))
})
})

0 comments on commit 055d553

Please sign in to comment.