node/test/parallel/test-module-binding.js
Yagiz Nizipli 951da5282c
lib: merge cjs and esm package json reader caches
PR-URL: https://github.com/nodejs/node/pull/48477
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-06-29 18:45:31 +00:00

30 lines
1006 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')[0], undefined);
}
{
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt'))[0], '');
}
{
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt'))[0], '');
}
{
const filename = fixtures.path('require-bin/package.json');
const returnValue = JSON.parse(internalModuleReadJSON(filename)[0]);
const file = JSON.parse(readFileSync(filename, 'utf-8'));
const expectedValue = filterOwnProperties(file, ['name', 'main', 'exports', 'imports', 'type']);
deepStrictEqual({
__proto__: null,
...returnValue,
}, expectedValue);
}