Home:ALL Converter>SyntaxError Unexpected token at test-script

SyntaxError Unexpected token at test-script

Ask Time:2022-08-02T08:45:15         Author:seth

Json Formatter

I have a Collection that has POST requests in it. This collections needs bearer token for auth. The Pre-request script and Tests assertion is written at Collection level.

Problem: The collection works fine when ran in Postman, but when I run it in Azure… it throws “Syntax Error Unexpected token at test-script inside…”. And none of the assertions written at collection level is validated as indicated by 0 in report.

How can I resolve Unexpected token issue and have the assertions run. Thanks.

PRE-Request Script:
   postman.setEnvironmentVariable("guid", genHexString(32));
   const parse =require('csv-parse/lib/sync');
   const holiday = parse(pm.environment.get("holiday"),{   
   });

Tests:
   const responseData = pm.response.json();
   const csv_data = pm.environment.get("test_data");
   const parse = require('csv-parse/lib/sync');
   const csv_parsed_json_data = parse(csv_data, {
   }); 
   pm.test("Response has a body", () => {
         pm.response.to.be.withBody;
   });   
   pm.test("response body is json", () => {
        pm.response.to.have.jsonBody()
   });

Error message in Azure
#  failure        detail                                                                                       
   01.  SyntaxError                                                                                                
                Unexpected token .                                                                            
                at test-script                                                                                
                inside "Set library"                                                                          
                                                                                                                
   02.  SyntaxError                                                                                                
                Unexpected token .                                                                            
                at test-script                                                                                
                inside "Obtain Token"                                                                         
                                                                                                              
   03.  SyntaxError                                                                                                
                Unexpected token .                                                                            
                at test-script                                                                                
                inside "Introspection"                                                                        
                                                                                                              
   04.  SyntaxError                                                                                                
                Unexpected token .                                                                            
                at test-script                                                                                
                inside "test case for so and so " 

Author:seth,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73200898/syntaxerror-unexpected-token-at-test-script
yy