@@ -75,12 +75,24 @@ describe('异步执行', () => {
7575 } ) ;
7676
7777 test ( 'undefined 仅从子环境移除变量,Windows 覆盖按名称忽略大小写' , async ( ) => {
78+ const variableName = 'JAVA_RUN_CHILD_REMOVE' ;
79+ const originalValue = process . env [ variableName ] ;
80+ const removalName = process . platform === 'win32' ? variableName . toLowerCase ( ) : variableName ;
81+ process . env [ variableName ] = 'parent-only-value' ;
82+ try {
83+ const removed = await runCommand ( command ( 'console.log(JSON.stringify({value:process.env.JAVA_RUN_CHILD_REMOVE}))' ) , {
84+ capture : true , env : { [ removalName ] : undefined } ,
85+ } ) ;
86+ expect ( JSON . parse ( removed . stdout ) ) . toEqual ( { } ) ;
87+ expect ( process . env [ variableName ] ) . toBe ( 'parent-only-value' ) ;
88+ } finally {
89+ if ( originalValue === undefined ) delete process . env [ variableName ] ;
90+ else process . env [ variableName ] = originalValue ;
91+ }
7892 const pathName = Object . keys ( process . env ) . find ( name => name . toLowerCase ( ) === 'path' ) ! ;
7993 const originalPath = process . env [ pathName ] ;
8094 const overrideName = process . platform === 'win32' ? pathName . toLowerCase ( ) : pathName ;
8195 const source = 'console.log(JSON.stringify({path:process.env[Object.keys(process.env).find(name=>name.toLowerCase()==="path")]}))' ;
82- const removed = await runCommand ( command ( source ) , { capture : true , env : { [ overrideName ] : undefined } } ) ;
83- expect ( JSON . parse ( removed . stdout ) ) . toEqual ( { } ) ;
8496 const overwritten = await runCommand ( command ( source ) , { capture : true , env : { [ overrideName ] : 'child-only-path' } } ) ;
8597 expect ( JSON . parse ( overwritten . stdout ) ) . toEqual ( { path : 'child-only-path' } ) ;
8698 expect ( { path : process . env [ pathName ] } ) . toEqual ( { path : originalPath } ) ;
0 commit comments