fix(node-utils): Do not throw if readFile path is not resolved.

This commit is contained in:
Sam Tolmay 2022-01-21 10:58:43 +02:00
parent 9df6579198
commit b451c29b4a
No known key found for this signature in database
GPG Key ID: D004126FCD1A6DF0
2 changed files with 1 additions and 12 deletions

View File

@ -27,14 +27,9 @@ async function readFile(filePath) {
`Could not read file, file path should be a string, received ${JSON.stringify(filePath)}.`
);
}
if (filePath !== path.resolve(filePath)) {
throw new Error(
`Could not read file, file path was not resolved, received ${JSON.stringify(filePath)}.`
);
}
try {
// By specifying encoding, readFile returns a string instead of a buffer.
const file = await readFilePromise(filePath, 'utf8');
const file = await readFilePromise(path.resolve(filePath), 'utf8');
return file;
} catch (error) {
if (error.code === 'ENOENT' || error.code === 'EISDIR') {

View File

@ -35,9 +35,3 @@ test('readFile error id filepath is not a string', async () => {
'Could not read file, file path should be a string, received {}.'
);
});
test('readFile errors if path is not already resolved', async () => {
await expect(readFile('./readFile/readFile.txt')).rejects.toThrow(
'Could not read file, file path was not resolved, received "./readFile/readFile.txt".'
);
});