11'use strict' ;
22
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
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
78// this same test script with different arguments. If those exit with
89// code 0, then the test passes. If they don't, it fails.
910
11+ // TODO(joyeecheung): instead of testing internals, test the actual features
12+ // pending deprecations.
13+
1014const common = require ( '../common' ) ;
1115
1216const assert = require ( 'assert' ) ;
13- const config = process . binding ( 'config' ) ;
1417const fork = require ( 'child_process' ) . fork ;
18+ const { getOptionValue } = require ( 'internal/options' ) ;
1519
1620function message ( name ) {
17- return `${ name } did not set the process.binding('config').` +
18- 'pendingDeprecation flag.' ;
21+ return `${ name } did not affect getOptionValue('--pending-deprecation')` ;
1922}
2023
2124switch ( process . argv [ 2 ] ) {
2225 case 'env' :
2326 case 'switch' :
24- assert . strictEqual ( config . pendingDeprecation , true ) ;
27+ assert . strictEqual (
28+ getOptionValue ( '--pending-deprecation' ) ,
29+ true
30+ ) ;
2531 break ;
2632 default :
2733 // Verify that the flag is off by default.
2834 const envvar = process . env . NODE_PENDING_DEPRECATION ;
29- assert . strictEqual ( config . pendingDeprecation , envvar && envvar [ 0 ] === '1' ) ;
35+ assert . strictEqual (
36+ getOptionValue ( '--pending-deprecation' ) ,
37+ ! ! ( envvar && envvar [ 0 ] === '1' )
38+ ) ;
3039
3140 // Test the --pending-deprecation command line switch.
3241 fork ( __filename , [ 'switch' ] , {
33- execArgv : [ '--pending-deprecation' ] ,
42+ execArgv : [ '--pending-deprecation' , '--expose-internals' ] ,
3443 silent : true
3544 } ) . on ( 'exit' , common . mustCall ( ( code ) => {
3645 assert . strictEqual ( code , 0 , message ( '--pending-deprecation' ) ) ;
3746 } ) ) ;
3847
3948 // Test the --pending_deprecation command line switch.
4049 fork ( __filename , [ 'switch' ] , {
41- execArgv : [ '--pending_deprecation' ] ,
50+ execArgv : [ '--pending_deprecation' , '--expose-internals' ] ,
4251 silent : true
4352 } ) . on ( 'exit' , common . mustCall ( ( code ) => {
4453 assert . strictEqual ( code , 0 , message ( '--pending_deprecation' ) ) ;
@@ -47,6 +56,7 @@ switch (process.argv[2]) {
4756 // Test the NODE_PENDING_DEPRECATION environment var.
4857 fork ( __filename , [ 'env' ] , {
4958 env : Object . assign ( { } , process . env , { NODE_PENDING_DEPRECATION : 1 } ) ,
59+ execArgv : [ '--expose-internals' ] ,
5060 silent : true
5161 } ) . on ( 'exit' , common . mustCall ( ( code ) => {
5262 assert . strictEqual ( code , 0 , message ( 'NODE_PENDING_DEPRECATION' ) ) ;
0 commit comments