Set env variable from script and set next request

//set var from script and next request - make it env var so we check that too

pm.test("Set env variable from script and set next request", () => {

    //second folder should have set var and next req

    let testsArr = mockArr.filter(value => value.event).map(value => value.event); 

    console.log("testArr",testsArr);

    let execArr = testsArr.flat().filter(value => value.script.exec).map(value => value.script.exec); 

    var setsVars = execArr.flat().filter(p => p.indexOf('environment.set(')>-1); 

    console.log(setsVars);

    pm.expect(setsVars).to.have.length.of.above(0);

    var setsReqs = execArr.flat().filter(p => p.indexOf('.setNextRequest')>-1); 

    console.log(setsReqs);

    pm.expect(setsReqs).to.have.length.of.above(0);

}); 

This is the test script that checks that, try to print each lines output and try to understand what it is exactly looking for.

Hint: it is looking for script.exec in any of the requests and checks whether it has a postman.setNextRequest and pm.environment.