Skip to content
Permalink
Browse files

fix(generic): correct the getOwnPropertyDescriptor proxy hook to resp…

…ect current properties writabil

ISSUES CLOSED: #340
  • Loading branch information
gerges authored and MarshallOfSound committed Sep 27, 2017
1 parent 0734e4c commit 8e9872bc08bcaddf1b1187fc626165073538489c
Showing with 18 additions and 2 deletions.
  1. +4 −2 src/util/forge-config.js
  2. +14 −0 test/fast/forge-config_spec.js
@@ -28,8 +28,10 @@ const proxify = (object, envPrefix) => {
getOwnPropertyDescriptor(target, name) {
const envValue = process.env[`${envPrefix}_${underscoreCase(name)}`];
// eslint-disable-next-line no-prototype-builtins
if (target.hasOwnProperty(name) || envValue) {
return { configurable: true, enumerable: true };
if (target.hasOwnProperty(name)) {
return Object.getOwnPropertyDescriptor(target, name);
} else if (envValue) {
return { writable: true, enumerable: true, configurable: true, value: envValue };
}
},
});
@@ -37,6 +37,7 @@ describe('forge-config', () => {
},
}));
});

it('should allow access to built-ins of proxied objects', async () => {
const conf = await findConfig(path.resolve(__dirname, '../fixture/dummy_js_conf'));
expect(conf.electronPackagerConfig.baz.hasOwnProperty).to.be.a('function');
@@ -46,6 +47,19 @@ describe('forge-config', () => {
delete process.env.ELECTRON_FORGE_S3_SECRET_ACCESS_KEY;
});

it('should allow overwrite of properties in proxied objects', async () => {
const conf = await findConfig(path.resolve(__dirname, '../fixture/dummy_js_conf'));
expect(conf.electronPackagerConfig.baz.hasOwnProperty).to.be.a('function');
expect(() => { conf.electronPackagerConfig.baz = 'bar'; }).to.not.throw();
process.env.ELECTRON_FORGE_S3_SECRET_ACCESS_KEY = 'SecretyThing';

const descriptor = { writable: true, enumerable: true, configurable: true, value: 'SecretyThing' };
expect(Object.getOwnPropertyDescriptor(conf.s3, 'secretAccessKey')).to.be.deep.equal(descriptor);
expect(() => { conf.s3.secretAccessKey = 'bar'; }).to.not.throw();
expect(conf.s3.secretAccessKey).to.equal('bar');
delete process.env.ELECTRON_FORGE_S3_SECRET_ACCESS_KEY;
});


it('should resolve the JS file exports in config.forge points to a JS file', async () => {
expect(JSON.parse(JSON.stringify(await findConfig(path.resolve(__dirname, '../fixture/dummy_js_conf'))))).to.be.deep.equal(Object.assign({}, defaults, {

0 comments on commit 8e9872b

Please sign in to comment.
You can’t perform that action at this time.