karatelabs/karate-npm

Unknown error while loading Javascript file

anoopgcmz opened this issue · 1 comments

Feature File

Background:
  * def jwtUtils = read('generatejwt.js')

Scenario: Generate JWT Token
  * def token = jwtUtils.createJWT()
  * print 'Generated JWT Token:', token

Javascript File-(generatejwt.js)

const jwt = require("jsonwebtoken");
const payload = {x
  user: {
    first_name: "fname",
    last_name: "lname",,
  },
};
const hashkey = 'hashkey';
const addOptions = {
  algorithm: "RS256",
};
function createJWT() {
  sails.log("Generating token..");
  const token = jwt.sign(payload, hashkey, addOptions);
  return token;
}

when i run the feature file i am getting syntax error

org.graalvm.polyglot.PolyglotException: SyntaxError: Unnamed:1:1 Expected an operand but found const
(const jwt = require("jsonwebtoken");
 ^
Unnamed:20:0 Expected ; but found )
)

I dont see any error in syntax. please correct me if i am having any syntax error. I tried with read, karate call etc