@@ -30,3 +30,47 @@ it('creates a process object that looks like the original one', () => {
3030it ( 'fakes require("process") so it is equal to "global.process"' , ( ) => {
3131 expect ( require ( 'process' ) === process ) . toBe ( true ) ;
3232} ) ;
33+
34+ it ( 'checks that process.env works as expected on Linux platforms' , ( ) => {
35+ Object . defineProperty ( process , 'platform' , { get : ( ) => 'linux' } ) ;
36+
37+ // Existing properties inside process.env are copied to the fake environment.
38+ process . env . PROP_STRING = 'foo' ;
39+ process . env . PROP_NUMBER = 3 ;
40+ process . env . PROP_UNDEFINED = undefined ;
41+
42+ const fake = createProcessObject ( ) . env ;
43+
44+ // All values converted to strings.
45+ expect ( fake . PROP_STRING ) . toBe ( 'foo' ) ;
46+ expect ( fake . PROP_NUMBER ) . toBe ( '3' ) ;
47+ expect ( fake . PROP_UNDEFINED ) . toBe ( 'undefined' ) ;
48+
49+ // Mac and Linux are case sensitive.
50+ expect ( fake . PROP_string ) . toBe ( undefined ) ;
51+
52+ // Added properties to the fake object are not added to the real one.
53+ fake . PROP_ADDED = 'new!' ;
54+
55+ expect ( fake . PROP_ADDED ) . toBe ( 'new!' ) ;
56+ expect ( process . env . PROP_ADDED ) . toBe ( undefined ) ;
57+ } ) ;
58+
59+ it ( 'checks that process.env works as expected in Windows platforms' , ( ) => {
60+ Object . defineProperty ( process , 'platform' , { get : ( ) => 'win32' } ) ;
61+
62+ // Windows is not case sensitive when it comes to property names.
63+ process . env . PROP_STRING = 'foo' ;
64+
65+ const fake = createProcessObject ( ) . env ;
66+
67+ expect ( fake . PROP_STRING ) . toBe ( 'foo' ) ;
68+ expect ( fake . PROP_string ) . toBe ( 'foo' ) ;
69+
70+ // Inherited methods, however, are not affected by case insensitiveness.
71+ expect ( typeof fake . toString ) . toBe ( 'function' ) ;
72+ expect ( typeof fake . valueOf ) . toBe ( 'function' ) ;
73+
74+ expect ( typeof fake . tostring ) . toBe ( 'undefined' ) ;
75+ expect ( typeof fake . valueof ) . toBe ( 'undefined' ) ;
76+ } ) ;
0 commit comments