Copy objects instead of properties on modifiers.

This commit is contained in:
David Diaz 2018-04-30 13:49:52 -06:00
parent dd2842c097
commit 185333cb20
6 changed files with 1321 additions and 1317 deletions

2624
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@
"commander": "^2.15.1", "commander": "^2.15.1",
"deepmerge": "^2.1.0", "deepmerge": "^2.1.0",
"dotenv": "^5.0.1", "dotenv": "^5.0.1",
"is-plain-object": "^2.0.4",
"js-yaml": "^3.11.0", "js-yaml": "^3.11.0",
"jsome": "^2.5.0", "jsome": "^2.5.0",
"request": "^2.85.0", "request": "^2.85.0",

View File

@ -192,6 +192,7 @@ Beau {
"DEPENDENCIES": Set {}, "DEPENDENCIES": Set {},
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"FORM": undefined, "FORM": undefined,
"FORMDATA": undefined,
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
}, },
@ -224,6 +225,7 @@ Beau {
"DEPENDENCIES": Set {}, "DEPENDENCIES": Set {},
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"FORM": undefined, "FORM": undefined,
"FORMDATA": undefined,
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
"hello": "world", "hello": "world",

View File

@ -79,7 +79,6 @@ describe(`Beau's plugin system`, () => {
it(`should look for dynamic values executing and replacing them`, async () => { it(`should look for dynamic values executing and replacing them`, async () => {
let req = await request.exec(cache); let req = await request.exec(cache);
expect(req).toHaveProperty('request.body', 'counted 3 so far.'); expect(req).toHaveProperty('request.body', 'counted 3 so far.');
}); });

View File

@ -2,6 +2,7 @@ const vm = require('vm');
const requireg = require('requireg'); const requireg = require('requireg');
const deepmerge = require('deepmerge'); const deepmerge = require('deepmerge');
const { toKebabCase, dynamicValueRegex, replaceInObject } = require('./shared'); const { toKebabCase, dynamicValueRegex, replaceInObject } = require('./shared');
const isPlainObject = require('is-plain-object');
class Plugins { class Plugins {
constructor(plugins = []) { constructor(plugins = []) {
@ -36,7 +37,7 @@ class Plugins {
} }
executeModifier(modifier, obj, orig) { executeModifier(modifier, obj, orig) {
let result = deepmerge({}, obj); let result = deepmerge({}, obj, { isMergeableObject: isPlainObject });
this.registry[modifier].forEach( this.registry[modifier].forEach(
modifier => (result = modifier(result, orig)) modifier => (result = modifier(result, orig))

View File

@ -25,7 +25,8 @@ class Request {
'PARAMS', 'PARAMS',
'FORM', 'FORM',
'ALIAS', 'ALIAS',
'COOKIEJAR' 'COOKIEJAR',
'FORMDATA'
], ],
req req
); );
@ -93,6 +94,7 @@ class Request {
qs: this.PARAMS, qs: this.PARAMS,
body: this.PAYLOAD, body: this.PAYLOAD,
form: this.FORM, form: this.FORM,
formData: this.FORMDATA,
json: true, json: true,
simple: false, simple: false,
@ -103,7 +105,8 @@ class Request {
'headers', 'headers',
'qs', 'qs',
'body', 'body',
'form' 'form',
'formData'
]); ]);
settings = this.plugins.replaceDynamicValues(settings); settings = this.plugins.replaceDynamicValues(settings);