|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Tests that --pending-deprecation and NODE_PENDING_DEPRECATION both |
| 4 | +// set the process.binding('config').pendingDeprecation flag that is |
| 5 | +// used to determine if pending deprecation messages should be shown. |
| 6 | +// The test is performed by launching two child processes that run |
| 7 | +// this same test script with different arguments. If those exit with |
| 8 | +// code 0, then the test passes. If they don't, it fails. |
| 9 | + |
| 10 | +const common = require('../common'); |
| 11 | + |
| 12 | +const assert = require('assert'); |
| 13 | +const config = process.binding('config'); |
| 14 | +const fork = require('child_process').fork; |
| 15 | + |
| 16 | +function message(name) { |
| 17 | + return `${name} did not set the process.binding('config').` + |
| 18 | + 'pendingDeprecation flag.'; |
| 19 | +} |
| 20 | + |
| 21 | +switch (process.argv[2]) { |
| 22 | + case 'env': |
| 23 | + case 'switch': |
| 24 | + assert.strictEqual(config.pendingDeprecation, true); |
| 25 | + break; |
| 26 | + default: |
| 27 | + // Verify that the flag is off by default. |
| 28 | + assert.strictEqual(config.pendingDeprecation, undefined); |
| 29 | + |
| 30 | + // Test the --pending-deprecation command line switch. |
| 31 | + fork(__filename, ['switch'], { |
| 32 | + execArgv: ['--pending-deprecation'], |
| 33 | + silent: true |
| 34 | + }).on('exit', common.mustCall((code) => { |
| 35 | + assert.strictEqual(code, 0, message('--pending-deprecation')); |
| 36 | + })); |
| 37 | + |
| 38 | + // Test the NODE_PENDING_DEPRECATION environment var. |
| 39 | + fork(__filename, ['env'], { |
| 40 | + env: {NODE_PENDING_DEPRECATION: 1}, |
| 41 | + silent: true |
| 42 | + }).on('exit', common.mustCall((code) => { |
| 43 | + assert.strictEqual(code, 0, message('NODE_PENDING_DEPRECATION')); |
| 44 | + })); |
| 45 | +} |
0 commit comments