@@ -22,11 +22,11 @@ var _ = require('lodash'),
22
22
EXECUTION_ERROR_EVENT_BASE = 'execution.error.' ,
23
23
EXECUTION_COOKIES_EVENT_BASE = 'execution.cookies.' ,
24
24
EXECUTION_SKIP_REQUEST_EVENT_BASE = 'execution.skipRequest.' ,
25
- EXECUTION_GET_VARIABLES_FROM_THIS_EXECUTION = 'execution.get_variables_from_this_execution.' ,
26
- EXECUTION_REPLY_TO_VARIABLES_REQUEST = 'execution.response_to_variables_request.' ,
27
25
28
26
EXECUTION_VAULT_BASE = 'execution.vault.' ,
29
27
28
+ CONTEXT_VARIABLE_SCOPES = [ '_variables' , 'environment' , 'globals' ] ,
29
+
30
30
COOKIES_EVENT_STORE_ACTION = 'store' ,
31
31
COOKIE_STORE_PUT_METHOD = 'putCookie' ,
32
32
COOKIE_STORE_UPDATE_METHOD = 'updateCookie' ,
@@ -515,7 +515,7 @@ module.exports = {
515
515
516
516
// Should fetch the request from the enclosing Postman App & resolve scripts and variables
517
517
containerRequestPassedOptions . requestResolverBridge ( requestToRunId ,
518
- async function ( err , collectionWithReqToRun ) {
518
+ function ( err , collectionWithReqToRun ) {
519
519
if ( err ) {
520
520
return dispatchErrorToListener ( err ) ;
521
521
}
@@ -531,39 +531,31 @@ module.exports = {
531
531
// variables set by the parent using pm.<variable-form>.set do not reflect
532
532
// in postman-runtime's scope immediately. They are present inside postman-sandbox
533
533
// till the parent request's script execution ends.
534
- const variablesRequestUniqueId = uuid . v4 ( ) ,
534
+ const variableValues = nestedRequestOptions . currentScopeVariableValues || { } ,
535
535
globals = { values : [ ] } ,
536
536
localVariables = { values : [ ] } ,
537
537
environment = { values : [ ] } ,
538
538
collectionVariables = { values : [ ] } ;
539
539
540
- await new Promise ( ( resolve ) => {
541
- self . host . once ( EXECUTION_REPLY_TO_VARIABLES_REQUEST + variablesRequestUniqueId ,
542
- function ( variableValues ) {
543
- if ( variableValues . globals && variableValues . globals . length ) {
544
- globals . values = variableValues . globals ;
545
- }
546
- if ( variableValues . environment && variableValues . environment . length ) {
547
- environment . values = variableValues . environment ;
548
- }
549
- if ( variableValues . _variables && variableValues . _variables . length ) {
550
- localVariables . values = variableValues . _variables ;
551
- }
552
- // Merge the root request's collection variables as globals
553
- // for nested requests. For all further nested requests, globals
554
- // will continue to have these values useful for resolution
555
- // unless overridden.
556
- if ( ! self . state . isNestedRequest &&
557
- variableValues . collectionVariables &&
558
- variableValues . collectionVariables . length ) {
559
- collectionVariables . values = variableValues . collectionVariables ;
560
- }
561
- resolve ( ) ;
562
- } ) ;
540
+ if ( variableValues . globals && variableValues . globals . length ) {
541
+ globals . values = variableValues . globals ;
542
+ }
543
+ if ( variableValues . environment && variableValues . environment . length ) {
544
+ environment . values = variableValues . environment ;
545
+ }
546
+ if ( variableValues . _variables && variableValues . _variables . length ) {
547
+ localVariables . values = variableValues . _variables ;
548
+ }
563
549
564
- self . host . dispatch ( EXECUTION_GET_VARIABLES_FROM_THIS_EXECUTION + executionId ,
565
- variablesRequestUniqueId ) ;
566
- } ) ;
550
+ // Merge the root request's collection variables as globals
551
+ // for nested requests. For all further nested requests, globals
552
+ // will continue to have these values useful for resolution
553
+ // unless overridden.
554
+ if ( ! self . state . isNestedRequest &&
555
+ variableValues . collectionVariables &&
556
+ variableValues . collectionVariables . length ) {
557
+ collectionVariables . values = variableValues . collectionVariables ;
558
+ }
567
559
568
560
// Merge provided local variables with the variables provided in reference request opts
569
561
const collectionRequestRunner = require ( '../../runner' ) ,
@@ -613,15 +605,15 @@ module.exports = {
613
605
function ( err , run ) {
614
606
let exceptionForThisRequest = null ,
615
607
responseForThisRequest = null ,
616
- variableMutationsFromThisScriptExecution = { } ;
608
+ variableMutationsFromThisExecution = { } ;
617
609
618
610
if ( err ) {
619
611
return self . host
620
612
. dispatch ( EXECUTION_RUN_REQUEST_RESPONSE_EVENT_BASE + eventId ,
621
613
requestId , err ) ;
622
614
}
623
615
run . start ( {
624
- script ( _err , _cursor , result , _script , event ) {
616
+ script ( _err , _cursor , result ) {
625
617
// This is to sync changes to pm.variables, pm.environment & pm.globals
626
618
// that happened inside the nested request's script
627
619
// back to parent request's scripts still currently executing.
@@ -631,11 +623,15 @@ module.exports = {
631
623
// All other global variables defined by syntax like 'a=1'
632
624
// are anyway synced as the sandbox's common scope is shared across runs
633
625
if ( result ) {
634
- variableMutationsFromThisScriptExecution [ event . listen ] = {
635
- _variables : result . _variables . mutations ,
636
- environment : result . environment . mutations ,
637
- globals : result . globals . mutations
638
- } ;
626
+ CONTEXT_VARIABLE_SCOPES . forEach ( function ( type ) {
627
+ variableMutationsFromThisExecution [ type ] =
628
+ ! variableMutationsFromThisExecution [ type ] ?
629
+ [ result [ type ] . mutations ] :
630
+ [
631
+ ...variableMutationsFromThisExecution [ type ] ,
632
+ result [ type ] . mutations
633
+ ] ;
634
+ } ) ;
639
635
}
640
636
} ,
641
637
exception ( _ , err ) {
@@ -672,8 +668,7 @@ module.exports = {
672
668
return self . host . dispatch ( runRequestRespEvent ,
673
669
requestId , error || null ,
674
670
responseForThisRequest ,
675
- { variableMutationStages :
676
- variableMutationsFromThisScriptExecution } ) ;
671
+ { variableMutations : variableMutationsFromThisExecution } ) ;
677
672
}
678
673
} ) ;
679
674
} ) ;
0 commit comments