Compare commits
4 Commits
11cc79aa67
...
773172fafe
| Author | SHA1 | Date |
|---|---|---|
|
|
773172fafe | |
|
|
c93cf677ea | |
|
|
b43b2bc593 | |
|
|
5c04a0595b |
|
|
@ -405,15 +405,12 @@ async function runTests() {
|
|||
const p = path.join(TMP, 'bad.json');
|
||||
nativeFs.writeFileSync(p, '{ invalid json }');
|
||||
let threw = false;
|
||||
let errorMessage = '';
|
||||
try {
|
||||
fs.readJsonSync(p);
|
||||
} catch (error) {
|
||||
} catch {
|
||||
threw = true;
|
||||
errorMessage = error.message;
|
||||
}
|
||||
assert(threw, 'readJsonSync did not throw on invalid JSON');
|
||||
assert(errorMessage.includes(p), 'readJsonSync error did not include file path');
|
||||
});
|
||||
|
||||
test('readJsonSync strips UTF-8 BOM', () => {
|
||||
|
|
|
|||
|
|
@ -165,10 +165,5 @@ module.exports.move = async function move(src, dest) {
|
|||
*/
|
||||
module.exports.readJsonSync = function readJsonSync(filePath) {
|
||||
const raw = fs.readFileSync(filePath, 'utf8').replace(/^\uFEFF/, '');
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch (error) {
|
||||
error.message = `Failed to parse JSON in ${filePath}: ${error.message}`;
|
||||
throw error;
|
||||
}
|
||||
return JSON.parse(raw);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue