1// Flags: --expose-internals 2'use strict'; 3require('../common'); 4const fixtures = require('../common/fixtures'); 5const { internalBinding } = require('internal/test/binding'); 6const { internalModuleReadJSON } = internalBinding('fs'); 7const { readFileSync } = require('fs'); 8const { strictEqual } = require('assert'); 9{ 10 const [string, containsKeys] = internalModuleReadJSON('nosuchfile'); 11 strictEqual(string, undefined); 12 strictEqual(containsKeys, undefined); 13} 14{ 15 const [string, containsKeys] = 16 internalModuleReadJSON(fixtures.path('empty.txt')); 17 strictEqual(string, ''); 18 strictEqual(containsKeys, false); 19} 20{ 21 const [string, containsKeys] = 22 internalModuleReadJSON(fixtures.path('empty.txt')); 23 strictEqual(string, ''); 24 strictEqual(containsKeys, false); 25} 26{ 27 const [string, containsKeys] = 28 internalModuleReadJSON(fixtures.path('empty-with-bom.txt')); 29 strictEqual(string, ''); 30 strictEqual(containsKeys, false); 31} 32{ 33 const filename = fixtures.path('require-bin/package.json'); 34 const [string, containsKeys] = internalModuleReadJSON(filename); 35 strictEqual(string, readFileSync(filename, 'utf8')); 36 strictEqual(containsKeys, true); 37} 38