mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 11:41:22 +00:00

PR-URL: https://github.com/nodejs/node/pull/48605 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
30 lines
994 B
JavaScript
30 lines
994 B
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
const { internalBinding } = require('internal/test/binding');
|
|
const { filterOwnProperties } = require('internal/util');
|
|
const { internalModuleReadJSON } = internalBinding('fs');
|
|
const { readFileSync } = require('fs');
|
|
const { strictEqual, deepStrictEqual } = require('assert');
|
|
|
|
{
|
|
strictEqual(internalModuleReadJSON('nosuchfile'), undefined);
|
|
}
|
|
{
|
|
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), '');
|
|
}
|
|
{
|
|
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), '');
|
|
}
|
|
{
|
|
const filename = fixtures.path('require-bin/package.json');
|
|
const returnValue = JSON.parse(internalModuleReadJSON(filename));
|
|
const file = JSON.parse(readFileSync(filename, 'utf-8'));
|
|
const expectedValue = filterOwnProperties(file, ['name', 'main', 'exports', 'imports', 'type']);
|
|
deepStrictEqual({
|
|
__proto__: null,
|
|
...returnValue,
|
|
}, expectedValue);
|
|
}
|