node/test/parallel/test-module-binding.js
Rich Trott bd4773a043 module: use undefined if no main
If the package.json file does not have a "main" entry, return undefined
rather than an empty string. This is to make more consistent behavior.
For example, when package.json is a directory, "main" is undefined
rather than an empty string.

PR-URL: https://github.com/nodejs/node/pull/18593
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-02-11 14:19:07 -08:00

16 lines
608 B
JavaScript

'use strict';
require('../common');
const fixtures = require('../common/fixtures');
const { internalModuleReadJSON } = process.binding('fs');
const { readFileSync } = require('fs');
const { strictEqual } = require('assert');
strictEqual(internalModuleReadJSON('nosuchfile'), undefined);
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), undefined);
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')),
undefined);
{
const filename = fixtures.path('require-bin/package.json');
strictEqual(internalModuleReadJSON(filename), readFileSync(filename, 'utf8'));
}