0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-cli-node-print-help.js
willhayslett a43e8896f2 doc, src: sort + fill up cli options and env vars
* Alphabetize the command line options and environment
  variables in doc/api/cli.md for consistency and readability.

* Update doc/api/cli.md to include command line options
  being printed in the `node.PrintHelp()` function in src/node.cc
  but weren't otherwise documented in the cli spec. Options added
  include:

  --napi-modules
  --v8-pool-size=num
  --experimental-modules
  --experimental-vm-modules

* ASCII sort the node man page command line options.
  This change brings sort order consistency between the
  cli options displayed in doc/node.1 and the cli options
  enumerated in other areas of the project.

  Also rearrange the language for `--use-bundled-ca`, `--use-openssl-ca`
  to correspond with the order of the options as displayed.

* Update `node.PrintHelp()` function to return command line options
  and environment variables sorted in ASCII order. Additionally,
  add missing options as sourced from doc/api/cli.md. Options
  added include `--`, `--help` and the `NODE_PRESERVE_SYMLINKS`
  environment variable.

  Also update the comments in the `node.PrintHelp()` method
  to C++ style.

* Create tests to validate that the newly ASCII sorted
  cli options in the `node.PrintHelp()` function are being
  returned according to build configurations as expected.

PR-URL: https://github.com/nodejs/node/pull/19878
Refs: https://github.com/nodejs/node/issues/19814
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-13 23:14:54 +03:00

59 lines
1.7 KiB
JavaScript

'use strict';
const common = require('../common');
// The following tests assert that the node.cc PrintHelp() function
// returns the proper set of cli options when invoked
const assert = require('assert');
const { exec } = require('child_process');
let stdOut;
function startPrintHelpTest() {
exec(`${process.execPath} --help`, common.mustCall((err, stdout, stderr) => {
assert.ifError(err);
stdOut = stdout;
validateNodePrintHelp();
}));
}
function validateNodePrintHelp() {
const config = process.config;
const HAVE_OPENSSL = common.hasCrypto;
const NODE_FIPS_MODE = common.hasFipsCrypto;
const NODE_HAVE_I18N_SUPPORT = common.hasIntl;
const HAVE_INSPECTOR = config.variables.v8_enable_inspector === 1;
const cliHelpOptions = [
{ compileConstant: HAVE_OPENSSL,
flags: [ '--openssl-config=file', '--tls-cipher-list=val',
'--use-bundled-ca', '--use-openssl-ca' ] },
{ compileConstant: NODE_FIPS_MODE,
flags: [ '--enable-fips', '--force-fips' ] },
{ compileConstant: NODE_HAVE_I18N_SUPPORT,
flags: [ '--experimental-modules', '--experimental-vm-modules',
'--icu-data-dir=dir', '--preserve-symlinks',
'NODE_ICU_DATA', 'NODE_PRESERVE_SYMLINKS' ] },
{ compileConstant: HAVE_INSPECTOR,
flags: [ '--inspect-brk[=[host:]port]', '--inspect-port=[host:]port',
'--inspect[=[host:]port]' ] },
];
cliHelpOptions.forEach(testForSubstring);
}
function testForSubstring(options) {
if (options.compileConstant) {
options.flags.forEach((flag) => {
assert.strictEqual(stdOut.indexOf(flag) !== -1, true);
});
} else {
options.flags.forEach((flag) => {
assert.strictEqual(stdOut.indexOf(flag), -1);
});
}
}
startPrintHelpTest();