summaryrefslogtreecommitdiff
path: root/test/parallel/test-pending-deprecation.js
blob: 6cabf9ddc693f770ca829138995831aa2469c2fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';

// Flags: --expose-internals
// Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both set the
// `require('internal/options').getOptionValue('--pending-deprecation')`
// flag that is used to determine if pending deprecation messages should be
// shown. The test is performed by launching two child processes that run
// this same test script with different arguments. If those exit with
// code 0, then the test passes. If they don't, it fails.

// TODO(joyeecheung): instead of testing internals, test the actual features
// pending deprecations.

const common = require('../common');

const assert = require('assert');
const fork = require('child_process').fork;
const { getOptionValue } = require('internal/options');

function message(name) {
  return `${name} did not affect getOptionValue('--pending-deprecation')`;
}

switch (process.argv[2]) {
  case 'env':
  case 'switch':
    assert.strictEqual(
      getOptionValue('--pending-deprecation'),
      true
    );
    break;
  default:
    // Verify that the flag is off by default.
    const envvar = process.env.NODE_PENDING_DEPRECATION;
    assert.strictEqual(
      getOptionValue('--pending-deprecation'),
      !!(envvar && envvar[0] === '1')
    );

    // Test the --pending-deprecation command line switch.
    fork(__filename, ['switch'], {
      execArgv: ['--pending-deprecation', '--expose-internals'],
      silent: true
    }).on('exit', common.mustCall((code) => {
      assert.strictEqual(code, 0, message('--pending-deprecation'));
    }));

    // Test the --pending_deprecation command line switch.
    fork(__filename, ['switch'], {
      execArgv: ['--pending_deprecation', '--expose-internals'],
      silent: true
    }).on('exit', common.mustCall((code) => {
      assert.strictEqual(code, 0, message('--pending_deprecation'));
    }));

    // Test the NODE_PENDING_DEPRECATION environment var.
    fork(__filename, ['env'], {
      env: Object.assign({}, process.env, { NODE_PENDING_DEPRECATION: 1 }),
      execArgv: ['--expose-internals'],
      silent: true
    }).on('exit', common.mustCall((code) => {
      assert.strictEqual(code, 0, message('NODE_PENDING_DEPRECATION'));
    }));
}