1'use strict'; 2require('../common'); 3const assert = require('assert'); 4 5assert.throws( 6 () => { 7 Object.defineProperty(process.env, 'foo', { 8 value: 'foo1' 9 }); 10 }, 11 { 12 code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY', 13 name: 'TypeError', 14 message: '\'process.env\' only accepts a ' + 15 'configurable, writable,' + 16 ' and enumerable data descriptor' 17 } 18); 19 20assert.strictEqual(process.env.foo, undefined); 21process.env.foo = 'foo2'; 22assert.strictEqual(process.env.foo, 'foo2'); 23 24assert.throws( 25 () => { 26 Object.defineProperty(process.env, 'goo', { 27 get() { 28 return 'goo'; 29 }, 30 set() {} 31 }); 32 }, 33 { 34 code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY', 35 name: 'TypeError', 36 message: '\'process.env\' does not accept an ' + 37 'accessor(getter/setter) descriptor' 38 } 39); 40 41const attributes = ['configurable', 'writable', 'enumerable']; 42 43attributes.forEach((attribute) => { 44 assert.throws( 45 () => { 46 Object.defineProperty(process.env, 'goo', { 47 [attribute]: false 48 }); 49 }, 50 { 51 code: 'ERR_INVALID_OBJECT_DEFINE_PROPERTY', 52 name: 'TypeError', 53 message: '\'process.env\' only accepts a ' + 54 'configurable, writable,' + 55 ' and enumerable data descriptor' 56 } 57 ); 58}); 59 60assert.strictEqual(process.env.goo, undefined); 61Object.defineProperty(process.env, 'goo', { 62 value: 'goo', 63 configurable: true, 64 writable: true, 65 enumerable: true 66}); 67assert.strictEqual(process.env.goo, 'goo'); 68