• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Flags: --expose-internals
4// Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both set the
5// `require('internal/options').getOptionValue('--pending-deprecation')`
6// flag that is used to determine if pending deprecation messages should be
7// shown. The test is performed by launching two child processes that run
8// this same test script with different arguments. If those exit with
9// code 0, then the test passes. If they don't, it fails.
10
11// TODO(joyeecheung): instead of testing internals, test the actual features
12// pending deprecations.
13
14const common = require('../common');
15
16const assert = require('assert');
17const fork = require('child_process').fork;
18const { getOptionValue } = require('internal/options');
19
20function message(name) {
21  return `${name} did not affect getOptionValue('--pending-deprecation')`;
22}
23
24switch (process.argv[2]) {
25  case 'env':
26  case 'switch':
27    assert.strictEqual(
28      getOptionValue('--pending-deprecation'),
29      true
30    );
31    break;
32  default:
33    // Verify that the flag is off by default.
34    const envvar = process.env.NODE_PENDING_DEPRECATION;
35    assert.strictEqual(
36      getOptionValue('--pending-deprecation'),
37      !!(envvar && envvar[0] === '1')
38    );
39
40    // Test the --pending-deprecation command line switch.
41    fork(__filename, ['switch'], {
42      execArgv: ['--pending-deprecation', '--expose-internals'],
43      silent: true
44    }).on('exit', common.mustCall((code) => {
45      assert.strictEqual(code, 0, message('--pending-deprecation'));
46    }));
47
48    // Test the --pending_deprecation command line switch.
49    fork(__filename, ['switch'], {
50      execArgv: ['--pending_deprecation', '--expose-internals'],
51      silent: true
52    }).on('exit', common.mustCall((code) => {
53      assert.strictEqual(code, 0, message('--pending_deprecation'));
54    }));
55
56    // Test the NODE_PENDING_DEPRECATION environment var.
57    fork(__filename, ['env'], {
58      env: { ...process.env, NODE_PENDING_DEPRECATION: 1 },
59      execArgv: ['--expose-internals'],
60      silent: true
61    }).on('exit', common.mustCall((code) => {
62      assert.strictEqual(code, 0, message('NODE_PENDING_DEPRECATION'));
63    }));
64}
65