Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/internal/main/print_help.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ const envVars = new SafeMap(ArrayPrototypeConcat([
'libuv\'s threadpool' }],
], hasIntl ? [
['NODE_ICU_DATA', { helpText: 'data path for ICU (Intl object) data' +
hasSmallICU ? '' : ' (will extend linked-in data)' }],
] : []), (hasNodeOptions ? [
(hasSmallICU ? '' : ' (will extend linked-in data)') }],
] : [], hasNodeOptions ? [
['NODE_OPTIONS', { helpText: 'set CLI options in the environment via a ' +
'space-separated list' }],
] : []), hasCrypto ? [
] : [], hasCrypto ? [
['OPENSSL_CONF', { helpText: 'load OpenSSL configuration from file' }],
['SSL_CERT_DIR', { helpText: 'sets OpenSSL\'s directory of trusted ' +
'certificates when used in conjunction with --use-openssl-ca' }],
['SSL_CERT_FILE', { helpText: 'sets OpenSSL\'s trusted certificate file ' +
'when used in conjunction with --use-openssl-ca' }],
] : []);
] : []));


function indent(text, depth) {
Expand Down
41 changes: 41 additions & 0 deletions test/parallel/test-cli-node-print-help.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,47 @@ function validateNodePrintHelp() {
];

cliHelpOptions.forEach(testForSubstring);

validateEnvVarSection();
}

// Verify that the "Environment variables:" section lists the expected
// entries. Each entry is printed at the start of its own line, so matching
// against the start of a line avoids false positives from names that also
// appear inside an option's description (e.g. `--icu-data-dir` mentions
// "overrides NODE_ICU_DATA" and `--openssl-config` mentions
// "overrides OPENSSL_CONF"). These checks guard against malformed
// construction of the environment-variable list that would silently drop
// entries from the help output.
function validateEnvVarSection() {
const { internalBinding } = require('internal/test/binding');
const { hasNodeOptions } = internalBinding('config');

const start = stdOut.indexOf('Environment variables:');
assert.ok(start !== -1, 'Missing "Environment variables:" section');
const end = stdOut.indexOf('Documentation can be found', start);
const envSection = stdOut.slice(start, end === -1 ? undefined : end);

const expectedEnvVars = [
{ name: 'FORCE_COLOR', present: true },
{ name: 'NODE_PATH', present: true },
{ name: 'NODE_ICU_DATA', present: common.hasIntl },
{ name: 'NODE_OPTIONS', present: hasNodeOptions },
{ name: 'OPENSSL_CONF', present: common.hasCrypto },
{ name: 'SSL_CERT_DIR', present: common.hasCrypto },
{ name: 'SSL_CERT_FILE', present: common.hasCrypto },
];

for (const { name, present } of expectedEnvVars) {
const re = new RegExp(`^${name}\\b`, 'm');
if (present) {
assert.match(envSection, re,
`Missing environment variable ${name} in:\n${envSection}`);
} else {
assert.doesNotMatch(envSection, re,
`Unexpected environment variable ${name} in:\n${envSection}`);
}
}
}

function testForSubstring(options) {
Expand Down
Loading